ArcEngine 创建工作空间工厂对象IWorkSpaceFactory有两种方式:
第一种使用ae的工厂方法:
IWorkspaceFactory pWsFactory = new ShapefileWorkspaceFactoryClass();
IFeatureWorkspace pWorkSpace = pWsFactory.OpenFromFile(path, 0) as IFeatureWorkspace;
使用这种方法有时候出现异常:无法将类型“System._ComObject”对象强制转换为ShapefileWorkspaceFactoryClass,这异常不只是针对ShapefileWorkspaceFactoryClass,还会出现在AccessWorkspaceFactoryClass,FileGDBWorkspaceFactoryClass和SdeWorkspaceFactoryClass等类型中,解决这个异常可以使用下面第二种方法创建。
第二种使用C#的动态创建类型的方法:
Type typeObj=System.Type .GetType ("esriWorkspaceType.ShapefileWorkspaceFactoryClass" );
IWorkspaceFactory pWsFactory =( IWorkspaceFactory)Activator .CreateInstance(typeObj,null);
IFeatureWorkspace pWorkSpace = pWsFactory.OpenFromFile(path, 0) as IFeatureWorkspace;
希望这篇文章能够帮助到你。文章为博主原创,转载请注明出处!
欢迎关注微信公众号“GIS带我奔跑”获取更多GIS前沿开发技术、行业应用和最新资讯。