コード例 #1
0
ファイル: FrmExportMxd.cs プロジェクト: eglrp/TESTPROJECT-1
        private IFeatureClass CopyFeatureClassToWorkspace(IMap map, ILayer layer, IWorkspace2 wksDst, bool bLayerSpatial)
        {
            IFeatureClass pFtClassNew = null;

            if (layer is IFeatureLayer)
            {
                IFeatureLayer featureLayer = layer as IFeatureLayer;
                if (featureLayer.FeatureClass == null)
                {
                    return(null);
                }

                IFeatureClass featureClass = featureLayer.FeatureClass;
                //注记图层
                //if (featureClass.FeatureType == esriFeatureType.esriFTAnnotation) return null;

                //设置空间参考
                ISpatialReference spatialRef;
                if (bLayerSpatial)
                {
                    IGeoDataset pGeo = (IGeoDataset)featureLayer;
                    spatialRef = pGeo.SpatialReference;
                }
                else
                {
                    spatialRef = map.SpatialReference;
                }
                //打开GDB的WORKSPACE

                ClsGDBDataCommon cls = new ClsGDBDataCommon();
                //字段拷贝
                //创建fields
                IFields pFields = ClsGDBDataCommon.CopyFeatureField(featureClass, spatialRef);
                if (pFields == null)
                {
                    MessageBox.Show("拷贝图形字段失败!");
                    return(null);
                }
                //创建FeatureClass
                //创建新的FeatureClass
                //注记图层
                if (featureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    pFtClassNew = cls.CreateAnnotationClass(featureClass, layer.Name, wksDst, spatialRef);
                }
                else
                {
                    pFtClassNew = cls.CreateFeatureClass(wksDst, null, layer.Name, pFields, null, null, null, true, featureClass.FeatureType);
                }

                if (pFtClassNew == null)
                {
                    MessageBox.Show("创建shp文件失败!");
                    return(null);
                }
                //拷贝Feature
                if (ClsGDBDataCommon.CopyFeatures(featureLayer, pFtClassNew, false) == false)
                {
                    MessageBox.Show("拷贝失败!");
                }
            }
            return(pFtClassNew);
        }