예제 #1
0
        public IEnumInvalidObject ConvertTable(IDatasetName idatasetName_0, IQueryFilter iqueryFilter_0,
                                               IDatasetName idatasetName_1, IFields ifields_0, string string_0, int int_0, int int_1)
        {
            IEnumFieldError    enumFieldError;
            IFields            field;
            string             str;
            IEnumInvalidObject enumInvalidObject = null;
            IFieldChecker      fieldCheckerClass = new FieldChecker();
            IWorkspace         workspace         = (idatasetName_1.WorkspaceName as IName).Open() as IWorkspace;

            fieldCheckerClass.ValidateWorkspace = workspace;
            fieldCheckerClass.Validate(ifields_0, out enumFieldError, out field);
            fieldCheckerClass.ValidateTableName(idatasetName_1.Name, out str);
            string str1  = str;
            ITable table = null;

            table = (workspace as IFeatureWorkspace).CreateTable(str1, field, null, null, string_0);
            ITable  table1  = (idatasetName_0 as IName).Open() as ITable;
            ICursor cursor  = table1.Search(iqueryFilter_0, false);
            int     num     = 0;
            ICursor cursor1 = table.Insert(true);
            IRow    row     = cursor.NextRow();

            while (row != null)
            {
                IRowBuffer rowBuffer = table.CreateRowBuffer();
                try
                {
                    this.method_1(cursor1, rowBuffer, field, row);
                }
                catch (Exception exception)
                {
                    Logger.Current.Error("", exception, "");
                }
                num++;
                if (num == int_0)
                {
                    num = 0;
                    cursor1.Flush();
                }
                row = cursor.NextRow();
                if (this.ifeatureProgress_StepEventHandler_0 == null)
                {
                    continue;
                }
                this.ifeatureProgress_StepEventHandler_0();
            }
            if (num > 0)
            {
                cursor1.Flush();
            }
            ComReleaser.ReleaseCOMObject(cursor);
            ComReleaser.ReleaseCOMObject(cursor1);
            return(enumInvalidObject);
        }
예제 #2
0
        private string method_0(IName iname_0, string string_1)
        {
            string        str;
            IFieldChecker fieldCheckerClass = new FieldChecker()
            {
                ValidateWorkspace = iname_0.Open() as IWorkspace
            };

            fieldCheckerClass.ValidateTableName(string_1, out str);
            fieldCheckerClass = null;
            return(str);
        }
예제 #3
0
        public static string GetFinalName2(IWorkspace iworkspace_0, esriDatasetType esriDatasetType_0, string string_0,
                                           string string_1, string string_2)
        {
            string str2;
            string name = string_0 + string_1 + string_2;
            int    num  = 1;

            if (esriDatasetType_0 == esriDatasetType.esriDTFeatureDataset)
            {
                try
                {
                    while ((iworkspace_0 as IFeatureWorkspace).OpenFeatureDataset(name) != null)
                    {
                        name = string_0 + string_1 + string_2 + "_" + num.ToString();
                        num++;
                    }
                }
                catch
                {
                }
                return(name);
            }
            IFieldChecker checker = new FieldChecker
            {
                ValidateWorkspace = iworkspace_0
            };

            checker.ValidateTableName(string_1, out str2);
            name = string_0 + str2 + string_2;
            if ((iworkspace_0.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) ||
                (iworkspace_0.Type == esriWorkspaceType.esriLocalDatabaseWorkspace))
            {
                while (((IWorkspace2)iworkspace_0).get_NameExists(esriDatasetType.esriDTFeatureClass, name))
                {
                    name = string_0 + str2 + string_2 + "_" + num.ToString();
                    num++;
                }
                return(name);
            }
            if (iworkspace_0.Type != esriWorkspaceType.esriFileSystemWorkspace)
            {
            }
            return(name);
        }
