Exemplo n.º 1
0
        public static void Project(IFeatureDataset ifeatureDataset_0, ISpatialReference ispatialReference_0,
                                   IWorkspace iworkspace_0, string string_0)
        {
            IGeometryDef      geometryDefClass = new GeometryDef();
            ISpatialReference spatialReference = ((IGeoDataset)ifeatureDataset_0).SpatialReference;

            ((IGeometryDefEdit)geometryDefClass).SpatialReference_2 = ispatialReference_0;
            IWorkspace            workspace = ifeatureDataset_0.Workspace;
            IFeatureDataConverter featureDataConverterClass = new FeatureDataConverter();
            IWorkspaceName        workspaceNameClass        = new WorkspaceName() as IWorkspaceName as IWorkspaceName;


            workspaceNameClass.ConnectionProperties   = workspace.ConnectionProperties;
            workspaceNameClass.WorkspaceFactoryProgID = workspace.WorkspaceFactory.GetClassID().Value.ToString();

            IWorkspaceName connectionProperties = new WorkspaceName() as IWorkspaceName as IWorkspaceName;
            PropertySet    propertySetClass     = new PropertySet();

            connectionProperties.ConnectionProperties   = iworkspace_0.ConnectionProperties;
            connectionProperties.WorkspaceFactoryProgID = iworkspace_0.WorkspaceFactory.GetClassID().Value.ToString();
            IDatasetName featureDatasetNameClass = new FeatureDatasetName() as IDatasetName;
            string       name = ifeatureDataset_0.Name;
            int          num  = name.LastIndexOf(".");

            if (num != -1)
            {
                name = name.Substring(num + 1);
            }
            featureDatasetNameClass.Name          = name;
            featureDatasetNameClass.WorkspaceName = workspaceNameClass;
            IDatasetName datasetName = new FeatureDatasetName() as IDatasetName;

            {
                datasetName.WorkspaceName = connectionProperties;
                datasetName.Name          = string_0;
            }
            ;
            featureDataConverterClass.ConvertFeatureDataset((IFeatureDatasetName)featureDatasetNameClass,
                                                            (IFeatureDatasetName)datasetName, geometryDefClass, "", 1000, 0);
        }