예제 #4
0
        public static void ExtractSelectFeatureFormLayer(IFeatureLayer ifeatureLayer_0,
                                                         IFeatureWorkspace ifeatureWorkspace_0, IGeometry igeometry_0)
        {
            IEnumFieldError enumFieldError;
            IFields         field;
            string          str;
            ICursor         cursor;

            try
            {
                IFeatureSelection ifeatureLayer0 = (IFeatureSelection)ifeatureLayer_0;
                if (ifeatureLayer0.SelectionSet.Count != 0)
                {
                    IFeatureClass featureClass      = ifeatureLayer_0.FeatureClass;
                    IFields       fields            = featureClass.Fields;
                    IFieldChecker fieldCheckerClass = new FieldChecker()
                    {
                        InputWorkspace    = (featureClass as IDataset).Workspace,
                        ValidateWorkspace = ifeatureWorkspace_0 as IWorkspace
                    };
                    fieldCheckerClass.Validate(fields, out enumFieldError, out field);
                    enumFieldError.Reset();
                    IFieldError fieldError = enumFieldError.Next();
                    string      str1       = "";
                    while (fieldError != null)
                    {
                        fieldError.FieldError.ToString();
                        IField   field1 = fields.Field[fieldError.FieldIndex];
                        IField   field2 = field.Field[fieldError.FieldIndex];
                        string   str2   = str1;
                        string[] name   = new string[] { str2, field2.Name, " reason: ", field1.Name, "  " };
                        str1       = string.Concat(name);
                        fieldError = enumFieldError.Next();
                    }
                    Hashtable hashtables = new Hashtable();
                    string    name1      = ifeatureLayer_0.Name;
                    char      chr        = name1[0];
                    if ((chr < '0' ? false : chr <= '9'))
                    {
                        name1 = string.Concat("A", name1);
                    }
                    fieldCheckerClass.ValidateTableName(name1, out str);
                    name1 = str;
                    string      name2       = "";
                    IFieldsEdit fieldsClass = new Fields() as IFieldsEdit;
                    for (int i = field.FieldCount - 1; i >= 0; i--)
                    {
                        IField field3 = field.Field[i];
                        if (field3.Type == esriFieldType.esriFieldTypeGeometry)
                        {
                            name2 = field3.Name;
                            IGeometryDef      geometryDef      = field3.GeometryDef;
                            ISpatialReference spatialReference =
                                (geometryDef.SpatialReference as IClone).Clone() as ISpatialReference;
                            SpatialReferenctOperator.ChangeCoordinateSystem(ifeatureWorkspace_0 as IGeodatabaseRelease,
                                                                            spatialReference, false);
                            (geometryDef as IGeometryDefEdit).SpatialReference_2 = spatialReference;
                            (field3 as IFieldEdit).GeometryDef_2 = geometryDef;
                        }
                        if ((ifeatureWorkspace_0 as IWorkspace).Type != esriWorkspaceType.esriFileSystemWorkspace)
                        {
                            fieldsClass.AddField(field3);
                        }
                        else if (field3.Type != esriFieldType.esriFieldTypeBlob)
                        {
                            fieldsClass.AddField(field3);
                        }
                    }
                    IFeatureClass featureClass1 = null;
                    try
                    {
                        featureClass1 = ifeatureWorkspace_0.CreateFeatureClass(name1, fieldsClass, null, null,
                                                                               esriFeatureType.esriFTSimple, name2, "");
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show("无法创建输出要素类!");
                        return;
                    }
                    IFeatureCursor featureCursor  = null;
                    IFeatureCursor featureCursor1 = featureClass1.Insert(true);
                    IFeatureBuffer featureBuffer  = featureClass1.CreateFeatureBuffer();
                    ifeatureLayer0.SelectionSet.Search(null, false, out cursor);
                    featureCursor = (IFeatureCursor)cursor;
                    for (IFeature j = featureCursor.NextFeature(); j != null; j = featureCursor.NextFeature())
                    {
                        if (j.Shape != null)
                        {
                            Clip.InsertFeature(featureCursor1, featureBuffer, field, j, j.Shape, igeometry_0);
                        }
                    }
                    featureCursor1.Flush();
                    Marshal.ReleaseComObject(featureBuffer);
                    featureBuffer = null;
                    Marshal.ReleaseComObject(featureCursor1);
                    featureCursor1 = null;
                }
            }
            catch
            {
            }
        }
예제 #5
0
        public static void ExtractSelectFeatureFormFeatureCursor(string string_0, IFeatureCursor ifeatureCursor_0,
                                                                 IFeatureWorkspace ifeatureWorkspace_0, IGeometry igeometry_0)
        {
            IEnumFieldError enumFieldError;
            IFields         field;
            string          str;
            string          string0;
            int             num;

            if (ifeatureCursor_0 != null)
            {
                IFields       fields            = ifeatureCursor_0.Fields;
                IFieldChecker fieldCheckerClass = new FieldChecker()
                {
                    ValidateWorkspace = ifeatureWorkspace_0 as IWorkspace
                };
                fieldCheckerClass.Validate(fields, out enumFieldError, out field);
                char chr = string_0[0];
                if ((chr < '0' ? false : chr <= '9'))
                {
                    string_0 = string.Concat("A", string_0);
                }
                fieldCheckerClass.ValidateTableName(string_0, out str);
                string name = "";
                int    num1 = 0;
                while (true)
                {
                    if (num1 < field.FieldCount)
                    {
                        IField field1 = field.Field[num1];
                        if (field1.Type == esriFieldType.esriFieldTypeGeometry)
                        {
                            name = field1.Name;
                            IGeometryDef      geometryDef      = field1.GeometryDef;
                            ISpatialReference spatialReference = geometryDef.SpatialReference;
                            SpatialReferenctOperator.ChangeCoordinateSystem(ifeatureWorkspace_0 as IGeodatabaseRelease,
                                                                            spatialReference, false);
                            (geometryDef as IGeometryDefEdit).SpatialReference_2 = spatialReference;
                            (field1 as IFieldEdit).GeometryDef_2 = geometryDef;
                            break;
                        }
                        else
                        {
                            num1++;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                string_0 = str;
                if (((ifeatureWorkspace_0 as IWorkspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace
                    ? false
                    : (ifeatureWorkspace_0 as IWorkspace).Type != esriWorkspaceType.esriRemoteDatabaseWorkspace))
                {
                    string str1 = string.Concat((ifeatureWorkspace_0 as IWorkspace).PathName, "\\", string_0);
                    string0 = string.Concat(str1, ".shp");
                    num     = 1;
                    while (File.Exists(string0))
                    {
                        string0 = string.Concat(str1, "_", num.ToString(), ".shp");
                        num++;
                    }
                    string_0 = System.IO.Path.GetFileNameWithoutExtension(string0);
                }
                else
                {
                    IWorkspace2 ifeatureWorkspace0 = ifeatureWorkspace_0 as IWorkspace2;
                    string0 = string_0;
                    num     = 1;
                    while (ifeatureWorkspace0.NameExists[esriDatasetType.esriDTFeatureClass, string0])
                    {
                        string0 = string.Concat(string_0, "_", num.ToString());
                        num++;
                    }
                    string_0 = string0;
                }
                try
                {
                    IFeatureClass featureClass = ifeatureWorkspace_0.CreateFeatureClass(string_0, field, null, null,
                                                                                        esriFeatureType.esriFTSimple, name, "");
                    IFeature       feature       = ifeatureCursor_0.NextFeature();
                    IFeatureCursor featureCursor = featureClass.Insert(true);
                    IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
                    while (feature != null)
                    {
                        if (feature.Shape != null)
                        {
                            Clip.InsertFeature(featureCursor, featureBuffer, field, feature, feature.Shape, igeometry_0);
                        }
                        feature = ifeatureCursor_0.NextFeature();
                    }
                    featureCursor.Flush();
                    Marshal.ReleaseComObject(featureClass);
                    featureClass = null;
                    Marshal.ReleaseComObject(featureBuffer);
                    featureBuffer = null;
                    Marshal.ReleaseComObject(featureCursor);
                    featureCursor = null;
                }
                catch
                {
                }
                Marshal.ReleaseComObject(ifeatureCursor_0);
                ifeatureCursor_0 = null;
            }
        }
예제 #6
0
        public static void ClipLayer(IFeatureLayer ifeatureLayer_0, IFeatureClass ifeatureClass_0,
                                     IFeatureWorkspace ifeatureWorkspace_0, IMap imap_0)
        {
            IEnumFieldError enumFieldError;
            IFields         field;
            string          str;

            try
            {
                string        name              = ifeatureLayer_0.Name;
                IFields       fields            = ifeatureLayer_0.FeatureClass.Fields;
                IFieldChecker fieldCheckerClass = new FieldChecker()
                {
                    ValidateWorkspace = ifeatureWorkspace_0 as IWorkspace
                };
                fieldCheckerClass.Validate(fields, out enumFieldError, out field);
                char chr = name[0];
                if ((chr < '0' ? false : chr <= '9'))
                {
                    name = string.Concat("A", name);
                }
                fieldCheckerClass.ValidateTableName(name, out str);
                string name1 = "";
                int    num   = 0;
                while (true)
                {
                    if (num < field.FieldCount)
                    {
                        IField field1 = field.Field[num];
                        if (field1.Type == esriFieldType.esriFieldTypeGeometry)
                        {
                            name1 = field1.Name;
                            IGeometryDef geometryDef = field1.GeometryDef;
                            (geometryDef as IGeometryDefEdit).SpatialReference_2 = geometryDef.SpatialReference;
                            (field1 as IFieldEdit).GeometryDef_2 = geometryDef;
                            break;
                        }
                        else
                        {
                            num++;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                name = str;
                IFeatureClass featureClass = ifeatureWorkspace_0.CreateFeatureClass(name, field, null, null,
                                                                                    esriFeatureType.esriFTSimple, name1, "");
                IFeatureClassName  fullName = (featureClass as IDataset).FullName as IFeatureClassName;
                IBasicGeoprocessor basicGeoprocessorClass = new BasicGeoprocessor();
                IFeatureClass      featureClass1          = basicGeoprocessorClass.Clip(ifeatureLayer_0 as ITable, false,
                                                                                        ifeatureClass_0 as ITable, false, 0, fullName);
                if (imap_0 != null)
                {
                    IFeatureLayer featureLayerClass = new FeatureLayer();
                    (featureLayerClass as IGeoFeatureLayer).Renderer = (ifeatureLayer_0 as IGeoFeatureLayer).Renderer;
                    featureLayerClass.Name         = (featureClass as IDataset).Name;
                    featureLayerClass.FeatureClass = featureClass1;
                    imap_0.AddLayer(featureLayerClass);
                }
            }
            catch
            {
            }
        }
예제 #7
0
        public static void ExtractSelectFeatureFormFeatureCursor(ILayer ilayer_0, IFeatureCursor ifeatureCursor_0,
                                                                 IFeatureWorkspace ifeatureWorkspace_0, IGeometry igeometry_0, IMap imap_0)
        {
            IEnumFieldError enumFieldError;
            IFields         field;
            string          str;
            string          name = ilayer_0.Name;

            if (ifeatureCursor_0 != null)
            {
                IFields       fields            = ifeatureCursor_0.Fields;
                IFieldChecker fieldCheckerClass = new FieldChecker()
                {
                    ValidateWorkspace = ifeatureWorkspace_0 as IWorkspace
                };
                fieldCheckerClass.Validate(fields, out enumFieldError, out field);
                char chr = name[0];
                if ((chr < '0' ? false : chr <= '9'))
                {
                    name = string.Concat("A", name);
                }
                fieldCheckerClass.ValidateTableName(name, out str);
                string name1 = "";
                int    num   = 0;
                while (true)
                {
                    if (num < field.FieldCount)
                    {
                        IField field1 = field.Field[num];
                        if (field1.Type == esriFieldType.esriFieldTypeGeometry)
                        {
                            name1 = field1.Name;
                            IGeometryDef      geometryDef      = field1.GeometryDef;
                            ISpatialReference spatialReference = geometryDef.SpatialReference;
                            SpatialReferenctOperator.ChangeCoordinateSystem(ifeatureWorkspace_0 as IGeodatabaseRelease,
                                                                            spatialReference, false);
                            (geometryDef as IGeometryDefEdit).SpatialReference_2 = spatialReference;
                            (field1 as IFieldEdit).GeometryDef_2 = geometryDef;
                            break;
                        }
                        else
                        {
                            num++;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                name = str;
                IFeatureClass featureClass = ifeatureWorkspace_0.CreateFeatureClass(name, field, null, null,
                                                                                    esriFeatureType.esriFTSimple, name1, "");
                IFeature feature = ifeatureCursor_0.NextFeature();
                if (feature != null)
                {
                    IFeatureCursor featureCursor = featureClass.Insert(true);
                    IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
                    while (feature != null)
                    {
                        if (feature.Shape != null)
                        {
                            try
                            {
                                Clip.InsertFeature(featureCursor, featureBuffer, field, feature, feature.Shape,
                                                   igeometry_0);
                            }
                            catch (Exception exception)
                            {
                                Logger.Current.Error("", exception, "");
                            }
                        }
                        feature = ifeatureCursor_0.NextFeature();
                    }
                    featureCursor.Flush();
                    IFeatureLayer featureLayerClass = new FeatureLayer();
                    (featureLayerClass as IGeoFeatureLayer).Renderer = (ilayer_0 as IGeoFeatureLayer).Renderer;
                    featureLayerClass.Name         = (featureClass as IDataset).Name;
                    featureLayerClass.FeatureClass = featureClass;
                    imap_0.AddLayer(featureLayerClass);
                    featureBuffer = null;
                    featureCursor = null;
                }
            }
        }
예제 #8
0
 public static string GetUniqueFeatureClassName(string name, IWorkspace2 workspace)
 {
     //ToDo: This works to get a unique name but it's goobery, need to implement recursion here...
     try
     {
     IFieldChecker fieldChecker = new FieldChecker();
     string fcName;
     fieldChecker.ValidateTableName(name, out fcName);
     int i = 1;
     while(workspace.get_NameExists(esriDatasetType.esriDTFeatureClass, fcName))
     {
         fcName = fcName + i;
         i++;
     }
     return fcName;
     }
     catch
     {
         return "";
     }
 }
예제 #9
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);
            }
        }
예제 #10
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);
            }
        }
예제 #11
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            IName            internalObjectName;
            IFields          fields2;
            IEnumFieldError  error;
            string           fileNameWithoutExtension;
            string           str4;
            string           name;
            IField           field;
            int              num;
            IGeometryDefEdit geometryDef;
            Exception        exception;
            IFeatureDataset  dataset;

            if (this.txtOutName.Tag == null)
            {
                IGxFolder folder = new GxFolder();
                (folder as IGxFile).Path = Path.GetDirectoryName(this.txtOutName.Text);
                this.txtOutName.Tag      = folder;
            }
            if (this.txtOutName.Tag == null)
            {
                return;
            }
            IGxObject tag = this.txtOutName.Tag as IGxObject;

            if (tag is IGxFolder)
            {
                IWorkspaceName name2 = new WorkspaceName() as IWorkspaceName;


                name2.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
                name2.PathName = (tag.InternalObjectName as IFileName).Path;

                internalObjectName = name2 as IName;
                string text = this.txtOutName.Text;
                if (Path.GetExtension(this.txtOutName.Text) != ".shp")
                {
                    text = Path.GetFileNameWithoutExtension(this.txtOutName.Text) + ".shp";
                }
                if (File.Exists(text))
                {
                    MessageBox.Show("已经存在该shapefile文件,请重新输入文件名");
                    return;
                }
            }
            else
            {
                internalObjectName = tag.InternalObjectName;
            }
            IFields       inputField = this.m_pFeatureLayer.FeatureClass.Fields;
            IFieldChecker checker    = new FieldChecker();
            IFeatureClass class2     = null;

            if (internalObjectName is IWorkspaceName)
            {
                IFeatureWorkspace workspace = internalObjectName.Open() as IFeatureWorkspace;
                checker.ValidateWorkspace = workspace as IWorkspace;
                checker.Validate(inputField, out error, out fields2);
                fileNameWithoutExtension = Path.GetFileNameWithoutExtension(this.txtOutName.Text);
                checker.ValidateTableName(fileNameWithoutExtension, out str4);
                fileNameWithoutExtension = str4;
                ISpatialReference spatialReference = (this.m_pFeatureLayer.FeatureClass as IGeoDataset).SpatialReference;
                if (this.rdoSRType.SelectedIndex == 0)
                {
                    spatialReference = this.m_pMap.SpatialReference;
                }
                name = "";
                for (num = 0; num < fields2.FieldCount; num++)
                {
                    field = fields2.get_Field(num);
                    if (field.Type == esriFieldType.esriFieldTypeGeometry)
                    {
                        geometryDef = (field as IFieldEdit).GeometryDef as IGeometryDefEdit;
                        geometryDef.SpatialReference_2      = spatialReference;
                        (field as IFieldEdit).GeometryDef_2 = geometryDef;
                        name = field.Name;
                        break;
                    }
                }
                try
                {
                    if ((workspace is IWorkspace2) &&
                        (workspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass,
                                                                  fileNameWithoutExtension))
                    {
                        MessageBox.Show("已经存在该要素类,请重新输入要素类名");
                        return;
                    }
                    class2 = workspace.CreateFeatureClass(fileNameWithoutExtension, fields2, null, null,
                                                          esriFeatureType.esriFTSimple, name, "");
                }
                catch (Exception exception1)
                {
                    exception = exception1;
                    MessageBox.Show("无法创建输出要素类!");
                    return;
                }
                goto Label_0400;
            }
            else
            {
                dataset = internalObjectName.Open() as IFeatureDataset;
                IWorkspace workspace2 = dataset.Workspace;
                checker.ValidateWorkspace = workspace2;
                checker.Validate(inputField, out error, out fields2);
                fileNameWithoutExtension = Path.GetFileNameWithoutExtension(this.txtOutName.Text);
                checker.ValidateTableName(fileNameWithoutExtension, out str4);
                fileNameWithoutExtension = str4;
                name = "";
                for (num = 0; num < fields2.FieldCount; num++)
                {
                    field = fields2.get_Field(num);
                    if (field.Type == esriFieldType.esriFieldTypeGeometry)
                    {
                        geometryDef = (field as IFieldEdit).GeometryDef as IGeometryDefEdit;
                        geometryDef.SpatialReference_2      = (dataset as IGeoDataset).SpatialReference;
                        (field as IFieldEdit).GeometryDef_2 = geometryDef;
                        name = field.Name;
                        break;
                    }
                }
            }
            try
            {
                class2 = dataset.CreateFeatureClass(fileNameWithoutExtension, fields2, null, null,
                                                    esriFeatureType.esriFTSimple, name, "");
            }
            catch (Exception exception2)
            {
                exception = exception2;
                MessageBox.Show("无法创建输出要素类!,原因:" + exception.Message);

                return;
            }
Label_0400:
            if (this.cboExportData.SelectedIndex == 0)
            {
                ExportDataHelper.ExportData(this.m_pFeatureLayer, class2, false);
            }
            else if (this.cboExportData.SelectedIndex == 1)
            {
                ISpatialFilter queryFilter = new SpatialFilter()
                {
                    Geometry = (this.m_pMap as IActiveView).Extent
                };
                IFeatureCursor cursor = this.m_pFeatureLayer.Search(queryFilter, false);
                ExportDataHelper.ExportData(cursor, class2);
                ComReleaser.ReleaseCOMObject(cursor);
            }
            else
            {
                ExportDataHelper.ExportData(this.m_pFeatureLayer, class2, true);
            }
            base.DialogResult = DialogResult.OK;
        }
예제 #12
0
 public static void ExtractSelectFeatureFormLayer(IFeatureLayer ifeatureLayer_0,
                                                  IFeatureWorkspace ifeatureWorkspace_0, IGeometry igeometry_0)
 {
     try
     {
         IFeatureSelection featureSelection = (IFeatureSelection)ifeatureLayer_0;
         if (featureSelection.SelectionSet.Count != 0)
         {
             IFeatureClass featureClass = ifeatureLayer_0.FeatureClass;
             IFields       fields       = featureClass.Fields;
             IFieldChecker fieldChecker = new FieldChecker();
             fieldChecker.InputWorkspace    = (featureClass as IDataset).Workspace;
             fieldChecker.ValidateWorkspace = (ifeatureWorkspace_0 as IWorkspace);
             IEnumFieldError enumFieldError;
             IFields         fields2;
             fieldChecker.Validate(fields, out enumFieldError, out fields2);
             enumFieldError.Reset();
             IFieldError fieldError = enumFieldError.Next();
             string      text       = "";
             while (fieldError != null)
             {
                 fieldError.FieldError.ToString();
                 IField field  = fields.get_Field(fieldError.FieldIndex);
                 IField field2 = fields2.get_Field(fieldError.FieldIndex);
                 string text2  = text;
                 text = string.Concat(new string[]
                 {
                     text2,
                     field2.Name,
                     " reason: ",
                     field.Name,
                     "  "
                 });
                 fieldError = enumFieldError.Next();
             }
             new Hashtable();
             string text3 = ifeatureLayer_0.Name;
             string text4;
             fieldChecker.ValidateTableName(text3, out text4);
             text3 = text4;
             string      shapeFieldName = "";
             IFieldsEdit fieldsEdit     = new Fields() as IFieldsEdit;
             for (int i = fields2.FieldCount - 1; i >= 0; i--)
             {
                 IField field3 = fields2.get_Field(i);
                 if (field3.Type == esriFieldType.esriFieldTypeGeometry)
                 {
                     shapeFieldName = field3.Name;
                     IGeometryDef      geometryDef      = field3.GeometryDef;
                     ISpatialReference spatialReference =
                         (geometryDef.SpatialReference as IClone).Clone() as ISpatialReference;
                     SpatialReferenctOperator.ChangeCoordinateSystem(ifeatureWorkspace_0 as IGeodatabaseRelease,
                                                                     spatialReference, false);
                     (geometryDef as IGeometryDefEdit).SpatialReference_2 = spatialReference;
                     (field3 as IFieldEdit).GeometryDef_2 = geometryDef;
                 }
                 if ((ifeatureWorkspace_0 as IWorkspace).Type == esriWorkspaceType.esriFileSystemWorkspace)
                 {
                     if (field3.Type != esriFieldType.esriFieldTypeBlob)
                     {
                         fieldsEdit.AddField(field3);
                     }
                 }
                 else
                 {
                     fieldsEdit.AddField(field3);
                 }
             }
             IFeatureClass featureClass2 = null;
             try
             {
                 featureClass2 = ifeatureWorkspace_0.CreateFeatureClass(text3, fieldsEdit, null, null,
                                                                        esriFeatureType.esriFTSimple, shapeFieldName, "");
             }
             catch (Exception)
             {
                 System.Windows.Forms.MessageBox.Show("无法创建输出要素类!");
                 return;
             }
             IFeatureCursor featureCursor = featureClass2.Insert(true);
             IFeatureBuffer featureBuffer = featureClass2.CreateFeatureBuffer();
             ICursor        cursor;
             featureSelection.SelectionSet.Search(null, false, out cursor);
             IFeatureCursor featureCursor2 = (IFeatureCursor)cursor;
             for (IFeature feature = featureCursor2.NextFeature();
                  feature != null;
                  feature = featureCursor2.NextFeature())
             {
                 if (feature.Shape != null)
                 {
                     ClipHelper.InsertFeature(featureCursor, featureBuffer, fields2, feature, feature.Shape,
                                              igeometry_0);
                 }
             }
             featureCursor.Flush();
             Marshal.ReleaseComObject(featureBuffer);
             Marshal.ReleaseComObject(featureCursor);
         }
     }
     catch
     {
     }
 }
예제 #13
0
        private void method_1(IFeatureClass ifeatureClass_0, IWorkspace iworkspace_0)
        {
            IEnumFieldError enumFieldError;
            IFields         field;
            int             i;
            IField          field1;
            string          str;
            string          aliasName = ifeatureClass_0.AliasName;

            string[] strArrays = aliasName.Split(new char[] { '.' });
            aliasName = strArrays[(int)strArrays.Length - 1];
            IFields       fields            = ifeatureClass_0.Fields;
            IFieldChecker fieldCheckerClass = new FieldChecker()
            {
                ValidateWorkspace = iworkspace_0
            };

            fieldCheckerClass.Validate(fields, out enumFieldError, out field);
            List <SDEToShapefile.FieldMap> fieldMaps = new List <SDEToShapefile.FieldMap>();

            for (i = 0; i < fields.FieldCount; i++)
            {
                field1 = fields.Field[i];
                if (field1.Type != esriFieldType.esriFieldTypeBlob)
                {
                    IField field2 = field.Field[i];
                    fieldMaps.Add(new SDEToShapefile.FieldMap(field1.Name, field2.Name));
                }
            }
            for (i = field.FieldCount - 1; i >= 0; i--)
            {
                field1 = field.Field[i];
                if (field1.Type == esriFieldType.esriFieldTypeBlob)
                {
                    (field as IFieldsEdit).DeleteField(field1);
                }
            }
            fieldCheckerClass.ValidateTableName(aliasName, out str);
            aliasName = string.Concat(this.string_0, "\\", str);
            if (File.Exists(string.Concat(aliasName, ".shp")))
            {
                File.Delete(string.Concat(aliasName, ".shp"));
            }
            if (File.Exists(string.Concat(aliasName, ".shx")))
            {
                File.Delete(string.Concat(aliasName, ".shx"));
            }
            if (File.Exists(string.Concat(aliasName, ".dbf")))
            {
                File.Delete(string.Concat(aliasName, ".dbf"));
            }
            int              num         = field.FindField(ifeatureClass_0.ShapeFieldName);
            IFieldEdit       fieldEdit   = field.Field[num] as IFieldEdit;
            IGeometryDefEdit geometryDef = fieldEdit.GeometryDef as IGeometryDefEdit;

            if (ifeatureClass_0.FeatureType == esriFeatureType.esriFTAnnotation)
            {
                geometryDef.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            }
            ISpatialReference spatialReference = geometryDef.SpatialReference;

            SpatialReferenctOperator.ChangeCoordinateSystem(iworkspace_0 as IGeodatabaseRelease, spatialReference, true);
            geometryDef.SpatialReference_2 = spatialReference;
            fieldEdit.GeometryDef_2        = geometryDef;
            try
            {
                IFeatureClass featureClass = (iworkspace_0 as IFeatureWorkspace).CreateFeatureClass(str, field, null,
                                                                                                    null, esriFeatureType.esriFTSimple, ifeatureClass_0.ShapeFieldName, "");
                this.method_2(ifeatureClass_0 as ITable, featureClass as ITable, fieldMaps, 800);
            }
            catch
            {
            }
        }
예제 #14
0
        public IEnumInvalidObject ConvertFeatureClass(IFeatureClassName ifeatureClassName_0, IQueryFilter iqueryFilter_0,
                                                      IFeatureDatasetName ifeatureDatasetName_0, IFeatureClassName ifeatureClassName_1,
                                                      IGeometryDef igeometryDef_0, IFields ifields_0, string string_0, int int_0, int int_1)
        {
            IEnumFieldError    enumFieldError;
            IFields            field;
            string             str;
            IEnumInvalidObject enumInvalidObject = null;
            IFieldChecker      fieldCheckerClass = new FieldChecker();
            IWorkspaceName     workspaceName     = null;

            workspaceName = (ifeatureDatasetName_0 == null
                ? (ifeatureClassName_1 as IDatasetName).WorkspaceName
                : (ifeatureDatasetName_0 as IDatasetName).WorkspaceName);
            IWorkspace workspace = (workspaceName as IName).Open() as IWorkspace;

            fieldCheckerClass.ValidateWorkspace = workspace;
            fieldCheckerClass.Validate(ifields_0, out enumFieldError, out field);
            string name = (ifeatureClassName_1 as IDatasetName).Name;

            fieldCheckerClass.ValidateTableName(name, out str);
            name = str;
            IField field1 = null;
            int    num    = 0;

            while (true)
            {
                if (num >= field.FieldCount)
                {
                    break;
                }
                else if (field.Field[num].Type == esriFieldType.esriFieldTypeGeometry)
                {
                    field1 = field.Field[num];
                    break;
                }
                else
                {
                    num++;
                }
            }
            IFeatureClass featureClass = null;

            if (ifeatureDatasetName_0 == null)
            {
                featureClass = (workspace as IFeatureWorkspace).CreateFeatureClass(name, field, null, null,
                                                                                   esriFeatureType.esriFTSimple, field1.Name, string_0);
            }
            else
            {
                IFeatureDataset featureDataset = (ifeatureDatasetName_0 as IName).Open() as IFeatureDataset;
                featureClass = featureDataset.CreateFeatureClass(name, field, null, null, esriFeatureType.esriFTSimple,
                                                                 field1.Name, string_0);
            }
            IFeatureClass  featureClass1  = (ifeatureClassName_0 as IName).Open() as IFeatureClass;
            IFeatureCursor featureCursor  = featureClass1.Search(iqueryFilter_0, false);
            IFeature       feature        = featureCursor.NextFeature();
            int            num1           = 0;
            IFeatureCursor featureCursor1 = featureClass.Insert(true);

            while (feature != null)
            {
                IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
                if (feature.Shape != null)
                {
                    try
                    {
                        this.method_0(featureCursor1, featureBuffer, field, feature);
                    }
                    catch (Exception exception)
                    {
                        Logger.Current.Error("", exception, "");
                    }
                }
                num1++;
                if (num1 == int_0)
                {
                    num1 = 0;
                    featureCursor1.Flush();
                }
                feature = featureCursor.NextFeature();
                if (this.ifeatureProgress_StepEventHandler_0 == null)
                {
                    continue;
                }
                this.ifeatureProgress_StepEventHandler_0();
            }
            if (num1 > 0)
            {
                featureCursor1.Flush();
            }
            ComReleaser.ReleaseCOMObject(featureCursor);
            ComReleaser.ReleaseCOMObject(featureCursor1);
            return(enumInvalidObject);
        }