Exemplo n.º 2
0
        public static void Project(IFeatureClass ifeatureClass_0, ISpatialReference ispatialReference_0,
                                   IWorkspace iworkspace_0, string string_0, double double_0)
        {
            string                str;
            double                num;
            double                num1;
            double                num2;
            double                num3;
            IEnumFieldError       enumFieldError;
            IFields               field;
            IWorkspace            workspace = ((IDataset)ifeatureClass_0).Workspace;
            IFeatureDataConverter featureDataConverterClass = new FeatureDataConverter();
            IWorkspaceName        workspaceNameClass        = new WorkspaceName() as IWorkspaceName;

            workspaceNameClass.ConnectionProperties   = workspace.ConnectionProperties;
            workspaceNameClass.WorkspaceFactoryProgID = workspace.WorkspaceFactory.GetClassID().Value.ToString();

            IWorkspaceName connectionProperties = new WorkspaceName() as IWorkspaceName;
            PropertySet    propertySetClass     = new PropertySet();

            connectionProperties.ConnectionProperties   = iworkspace_0.ConnectionProperties;
            connectionProperties.WorkspaceFactoryProgID = iworkspace_0.WorkspaceFactory.GetClassID().Value.ToString();
            IDatasetName featureClassNameClass = new FeatureClassName() as IDatasetName;
            string       aliasName             = ifeatureClass_0.AliasName;
            int          num4 = aliasName.LastIndexOf(".");

            if (num4 != -1)
            {
                aliasName = aliasName.Substring(num4 + 1);
            }
            featureClassNameClass.Name          = aliasName;
            featureClassNameClass.WorkspaceName = workspaceNameClass;
            IDatasetName datasetName = new FeatureClassName() as IDatasetName;

            {
                datasetName.WorkspaceName = connectionProperties;
            }
            ;
            IFieldChecker fieldCheckerClass = new FieldChecker()
            {
                ValidateWorkspace = iworkspace_0
            };

            string[] strArrays = string_0.Split(new char[] { '.' });
            string_0 = string.Concat(strArrays[(int)strArrays.Length - 1], "_Project");
            fieldCheckerClass.ValidateTableName(string_0, out str);
            string str1 = str;
            int    num5 = 1;

            if (
                !(iworkspace_0.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace
                    ? false
                    : iworkspace_0.Type != esriWorkspaceType.esriLocalDatabaseWorkspace))
            {
                while (((IWorkspace2)iworkspace_0).NameExists[esriDatasetType.esriDTFeatureClass, str1])
                {
                    str1 = string.Concat(str, "_", num5.ToString());
                    num5++;
                }
            }
            else if (iworkspace_0.Type == esriWorkspaceType.esriFileSystemWorkspace)
            {
                while (File.Exists(string.Concat(str1, ".shp")))
                {
                    str1 = string.Concat(str, "_", num5.ToString());
                    num5++;
                }
            }
            datasetName.Name = str1;
            IFields fieldsClass = new ESRI.ArcGIS.Geodatabase.Fields();

            num4 = ifeatureClass_0.Fields.FindField(ifeatureClass_0.ShapeFieldName);
            IField            field1           = ifeatureClass_0.Fields.Field[num4];
            IGeometryDef      geometryDef      = field1.GeometryDef;
            ISpatialReference spatialReference = geometryDef.SpatialReference;

            ispatialReference_0.GetDomain(out num, out num1, out num2, out num3);
            ((IGeometryDefEdit)geometryDef).GridCount_2        = 1;
            ((IGeometryDefEdit)geometryDef).GridSize_2[0]      = double_0;
            ((IGeometryDefEdit)geometryDef).SpatialReference_2 = ispatialReference_0;
            ((IFieldEdit)field1).GeometryDef_2 = geometryDef;
            for (int i = 0; i < ifeatureClass_0.Fields.FieldCount; i++)
            {
                if (i != num4)
                {
                    IField field2 = ifeatureClass_0.Fields.Field[i];
                    ((IFieldsEdit)fieldsClass).AddField(field2);
                }
                else
                {
                    ((IFieldsEdit)fieldsClass).AddField(field1);
                }
            }
            fieldCheckerClass.Validate(fieldsClass, out enumFieldError, out field);
            if (SRLibCommonFunc.m_pfrm != null)
            {
                SRLibCommonFunc.m_pfrm.FeatureProgress = featureDataConverterClass;
            }
            try
            {
                featureDataConverterClass.ConvertFeatureClass((IFeatureClassName)featureClassNameClass, null, null,
                                                              (IFeatureClassName)datasetName, geometryDef, field, "", 1000, 0);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Exemplo n.º 3
0
        public static void Project(IFeatureClass ifeatureClass_0, ISpatialReference ispatialReference_0,
                                   IFeatureDatasetName ifeatureDatasetName_0, string string_0, double double_0)
        {
            IWorkspace            workspace            = ((IDataset)ifeatureClass_0).Workspace;
            IFeatureDataConverter featureDataConverter = new FeatureDataConverter();
            IWorkspaceName        workspaceName        = new WorkspaceName() as IWorkspaceName;

            workspaceName.ConnectionProperties   = workspace.ConnectionProperties;
            workspaceName.WorkspaceFactoryProgID = workspace.WorkspaceFactory.GetClassID().Value.ToString();
            IWorkspaceName workspaceName2 = (ifeatureDatasetName_0 as IDatasetName).WorkspaceName;
            IDatasetName   datasetName    = new FeatureClassName() as IDatasetName;
            string         text           = ifeatureClass_0.AliasName;
            int            num            = text.LastIndexOf(".");

            if (num != -1)
            {
                text = text.Substring(num + 1);
            }
            datasetName.Name          = text;
            datasetName.WorkspaceName = workspaceName;
            IWorkspace2  workspace2   = (workspaceName2 as IName).Open() as IWorkspace2;
            IDatasetName datasetName2 = new FeatureClassName() as IDatasetName;

            datasetName2.WorkspaceName = workspaceName2;
            (datasetName2 as IFeatureClassName).FeatureDatasetName = (ifeatureDatasetName_0 as IDatasetName);
            IFieldChecker fieldChecker = new FieldChecker();

            fieldChecker.ValidateWorkspace = (workspace2 as IWorkspace);
            string[] array = string_0.Split(new char[]
            {
                '.'
            });
            string_0 = array[array.Length - 1] + "_Project";
            string text2;

            fieldChecker.ValidateTableName(string_0, out text2);
            string text3 = text2;
            int    num2  = 1;

            if (workspaceName2.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace ||
                workspaceName2.Type == esriWorkspaceType.esriLocalDatabaseWorkspace)
            {
                while (workspace2.get_NameExists(esriDatasetType.esriDTFeatureClass, text3))
                {
                    text3 = text2 + "_" + num2.ToString();
                    num2++;
                }
            }
            else if (workspaceName2.Type == esriWorkspaceType.esriFileSystemWorkspace)
            {
                while (System.IO.File.Exists(text3 + ".shp"))
                {
                    text3 = text2 + "_" + num2.ToString();
                    num2++;
                }
            }
            datasetName2.Name = text3;
            IFields fields = new ESRI.ArcGIS.Geodatabase.Fields() as IFields;

            num = ifeatureClass_0.Fields.FindField(ifeatureClass_0.ShapeFieldName);
            IField            field       = ifeatureClass_0.Fields.get_Field(num);
            IGeometryDef      geometryDef = field.GeometryDef;
            ISpatialReference arg_1D9_0   = geometryDef.SpatialReference;
            double            num3;
            double            num4;
            double            num5;
            double            num6;

            ispatialReference_0.GetDomain(out num3, out num4, out num5, out num6);
            ((IGeometryDefEdit)geometryDef).GridCount_2 = 1;
            ((IGeometryDefEdit)geometryDef).set_GridSize(0, double_0);
            ((IGeometryDefEdit)geometryDef).SpatialReference_2 = ispatialReference_0;
            ((IFieldEdit)field).GeometryDef_2 = geometryDef;
            for (int i = 0; i < ifeatureClass_0.Fields.FieldCount; i++)
            {
                if (i == num)
                {
                    ((IFieldsEdit)fields).AddField(field);
                }
                else
                {
                    IField field2 = ifeatureClass_0.Fields.get_Field(i);
                    ((IFieldsEdit)fields).AddField(field2);
                }
            }
            IEnumFieldError enumFieldError;
            IFields         outputFields;

            fieldChecker.Validate(fields, out enumFieldError, out outputFields);
            if (SRLibCommonFunc.m_pfrm != null)
            {
                SRLibCommonFunc.m_pfrm.FeatureProgress = featureDataConverter;
            }
            try
            {
                featureDataConverter.ConvertFeatureClass((IFeatureClassName)datasetName, null, ifeatureDatasetName_0,
                                                         (IFeatureClassName)datasetName2, geometryDef, outputFields, "", 1000, 0);
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 将指定要素类复制到目标数据库中(在目标数据库中创建要素类)
        /// </summary>
        /// <param name="pSrcFC">源要素类</param>
        /// <param name="pQueryFilter">查询条件</param>
        /// <param name="pTargetWks">目标数据库</param>
        /// <param name="sMessage">转换消息</param>
        /// <param name="sTargetName">目标要素类名</param>
        /// <param name="sAlias">目标要素类别名</param>
        /// <param name="sFDatasetName">目标要素数据集</param>
        /// <returns></returns>
        public bool TranslateFeatureClass(IFeatureClass pSrcFC, IQueryFilter pQueryFilter, IWorkspace pTargetWks, string sTargetName = null, string sAlias = null, string sFDatasetName = null)
        {
            GeoDataUtils geoDataUtils = new GeoDataUtils();

            IDataset            pSrcDataset         = pSrcFC as IDataset;
            IFeatureClassName   pSrcName            = pSrcDataset.FullName as IFeatureClassName;
            IFeatureDatasetName pFeatureDatasetName = null;

            if (pTargetWks.Type != esriWorkspaceType.esriFileSystemWorkspace)
            {
                string sFeatureDatasetName = sFDatasetName;
                if (string.IsNullOrEmpty(sFeatureDatasetName) && pSrcFC.FeatureDataset != null)
                {
                    sFeatureDatasetName = geoDataUtils.ExtractDatasetName(pSrcFC.FeatureDataset.Name);
                }
                if (!string.IsNullOrEmpty(sFeatureDatasetName))
                {
                    if (geoDataUtils.IsNameExist(pTargetWks, sFeatureDatasetName, esriDatasetType.esriDTFeatureDataset))
                    {
                        IFeatureDataset pTargetFeatureDataset = (pTargetWks as IFeatureWorkspace).OpenFeatureDataset(sFeatureDatasetName);
                        pFeatureDatasetName = pTargetFeatureDataset.FullName as IFeatureDatasetName;
                        Marshal.ReleaseComObject(pTargetFeatureDataset);
                    }
                    else
                    {
                        pFeatureDatasetName = new FeatureDatasetName() as IFeatureDatasetName;
                        IDatasetName pDatasetName = pFeatureDatasetName as IDatasetName;
                        pDatasetName.Name          = sFeatureDatasetName;
                        pDatasetName.WorkspaceName = (pTargetWks as IDataset).FullName as IWorkspaceName;
                    }
                }
            }

            //目标要素类名
            FeatureClassName pTargetName        = new FeatureClassName();
            IDatasetName     pTargetDatasetName = pTargetName as IDatasetName;

            if (string.IsNullOrEmpty(sTargetName))
            {
                sTargetName = geoDataUtils.ExtractDatasetName(pSrcDataset.Name);
            }
            pTargetDatasetName.Name          = sTargetName;
            pTargetDatasetName.WorkspaceName = (pTargetWks as IDataset).FullName as IWorkspaceName;
            geoDataUtils.DeleteDataset(pTargetWks, pTargetDatasetName);

            // 验证字段
            IFields pTargetFields;
            string  sShapeFieldName;

            geoDataUtils.CheckFields(pSrcFC, pTargetWks, out pTargetFields, out sShapeFieldName);
            IEnumInvalidObject    pEnumInvalidObject = null;
            IFeatureDataConverter pConverter         = null;

            try
            {
                int          iIndex             = pTargetFields.FindField(sShapeFieldName);
                IGeometryDef pTargetGeometryDef = pTargetFields.get_Field(iIndex).GeometryDef;

                // 执行批量转换
                pConverter         = new FeatureDataConverter();
                pEnumInvalidObject = pConverter.ConvertFeatureClass(pSrcName, pQueryFilter, pFeatureDatasetName as IFeatureDatasetName,
                                                                    pTargetName as IFeatureClassName, pTargetGeometryDef, pTargetFields, "", 1000, 0);

                // 检查转换过程中是否产生错误
                if (pEnumInvalidObject != null)
                {
                    IInvalidObjectInfo pInvalidInfo = null;
                    pEnumInvalidObject.Reset();
                    while ((pInvalidInfo = pEnumInvalidObject.Next()) != null)
                    {
                        ErrorMessage += pSrcFC.AliasName + "图层要素:" + pInvalidInfo.InvalidObjectID + "执行失败!";
                    }
                }
            }
            finally //释放资源
            {
                if (pEnumInvalidObject != null)
                {
                    Marshal.ReleaseComObject(pEnumInvalidObject);
                }
                if (pConverter != null)
                {
                    Marshal.ReleaseComObject(pConverter);
                }
            }
            //修改要素类别名
            if (string.IsNullOrEmpty(sAlias))
            {
                sAlias = pSrcFC.AliasName;
            }
            IFeatureClass pTargetFC = (pTargetWks as IFeatureWorkspace).OpenFeatureClass(sTargetName);

            geoDataUtils.AlterDatasetAlias(pTargetFC, sAlias);
            Marshal.ReleaseComObject(pTargetFC);
            return(true);
        }