Beispiel #1
0
        private string GenerateTemp3DPolygonStorage()
        {
            string newFeatureClassName = $"Polygon3D_L{Helper.GetTemporaryNameSuffix()}";

            IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDescription = (IObjectClassDescription)fcDescription;
            IFields fields = ocDescription.RequiredFields;

            int shapeFieldIndex = fields.FindField(fcDescription.ShapeFieldName);

            IField           field           = fields.get_Field(shapeFieldIndex);
            IGeometryDef     geometryDef     = field.GeometryDef;
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            geometryDefEdit.HasZ_2             = true;
            geometryDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPolygon;
            geometryDefEdit.SpatialReference_2 = ArcMapInstance.Document.FocusMap.SpatialReference;

            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;

            IField     isVisibleField     = new FieldClass();
            IFieldEdit isVisibleFieldEdit = (IFieldEdit)isVisibleField;

            isVisibleFieldEdit.Name_2 = "IS_VISIBLE";
            isVisibleFieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
            fieldsEdit.AddField(isVisibleFieldEdit);

            GenerateTempStorage(newFeatureClassName, fields, esriGeometryType.esriGeometryPolygon);
            return(newFeatureClassName);
        }
Beispiel #2
0
        /// <summary>
        /// 创建一个要素集
        /// </summary>
        /// <param name="shpfolder"></param>
        /// <param name="shpname"></param>
        /// <returns></returns>
        public static IFeatureClass CreatePolygonFeatureClass(string shpfolder, string shpname)
        {
            IWorkspaceFactory pWorkSpaceFac     = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pFeatureWorkSpace = pWorkSpaceFac.OpenFromFile(shpfolder, 0) as IFeatureWorkspace;

            //创建字段集2
            IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDescription = (IObjectClassDescription)fcDescription;//创建必要字段
            IFields          fields          = ocDescription.RequiredFields;
            int              shapeFieldIndex = fields.FindField(fcDescription.ShapeFieldName);
            IField           field           = fields.get_Field(shapeFieldIndex);
            IGeometryDef     geometryDef     = field.GeometryDef;
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            //geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            //geometryDefEdit.SpatialReference_2 = spatialReference;

            geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
            ISpatialReferenceFactory   pSpatialRefFac = new SpatialReferenceEnvironmentClass();
            IProjectedCoordinateSystem pcsSys         = pSpatialRefFac.CreateProjectedCoordinateSystem((int)esriSRProjCS4Type.esriSRProjCS_Xian1980_3_Degree_GK_Zone_39);

            geometryDefEdit.SpatialReference_2 = pcsSys;

            IFieldChecker   fieldChecker    = new FieldCheckerClass();
            IEnumFieldError enumFieldError  = null;
            IFields         validatedFields = null; //将传入字段 转成 validatedFields

            fieldChecker.ValidateWorkspace = (IWorkspace)pFeatureWorkSpace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            IFeatureClass featureClass = pFeatureWorkSpace.CreateFeatureClass(shpname, validatedFields, ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDescription.ShapeFieldName, "");

            AddField(featureClass, "BuildID", "自带id", 50);
            return(featureClass);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (!String.IsNullOrEmpty(textBox1.Text) && !String.IsNullOrEmpty(textBox2.Text))
                {
                    string     databasefilename = openFileDialog1.FileName;
                    IWorkspace workspace        = AccessWorkspaceFromPropertySet(databasefilename);

                    ISpatialReference        spatialreference = map.SpatialReference;
                    IFeatureClassDescription fcDesc           = new FeatureClassDescriptionClass();
                    IObjectClassDescription  ocDesc           = (IObjectClassDescription)fcDesc;
                    IFeatureClassDescription fcDescription    = new FeatureClassDescriptionClass();
                    IFeatureWorkspace        featureworkspace = (IFeatureWorkspace)workspace;
                    IFeatureClass            featureclass     = CreateFeatureClass(textBox1.Text, featureworkspace);
                    if (featureclass == null)
                    {
                        MessageBox.Show("Feature Class not created");
                    }
                    else
                    {
                        MessageBox.Show("Feature Class successfull created");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
            textBox1.Clear();
            textBox2.Clear();
            panel3.Visible = false;
        }
Beispiel #4
0
        private static IFeatureClass CreateFeaturepointClass(String featureClassName, IFeatureWorkspace featureWorkspace, ISpatialReference spatialReference)
        {
            try
            {
                IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
                IObjectClassDescription  ocDescription = (IObjectClassDescription)fcDescription;
                IFields fields = ocDescription.RequiredFields;

                int              shapeFieldIndex = fields.FindField(fcDescription.ShapeFieldName);
                IField           field           = fields.get_Field(shapeFieldIndex);
                IGeometryDef     geometryDef     = field.GeometryDef;
                IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
                geometryDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPoint;
                geometryDefEdit.SpatialReference_2 = spatialReference;

                IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(featureClassName, fields,
                                                                                 ocDescription.ClassExtensionCLSID, ocDescription.InstanceCLSID, esriFeatureType.esriFTSimple,
                                                                                 fcDescription.ShapeFieldName, "");
                return(featureClass);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "异常");
                return(null);
            }
        }
Beispiel #5
0
        public static IFeatureClass CreateFeatureClass(IWorkspace workspace, string featureClassName, esriGeometryType type, ISpatialReference spatialReference)
        {
            IFeatureWorkspace        pFeatureWorkspace        = workspace as IFeatureWorkspace;
            IFeatureClassDescription pFeatureClassDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  pObjectClassDescription  = pFeatureClassDescription as IObjectClassDescription;
            IFields     pFields     = pObjectClassDescription.RequiredFields;
            IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;

            for (int i = 0; i < pFields.FieldCount; i++)
            {
                if (pFieldsEdit.Field[i].Type == esriFieldType.esriFieldTypeGeometry)
                {
                    IFieldEdit       pFieldEdit       = pFieldsEdit.Field[i] as IFieldEdit;
                    IGeometryDef     pGeometryDef     = new GeometryDefClass();
                    IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
                    pGeometryDefEdit.GeometryType_2     = type;
                    pGeometryDefEdit.SpatialReference_2 = spatialReference;
                    pFieldEdit.GeometryDef_2            = pGeometryDef;
                }
            }

            IFieldChecker   pFieldChecker   = new FieldCheckerClass();
            IEnumFieldError enumFieldError  = null;
            IFields         validatedFields = null;

            pFieldChecker.ValidateWorkspace = workspace;
            pFieldChecker.Validate(pFields, out enumFieldError, out validatedFields);

            return(pFeatureWorkspace.CreateFeatureClass(featureClassName, validatedFields,
                                                        pObjectClassDescription.InstanceCLSID, pObjectClassDescription.ClassExtensionCLSID,
                                                        esriFeatureType.esriFTSimple, "SHAPE", ""));
        }
Beispiel #6
0
        public static IFields CreateFields(esriGeometryType geoType)
        {
            IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDescription = (IObjectClassDescription)fcDescription;
            IFields fields = ocDescription.RequiredFields;

            int              shapeFieldIndex = fields.FindField(fcDescription.ShapeFieldName);
            IField           field           = fields.get_Field(shapeFieldIndex);
            IGeometryDef     geometryDef     = field.GeometryDef;
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            geometryDefEdit.GeometryType_2 = geoType;
            ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            var sr = spatialReferenceFactory.CreateGeographicCoordinateSystem(4326);

            geometryDefEdit.SpatialReference_2 = sr;

            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;

            field = new FieldClass();
            IFieldEdit fieldEdit = (IFieldEdit)field;

            fieldEdit.Name_2 = "Name";
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            fieldsEdit.AddField(field);

            return(fields);
        }
        /// <summary>
        /// create a feature class in workspace with type geometry
        /// </summary>
        /// <param name="geometry">geometry of feature class</param>
        /// <param name="featureWorkspace">workspace for store feature class</param>
        /// <returns>feature class created</returns>
        private IFeatureClass CreateFeatureClass(IGeometry geometry, IFeatureWorkspace featureWorkspace)
        {
            // Create a fields collection for the feature class.
            IFields     fields     = new FieldsClass();
            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;

            // Add an object ID field to the fields collection. This is mandatory for feature classes.
            IField     oidField     = new FieldClass();
            IFieldEdit oidFieldEdit = (IFieldEdit)oidField;

            oidFieldEdit.Name_2 = "OID";
            oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            fieldsEdit.AddField(oidField);

            IField     idField     = new FieldClass();
            IFieldEdit idFieldEdit = (IFieldEdit)idField;

            idFieldEdit.Name_2 = SAUtility.FieldNameIdWatershed;
            idFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
            fieldsEdit.AddField(idField);

            // Create a geometry definition (and spatial reference) for the feature class.
            IGeometryDef     geometryDef     = new GeometryDefClass();
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            geometryDefEdit.GeometryType_2     = geometry.GeometryType;
            geometryDefEdit.SpatialReference_2 = geometry.SpatialReference;

            IFeatureClassDescription featureClassDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  objectClassDescription  = (IObjectClassDescription)featureClassDescription;

            // Add a geometry field to the fields collection. This is where the geometry definition is applied.
            IField     geometryField     = new FieldClass();
            IFieldEdit geometryFieldEdit = (IFieldEdit)geometryField;

            geometryFieldEdit.Name_2        = featureClassDescription.ShapeFieldName;
            geometryFieldEdit.Type_2        = esriFieldType.esriFieldTypeGeometry;
            geometryFieldEdit.GeometryDef_2 = geometryDef;
            fieldsEdit.AddField(geometryField);

            // Use IFieldChecker to create a validated fields collection.
            IFieldChecker   fieldChecker    = new FieldCheckerClass();
            IEnumFieldError enumFieldError  = null;
            IFields         validatedFields = null;

            fieldChecker.ValidateWorkspace = (IWorkspace)featureWorkspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.
            // Create the feature class. Note that the CLSID parameter is null - this indicates to use the
            // default CLSID, esriGeodatabase.Feature (acceptable in most cases for feature classes).
            IFeatureClass featureClass = featureWorkspace.CreateFeatureClass("pourPoint", validatedFields, objectClassDescription.InstanceCLSID, objectClassDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, featureClassDescription.ShapeFieldName, string.Empty);

            return(featureClass);
        }
Beispiel #8
0
        //字段集
        private IFields CreateFieldsCollectionForFeatueClass(ISpatialReference spatialReference,
                                                             esriGeometryType geometryType, string className)
        {
            //Use the feature class description to return the required fields in a fields collection.
            IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDesc = (IObjectClassDescription)fcDesc;
            //Create the fields using the required fields method.
            IFields fields = ocDesc.RequiredFields;
            //Locate the shape field with the name from the feature class description.
            int    shapeFieldIndex = fields.FindField(fcDesc.ShapeFieldName);
            IField shapeField      = fields.get_Field(shapeFieldIndex);
            //Modify the GeometryDef object before using the fields collection to create a
            //feature class.
            IGeometryDef     geometryDef     = shapeField.GeometryDef;
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            //Alter the feature class geometry type to the type we need.
            geometryDefEdit.GeometryType_2 = geometryType;
            geometryDefEdit.HasZ_2         = true;
            geometryDefEdit.HasM_2         = true;
            geometryDefEdit.GridCount_2    = 1;
            //Set the first grid size to zero and allow ArcGIS to determine a valid grid size.
            geometryDefEdit.set_GridSize(0, 0);
            geometryDefEdit.SpatialReference_2 = spatialReference;
            //添加地质属性概率字段
            if (geometryType == esriGeometryType.esriGeometryPoint)
            {
                //Create a user-defined double field for "probability"
                IFieldsEdit fieldsEdit      = (IFieldsEdit)fields;
                IField      incomeField     = new FieldClass();
                IFieldEdit  incomeFieldEdit = (IFieldEdit)incomeField;
                incomeFieldEdit.AliasName_2  = "probability";
                incomeFieldEdit.Editable_2   = true;
                incomeFieldEdit.IsNullable_2 = false;
                incomeFieldEdit.Name_2       = "probability";
                incomeFieldEdit.Precision_2  = 2;
                incomeFieldEdit.Scale_2      = 5;
                incomeFieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
                fieldsEdit.AddField(incomeField);
                //Create a user-defined double field for "RegardP"
                IFieldsEdit fieldsEdit1      = (IFieldsEdit)fields;
                IField      incomeField1     = new FieldClass();
                IFieldEdit  incomeFieldEdit1 = (IFieldEdit)incomeField1;
                incomeFieldEdit1.AliasName_2  = "RegardP";
                incomeFieldEdit1.Editable_2   = true;
                incomeFieldEdit1.IsNullable_2 = false;
                incomeFieldEdit1.Name_2       = "RegardP";
                incomeFieldEdit1.Precision_2  = 2;
                incomeFieldEdit1.Scale_2      = 5;
                incomeFieldEdit1.Type_2       = esriFieldType.esriFieldTypeDouble;
                fieldsEdit1.AddField(incomeField1);
            }
            return(fields);
        }
Beispiel #9
0
        private void button2_Click(object sender, EventArgs e)
        {
            //工作空间
            IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(pFilePath, 0) as IFeatureWorkspace;

            //创建字段集2
            IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
            //创建必要字段
            IObjectClassDescription ocDescription = (IObjectClassDescription)fcDescription;

            //必要字段
            IFields pFields = new FieldsClass();

            pFields = ocDescription.RequiredFields;

            //要素类的几何类型、坐标系
            int              shapeFileIndex   = pFields.FindField(fcDescription.ShapeFieldName);
            IField           pField           = pFields.get_Field(shapeFileIndex);
            IGeometryDef     pGeometryDef     = pField.GeometryDef;
            IGeometryDefEdit pGeometryDefEdit = (IGeometryDefEdit)pGeometryDef;

            pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();

            //更改为可选的坐标系
            IProjectedCoordinateSystem pProjectedCoordinateSystem = pSpatialReferenceFactory.CreateProjectedCoordinateSystem(
                (int)esriSRProjCS4Type.esriSRProjCS_Xian1980_GK_Zone_21);

            pGeometryDefEdit.SpatialReference_2 = pProjectedCoordinateSystem;


            //自定义字段
            IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;

            addField(pFieldsEdit, "FID");
            addField(pFieldsEdit, "Row");
            addField(pFieldsEdit, "Column");
            addField(pFieldsEdit, "Number");
            //传入字段
            IFieldChecker   pFieldChecker   = new FieldCheckerClass();
            IEnumFieldError pEnumFieldError = null;
            IFields         validatedFields = null;

            pFieldChecker.ValidateWorkspace = (IWorkspace)pFeatureWorkspace;
            pFieldChecker.Validate(pFields, out pEnumFieldError, out validatedFields);

            //创建要素类
            IFeatureClass pFeatureClass = pFeatureWorkspace.CreateFeatureClass(pFileName, validatedFields
                                                                               , ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDescription.ShapeFieldName, "");

            MessageBox.Show("创建要素类成功");
        }
Beispiel #10
0
        /// <summary>
        /// 将Shapefile导入到数据库
        /// </summary>
        /// <param name="pFeaClass"></param>
        /// <param name="pWorkspace"></param>
        /// <param name="tFeatureClass"></param>
        private void importToDB(IFeatureClass pFeaClass, IWorkspace pWorkspace, IFeatureDataset tFeatureClass, string SHPName)
        {
            IFeatureClassDescription featureClassDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  objectClassDescription  = featureClassDescription as IObjectClassDescription;

            IFields         pFields         = pFeaClass.Fields;
            IFieldChecker   pFieldChecker   = new FieldCheckerClass();
            IEnumFieldError pEnumFieldError = null;
            IFields         vFields         = null;

            pFieldChecker.ValidateWorkspace = pWorkspace as IWorkspace;
            pFieldChecker.Validate(pFields, out pEnumFieldError, out vFields);
            IFeatureWorkspace featureWorkspace = pWorkspace as IFeatureWorkspace;
            IFeatureClass     sdeFeatureClass  = null;

            if (sdeFeatureClass == null)
            {
                sdeFeatureClass = tFeatureClass.CreateFeatureClass(SHPName, vFields,
                                                                   objectClassDescription.InstanceCLSID, objectClassDescription.ClassExtensionCLSID,
                                                                   pFeaClass.FeatureType, pFeaClass.ShapeFieldName, "");
                IFeatureCursor featureCursor    = pFeaClass.Search(null, true);
                IFeature       feature          = featureCursor.NextFeature();
                IFeatureCursor sdeFeatureCursor = sdeFeatureClass.Insert(true);
                IFeatureBuffer sdeFeatureBuffer;
                while (feature != null)
                {
                    sdeFeatureBuffer = sdeFeatureClass.CreateFeatureBuffer();
                    IField  shpField  = new FieldClass();
                    IFields shpFields = feature.Fields;
                    for (int i = 0; i < shpFields.FieldCount; i++)
                    {
                        shpField = shpFields.get_Field(i);
                        if (shpField.Name.Contains("Area") || shpField.Name.Contains("Leng") || shpField.Name.Contains("FID"))
                        {
                            continue;
                        }
                        int index = sdeFeatureBuffer.Fields.FindField(shpField.Name);
                        if (index != -1)
                        {
                            sdeFeatureBuffer.set_Value(index, feature.get_Value(i));
                        }
                    }
                    sdeFeatureCursor.InsertFeature(sdeFeatureBuffer);
                    sdeFeatureCursor.Flush();
                    feature = featureCursor.NextFeature();
                }
                featureCursor.Flush();
                Marshal.ReleaseComObject(feature);
                Marshal.ReleaseComObject(featureCursor);
            }
        }
Beispiel #11
0
        /// <summary>
        /// 创建指定名称的FeatureClass 适用于创建Stops和Barriers
        /// </summary>
        /// <param name="workspace"></param>
        /// <param name="name"></param>
        /// <param name="spatialReference">与主窗体上的axMapcontrol的连接吧...</param>
        public static IFeatureClass CreateFeatureClass(IFeatureWorkspace workspace, string name, ISpatialReference spatialReference = null)
        {
            if (spatialReference == null)
            {
                spatialReference = ApplicationV.GlobalMapControl.ActiveView.FocusMap.SpatialReference;
            }

            //创建字段集
            IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDescription = (IObjectClassDescription)fcDescription;

            //创建字段组
            IFields     pFields     = new FieldsClass();
            IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;

            IField     Field_OID      = new FieldClass();
            IFieldEdit Field_OID_EDIT = Field_OID as IFieldEdit;

            Field_OID_EDIT.Name_2       = "OBJECTID";
            Field_OID_EDIT.Type_2       = esriFieldType.esriFieldTypeOID;
            Field_OID_EDIT.IsNullable_2 = false;
            Field_OID_EDIT.Required_2   = false;
            pFieldsEdit.AddField(Field_OID);

            //创建一个必要的东西
            IGeometryDef     geoDef     = new GeometryDefClass();
            IGeometryDefEdit geoDefEdit = (IGeometryDefEdit)geoDef;

            geoDefEdit.AvgNumPoints_2     = 5;
            geoDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPoint;
            geoDefEdit.GridCount_2        = 1;
            geoDefEdit.HasM_2             = false;
            geoDefEdit.HasZ_2             = false;
            geoDefEdit.SpatialReference_2 = spatialReference;


            //创建SHAPE字段
            IField     Field_SHAPE      = new FieldClass();
            IFieldEdit pFieldEdit_SHAPE = (IFieldEdit)Field_SHAPE;

            pFieldEdit_SHAPE.Name_2        = "SHAPE";
            pFieldEdit_SHAPE.Type_2        = esriFieldType.esriFieldTypeGeometry;
            pFieldEdit_SHAPE.GeometryDef_2 = geoDef;

            //放入组
            pFieldsEdit.AddField(Field_SHAPE);


            //正式创建要素类
            return(workspace.CreateFeatureClass(name, pFields, ocDescription.ClassExtensionCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDescription.ShapeFieldName, ""));
        }
Beispiel #12
0
        /// <summary>
        /// 创建要素类
        /// </summary>
        /// <param name="featureWorkspace"></param>
        /// <param name="name"></param>
        /// <param name="esriGeometryType"></param>
        /// <param name="fielddict"></param>
        /// <returns></returns>
        public static IFeatureClass CreateFeatureClass(IFeatureWorkspace featureWorkspace, string name, esriGeometryType esriGeometryType, Dictionary <string, GISField> fielddict)
        {
            IFields     fields     = new FieldsClass();
            IFieldsEdit fieldsedit = fields as IFieldsEdit;
            IField      field      = new FieldClass();
            IFieldEdit  fieldedit  = field as IFieldEdit;

            fieldedit.Name_2 = "shape";
            fieldedit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            IGeometryDef     geometryDef      = new GeometryDefClass();
            IGeometryDefEdit pGeometryDefEdit = geometryDef as IGeometryDefEdit;

            pGeometryDefEdit.GeometryType_2 = esriGeometryType;

            ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            ISpatialReference        pSpatialReference        = pSpatialReferenceFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);

            pSpatialReference.SetDomain(-6000000, 6000000, -6000000, 6000000);
            pGeometryDefEdit.SpatialReference_2 = pSpatialReference;
            fieldedit.GeometryDef_2             = geometryDef;
            fieldsedit.AddField(field);

            field            = new FieldClass();
            fieldedit        = field as IFieldEdit;
            fieldedit.Name_2 = "FID";
            fieldedit.Type_2 = esriFieldType.esriFieldTypeOID;
            fieldsedit.AddField(field);

            foreach (var entry in fielddict)
            {
                if (entry.Key.ToUpper() == "SHAPE" || entry.Key.ToUpper() == "OBJECTID")
                {
                    continue;
                }
                field            = new FieldClass();
                fieldedit        = field as IFieldEdit;
                fieldedit.Name_2 = entry.Key;
                fieldedit.Type_2 = entry.Value.Type;
                fieldsedit.AddField(field);
            }


            IFeatureClassDescription featureClassDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  objectClassDescription  = featureClassDescription as IObjectClassDescription;
            IFeatureClass            featureClass            = featureWorkspace.CreateFeatureClass(name, fields, objectClassDescription.InstanceCLSID, objectClassDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, "shape", "");

            return(featureClass);
        }
Beispiel #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="featureDataset"></param>
        /// <param name="strNameOfFeatureClass"></param>
        /// <param name="isDissolved"></param>
        /// <returns></returns>
        public static IFeatureClass CreateCurveAreaFeatureClass(IFeatureDataset featureDataset, String strNameOfFeatureClass, bool isDissolved)
        {
            // This function creates a new feature class in a supplied feature dataset by building all of the
            // fields from scratch. IFeatureClassDescription (or IObjectClassDescription if the table is
            // created at the workspace level) can be used to get the required fields and are used to
            // get the InstanceClassID and ExtensionClassID.
            // Create new fields collection with the number of fields you plan to add. Must add at least two fields
            // for a feature class: Object ID and Shape field.


            // Create a feature class description object to use for specifying the CLSID and EXTCLSID.
            IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDesc = (IObjectClassDescription)fcDesc;

            return(featureDataset.CreateFeatureClass(strNameOfFeatureClass, GetCurveAreaFields(false, isDissolved), ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, "SHAPE", ""));
        }
Beispiel #14
0
        private IFeatureClass CreateNewFeatureClass(IWorkspace pWS, String featureClassName, IFields pFields, esriFeatureType pEsriFeatureType)
        {
            IFeatureClassDescription fcDesc          = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDesc          = fcDesc as IObjectClassDescription;
            IFieldChecker            pFieldChecker   = new FieldCheckerClass();
            IEnumFieldError          pEnumFieldError = null;
            IFields           validatedFields        = null;
            IFeatureWorkspace pFeatureWorkspace      = pWS as IFeatureWorkspace;

            pFieldChecker.ValidateWorkspace = pWS;
            pFieldChecker.Validate(pFields, out pEnumFieldError, out validatedFields);

            IFeatureClass pFeatureClass = pFeatureWorkspace.CreateFeatureClass(featureClassName, validatedFields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, pEsriFeatureType, fcDesc.ShapeFieldName, "");

            return(pFeatureClass);
        }
Beispiel #15
0
        public string GenerateTempProfileLinesStorage()
        {
            IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)calcWorkspace;

            workspaceEdit.StartEditing(true);
            workspaceEdit.StartEditOperation();

            string newFeatureClassName = $"{calcFeatureClass}{MilSpace.DataAccess.Helper.GetTemporaryNameSuffix()}";

            IWorkspace2       wsp2             = (IWorkspace2)calcWorkspace;
            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)calcWorkspace;

            if (!wsp2.get_NameExists(esriDatasetType.esriDTFeatureClass, newFeatureClassName))
            {
                IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
                IObjectClassDescription  ocDescription = (IObjectClassDescription)fcDescription;
                IFields fields = ocDescription.RequiredFields;


                // Find the shape field in the required fields and modify its GeometryDef to
                // use point geometry and to set the spatial reference.

                int shapeFieldIndex = fields.FindField(fcDescription.ShapeFieldName);

                IField           field           = fields.get_Field(shapeFieldIndex);
                IGeometryDef     geometryDef     = field.GeometryDef;
                IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
                geometryDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPolyline;
                geometryDefEdit.SpatialReference_2 = ArcMapInstance.Document.FocusMap.SpatialReference;;

                IFieldsEdit fieldsEdit    = (IFieldsEdit)fields;
                IField      nameField     = new FieldClass();
                IFieldEdit  nameFieldEdit = (IFieldEdit)nameField;
                nameFieldEdit.Name_2 = "ID";
                nameFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
                fieldsEdit.AddField(nameField);

                IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(newFeatureClassName, fields,
                                                                                 ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, "shape", "");
            }

            workspaceEdit.StopEditOperation();
            workspaceEdit.StopEditing(true);

            return(newFeatureClassName);
        }
Beispiel #16
0
        //using a class description object创建一个新要素类,并赋予空间参考和要素类型
        private IFeatureClass CreateFeatureClass(String featureClassName, IFeatureWorkspace featureWorkspace, ISpatialReference spatialReference)
        {  //实例化要素类描述对象,获得默认字段
            IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDescription = (IObjectClassDescription)fcDescription;
            IFields fields = ocDescription.RequiredFields;
            // 找到图形字段定义空间参考和类型
            int              shapeFieldIndex = fields.FindField(fcDescription.ShapeFieldName);
            IField           field           = fields.get_Field(shapeFieldIndex);
            IGeometryDef     geometryDef     = field.GeometryDef;
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            geometryDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPolygon;
            geometryDefEdit.SpatialReference_2 = spatialReference;

            IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(featureClassName, fields, ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID,
                                                                             esriFeatureType.esriFTSimple, fcDescription.ShapeFieldName, "");

            return(featureClass);
        }
Beispiel #17
0
        /// <summary>
        /// Creates the photo featureclass.
        /// </summary>
        /// <param name="workspace">The workspace.</param>
        /// <param name="featureclassname">The featureclassname.</param>
        /// <returns>IFeatureClass for GPS Photos</returns>
        private IFeatureClass CreatePhotoFeatureclass(IWorkspace workspace, string featureclassname)
        {
            ISpatialReference spatialReference = Utility.GetWGS84SpatialReference();

            IFeatureClassDescription featureclassDesc = new FeatureClassDescriptionClass();
            IObjectClassDescription  objectclassDesc  = (IObjectClassDescription)featureclassDesc;

            try
            {
                IFeatureClass featureclass = this.CreateFeatureClass((IFeatureWorkspace)workspace, featureclassname, spatialReference);

                return(featureclass);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.StackTrace);
                throw;
            }
        }
        //用帮助里的例子,修改了字段和空间参考
        public IFeatureClass CreateFeatureClass(String featureClassName, IFeatureWorkspace featureWorkspace, IField[] arrFields)
        {
            // Instantiate a feature class description to get the required fields.
            IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDescription = (IObjectClassDescription)fcDescription;
            IFields     fields     = ocDescription.RequiredFields;
            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;

            // Add some fields to the required fields.
            foreach (IField pField in arrFields)
            {
                fieldsEdit.AddField(pField);
            }

            // Find the shape field in the required fields and modify its GeometryDef to
            // use point geometry and to set the spatial reference.
            int              shapeFieldIndex = fields.FindField(fcDescription.ShapeFieldName);
            IField           field           = fields.get_Field(shapeFieldIndex);
            IGeometryDef     geometryDef     = field.GeometryDef;
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            geometryDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPolygon;
            geometryDefEdit.SpatialReference_2 = this.pMapControl.SpatialReference;//导进来的要素类使用当前地图的空间参考

            // Use IFieldChecker to create a validated fields collection.
            IFieldChecker   fieldChecker    = new FieldCheckerClass();
            IEnumFieldError enumFieldError  = null;
            IFields         validatedFields = null;

            fieldChecker.ValidateWorkspace = (IWorkspace)featureWorkspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.

            // Create the feature class.//这一步极易出错,一般都是名为featureClassName的文件已存在
            IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields,
                                                                             ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple,
                                                                             fcDescription.ShapeFieldName, "");

            return(featureClass);
        }
Beispiel #19
0
        private IFeatureClass method_2(IFeatureWorkspace ifeatureWorkspace_0, string string_4,
                                       esriFeatureType esriFeatureType_0, esriGeometryType esriGeometryType_0, IFields ifields_0)
        {
            IFeatureClass class2 = null;
            string        str;
            IFieldChecker checker = new FieldCheckerClass
            {
                ValidateWorkspace = ifeatureWorkspace_0 as IWorkspace
            };

            checker.ValidateTableName(string_4, out str);
            IObjectClassDescription description = null;

            if (esriFeatureType_0 == esriFeatureType.esriFTAnnotation)
            {
                return(this.method_1(ifeatureWorkspace_0, string_4, 1000.0, new TextSymbolClass(), ifields_0));
            }
            description = new FeatureClassDescriptionClass();
            IFieldsEdit requiredFields = description.RequiredFields as IFieldsEdit;
            IFieldEdit  edit2          = null;
            int         index          = requiredFields.FindField((description as IFeatureClassDescription).ShapeFieldName);

            edit2 = requiredFields.get_Field(index) as IFieldEdit;
            IGeometryDefEdit geometryDef  = edit2.GeometryDef as IGeometryDefEdit;
            esriFeatureType  esriFTSimple = esriFeatureType.esriFTSimple;

            edit2.GeometryDef_2 = geometryDef;
            for (int i = 0; i < ifields_0.FieldCount; i++)
            {
                requiredFields.AddField(ifields_0.get_Field(i));
            }
            try
            {
                class2 = ifeatureWorkspace_0.CreateFeatureClass(string_4, requiredFields, null, null, esriFTSimple,
                                                                (description as IFeatureClassDescription).ShapeFieldName, "");
            }
            catch (Exception exception)
            {
                Logger.Current.Error("", exception, "");
            }
            return(class2);
        }
Beispiel #20
0
        public IFeatureClass CreateFeatureDatasetFeatureClass(IFeatureDataset featureDataset, String featureClassName, IFields fieldsCollection, esriFeatureType featureType, String shapeFieldName)
        {
            IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDesc = (IObjectClassDescription)fcDesc;

            // Use IFieldChecker to create a validated fields collection.
            IFieldChecker   fieldChecker    = new FieldCheckerClass();
            IEnumFieldError enumFieldError  = null;
            IFields         validatedFields = null;

            fieldChecker.ValidateWorkspace = featureDataset.Workspace;
            fieldChecker.Validate(fieldsCollection, out enumFieldError, out validatedFields);

            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.
            IFeatureClass featureClass = featureDataset.CreateFeatureClass(featureClassName, validatedFields, ocDesc.InstanceCLSID,
                                                                           ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, "");

            return(featureClass);
        }
Beispiel #21
0
        private IFields CreateFieldsCollection(ISpatialReference spatialReference, esriGeometryType geometryType)
        {
            IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDesc = fcDesc as IObjectClassDescription;

            IFields     fields     = ocDesc.RequiredFields;
            IFieldsEdit fieldsEdit = fields as IFieldsEdit;

            int    shapeFieldIndex = fields.FindField(fcDesc.ShapeFieldName);
            IField shapeField      = fields.get_Field(shapeFieldIndex);

            IGeometryDef     geometryDef     = shapeField.GeometryDef;
            IGeometryDefEdit geometryDefEdit = geometryDef as IGeometryDefEdit;

            geometryDefEdit.GeometryType_2 = geometryType;
            geometryDefEdit.GridCount_2    = 1;
            geometryDefEdit.set_GridSize(0, 0);
            geometryDefEdit.SpatialReference_2 = spatialReference;

            return(fields);
        }
        public IFeatureClass CreateFeatureClass(String featureClassName, IFeatureWorkspace featureWorkspace)
        {
            CreateFieldForm f = new CreateFieldForm();

            if (f.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
                    IObjectClassDescription  ocDescription = (IObjectClassDescription)fcDescription;
                    IFields     fields     = ocDescription.RequiredFields;
                    IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
                    for (int i = 0; i < MyGlobalClass.fields.Length; i++)
                    {
                        IField     field     = new FieldClass();
                        IFieldEdit fieldEdit = (IFieldEdit)field;
                        fieldEdit.Name_2 = MyGlobalClass.fields[i].name;
                        fieldEdit.Type_2 = MyGlobalClass.fields[i].type;
                        fieldsEdit.AddField(field);
                    }
                    IFieldChecker   fieldChecker    = new FieldCheckerClass();
                    IEnumFieldError enumFieldError  = null;
                    IFields         validatedFields = null;
                    fieldChecker.ValidateWorkspace = (IWorkspace)featureWorkspace;
                    fieldChecker.Validate(fields, out enumFieldError, out validatedFields);
                    IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDescription.ShapeFieldName, "");
                    return(featureClass);
                }

                catch (Exception ex)
                {
                    MessageBox.Show("Error is function CreateFeatureClass: " + ex.Message);
                }
            }

            return(null);
        }
Beispiel #23
0
        private void GenerateTempStorage(string featureClassName, IFields fields, esriGeometryType type)
        {
            IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)calcWorkspace;

            workspaceEdit.StartEditing(true);
            workspaceEdit.StartEditOperation();

            IWorkspace2       wsp2             = (IWorkspace2)calcWorkspace;
            IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)calcWorkspace;

            if (!wsp2.get_NameExists(esriDatasetType.esriDTFeatureClass, featureClassName))
            {
                IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
                IObjectClassDescription  ocDescription = (IObjectClassDescription)fcDescription;

                if (fields == null)
                {
                    fields = ocDescription.RequiredFields;

                    int shapeFieldIndex = fields.FindField(fcDescription.ShapeFieldName);

                    IField           field           = fields.get_Field(shapeFieldIndex);
                    IGeometryDef     geometryDef     = field.GeometryDef;
                    IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
                    geometryDefEdit.HasZ_2             = true;
                    geometryDefEdit.GeometryType_2     = type;
                    geometryDefEdit.SpatialReference_2 = ArcMapInstance.Document.FocusMap.SpatialReference;
                }

                IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(featureClassName, fields,
                                                                                 ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, "shape", "");
            }

            workspaceEdit.StopEditOperation();
            workspaceEdit.StopEditing(true);
        }
Beispiel #24
0
        /// <summary>
        /// 创建照片点集FeatureClass
        /// </summary>
        private IFeatureClass CreateFeatureClass()
        {
            //创建字段集
            IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDescription = (IObjectClassDescription)fcDescription;

            //创建字段组
            IFields     pFields     = new FieldsClass();
            IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;

            IField     Field_OID      = new FieldClass();
            IFieldEdit Field_OID_EDIT = Field_OID as IFieldEdit;

            Field_OID_EDIT.Name_2       = "OBJECTID";
            Field_OID_EDIT.Type_2       = esriFieldType.esriFieldTypeOID;
            Field_OID_EDIT.IsNullable_2 = false;
            Field_OID_EDIT.Required_2   = false;
            pFieldsEdit.AddField(Field_OID);

            //创建一个必要的东西
            IGeometryDef     geoDef     = new GeometryDefClass();
            IGeometryDefEdit geoDefEdit = (IGeometryDefEdit)geoDef;

            geoDefEdit.AvgNumPoints_2     = 5;
            geoDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPoint;
            geoDefEdit.GridCount_2        = 1;
            geoDefEdit.HasM_2             = false;
            geoDefEdit.HasZ_2             = false;
            geoDefEdit.SpatialReference_2 = mainMapControl.SpatialReference;


            //创建SHAPE字段
            IField     Field_SHAPE      = new FieldClass();
            IFieldEdit pFieldEdit_SHAPE = (IFieldEdit)Field_SHAPE;

            pFieldEdit_SHAPE.Name_2        = "SHAPE";
            pFieldEdit_SHAPE.Type_2        = esriFieldType.esriFieldTypeGeometry;
            pFieldEdit_SHAPE.GeometryDef_2 = geoDef;
            pFieldsEdit.AddField(Field_SHAPE);

            //创建Name字段
            IField     Field_Name      = new FieldClass();
            IFieldEdit pFieldEdit_Name = (IFieldEdit)Field_Name;

            pFieldEdit_Name.Name_2 = "Name";
            pFieldEdit_Name.Type_2 = esriFieldType.esriFieldTypeString;
            pFieldsEdit.AddField(Field_Name);

            //创建latitude字段
            IField     Field_Lat      = new FieldClass();
            IFieldEdit pFieldEdit_Lat = (IFieldEdit)Field_Lat;

            pFieldEdit_Lat.Name_2 = "Latitude";
            pFieldEdit_Lat.Type_2 = esriFieldType.esriFieldTypeDouble;
            pFieldsEdit.AddField(Field_Lat);

            //创建longtitude字段
            IField     Field_Log      = new FieldClass();
            IFieldEdit pFieldEdit_Log = (IFieldEdit)Field_Log;

            pFieldEdit_Log.Name_2 = "Longtitude";
            pFieldEdit_Log.Type_2 = esriFieldType.esriFieldTypeDouble;
            pFieldsEdit.AddField(Field_Log);

            //创建OssPath字段
            IField     Field_OSSpath      = new FieldClass();
            IFieldEdit pFieldEdit_OSSpath = (IFieldEdit)Field_OSSpath;

            pFieldEdit_OSSpath.Name_2 = "OSSpath";
            pFieldEdit_OSSpath.Type_2 = esriFieldType.esriFieldTypeString;
            pFieldsEdit.AddField(Field_OSSpath);


            //正式创建要素类
            try
            {
                return(MemoryWorkspace.CreateFeatureClass("特征地物照片", pFields, ocDescription.ClassExtensionCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDescription.ShapeFieldName, ""));
            }
            //The table already exists. 清除数据重建
            catch (Exception e)
            {
                Console.WriteLine(e);
                IFeatureClass tmp    = MemoryWorkspace.OpenFeatureClass("特征地物照片");
                ITable        pTable = tmp as ITable;
                pTable.DeleteSearchedRows(null);
                return(tmp);
            }
        }
Beispiel #25
0
        public static IFeatureClass CreateFeatureClass(IFeatureWorkspace featureWorkspace, esriGeometryType esriGeometryType, ISpatialReference spatialReference, StockTable stockTable)
        {
            IFields     fields     = new FieldsClass();
            IFieldsEdit fieldsedit = fields as IFieldsEdit;
            IField      field      = new FieldClass();
            IFieldEdit  fieldedit  = field as IFieldEdit;

            fieldedit.Name_2 = "shape";
            fieldedit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            IGeometryDef     geometryDef      = new GeometryDefClass();
            IGeometryDefEdit pGeometryDefEdit = geometryDef as IGeometryDefEdit;

            pGeometryDefEdit.GeometryType_2 = esriGeometryType;

            pGeometryDefEdit.SpatialReference_2 = spatialReference;
            fieldedit.GeometryDef_2             = geometryDef;
            fieldsedit.AddField(field);

            field            = new FieldClass();
            fieldedit        = field as IFieldEdit;
            fieldedit.Name_2 = "OBJECTID";
            fieldedit.Type_2 = esriFieldType.esriFieldTypeOID;
            fieldsedit.AddField(field);

            field                 = new FieldClass();
            fieldedit             = field as IFieldEdit;
            fieldedit.Name_2      = "XZSDM";
            fieldedit.AliasName_2 = "行政市代码";
            fieldedit.Type_2      = esriFieldType.esriFieldTypeString;
            fieldsedit.AddField(field);

            field                 = new FieldClass();
            fieldedit             = field as IFieldEdit;
            fieldedit.Name_2      = "XZSMC";
            fieldedit.AliasName_2 = "行政市名称";
            fieldedit.Type_2      = esriFieldType.esriFieldTypeString;
            fieldsedit.AddField(field);

            field                 = new FieldClass();
            fieldedit             = field as IFieldEdit;
            fieldedit.Name_2      = "XZXDM";
            fieldedit.AliasName_2 = "行政县代码";
            fieldedit.Type_2      = esriFieldType.esriFieldTypeString;
            fieldsedit.AddField(field);

            field                 = new FieldClass();
            fieldedit             = field as IFieldEdit;
            fieldedit.Name_2      = "XZXMC";
            fieldedit.AliasName_2 = "行政县名称";
            fieldedit.Type_2      = esriFieldType.esriFieldTypeString;
            fieldsedit.AddField(field);

            foreach (var item in stockTable.Fields)
            {
                field                 = new FieldClass();
                fieldedit             = field as IFieldEdit;
                fieldedit.Name_2      = item.Name;
                fieldedit.AliasName_2 = item.Title;
                switch (item.Type)
                {
                case Models.FieldType.Char:
                    fieldedit.Type_2 = esriFieldType.esriFieldTypeString;
                    break;

                case Models.FieldType.Float:
                    fieldedit.Type_2 = esriFieldType.esriFieldTypeDouble;
                    break;

                case Models.FieldType.Int:
                    fieldedit.Type_2 = esriFieldType.esriFieldTypeInteger;
                    break;
                }
                fieldsedit.AddField(field);
            }
            IFeatureClassDescription featureClassDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  objectClassDescription  = featureClassDescription as IObjectClassDescription;
            IFeatureClass            featureClass            = featureWorkspace.CreateFeatureClass(stockTable.Name, fields, objectClassDescription.InstanceCLSID, objectClassDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, "shape", "");

            return(featureClass);
        }
Beispiel #26
0
        public void CopyFeatures(LoadTarget target)
        {
            IWorkspaceFactory sourceWsf;

            if (System.IO.Path.GetExtension(target.In_Directory).ToUpper().Equals(".GDB"))
            {
                sourceWsf = new FileGDBWorkspaceFactoryClass();
            }
            else
            {
                sourceWsf = new ShapefileWorkspaceFactoryClass();
            }
            IFeatureWorkspace sourceFeatWs       = sourceWsf.OpenFromFile(target.In_Directory, 0) as IFeatureWorkspace;
            IFeatureClass     sourceFeatureClass = sourceFeatWs.OpenFeatureClass(target.In_FileName);

            IWorkspaceFactory targetWsf;

            if (System.IO.Path.GetExtension(target.Out_Directory).ToUpper().Equals(".GDB"))
            {
                targetWsf = new FileGDBWorkspaceFactoryClass();
            }
            else
            {
                targetWsf = new ShapefileWorkspaceFactoryClass();
            }

            IWorkspace targetWs = targetWsf.OpenFromFile(target.Out_Directory, 0) as IWorkspace;

            string targetFileName;

            if (System.IO.Path.GetExtension(target.Out_Directory).ToUpper().Equals(".GDB"))
            {
                targetFileName = LoadHelper.GetNameGDB(target.Out_Directory, target.Out_FileName);
            }
            else
            {
                targetFileName = LoadHelper.GetNameShapeFile(target.Out_Directory, target.Out_FileName);
            }

            IFeatureWorkspace        targetFeatWs            = targetWs as IFeatureWorkspace;
            IFeatureClassDescription featureClassDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  objectClassDescription  = featureClassDescription as IObjectClassDescription;

            IFields         pFields         = sourceFeatureClass.Fields;
            IFieldChecker   pFieldChecker   = new FieldCheckerClass();
            IEnumFieldError pEnumFieldError = null;
            IFields         vFields         = null;

            pFieldChecker.ValidateWorkspace = targetWs as IWorkspace;
            pFieldChecker.Validate(pFields, out pEnumFieldError, out vFields);

            IFeatureClass sdeFeatureClass = null;

            if (sdeFeatureClass == null)
            {
                sdeFeatureClass = targetFeatWs.CreateFeatureClass(targetFileName, vFields,
                                                                  objectClassDescription.InstanceCLSID, objectClassDescription.ClassExtensionCLSID,
                                                                  sourceFeatureClass.FeatureType, sourceFeatureClass.ShapeFieldName, "");
                IFeatureCursor featureCursor    = sourceFeatureClass.Search(null, true);
                IFeature       feature          = featureCursor.NextFeature();
                IFeatureCursor sdeFeatureCursor = sdeFeatureClass.Insert(true);
                IFeatureBuffer sdeFeatureBuffer;
                IQueryFilter   qf = new QueryFilterClass();
                target.Size = sourceFeatureClass.FeatureCount(qf);
                while (feature != null)
                {
                    sdeFeatureBuffer = sdeFeatureClass.CreateFeatureBuffer();
                    IField  shpField  = new FieldClass();
                    IFields shpFields = feature.Fields;
                    for (int i = 0; i < shpFields.FieldCount; i++)
                    {
                        shpField = shpFields.get_Field(i);
                        if (shpField.Name.ToLower().Contains("area") || shpField.Name.ToLower().Contains("leng") || shpField.Name.ToLower().Contains("fid") || shpField.Name.ToLower().Contains("objectid"))
                        {
                            continue;
                        }
                        int index = sdeFeatureBuffer.Fields.FindField(shpField.Name);
                        if (index != -1)
                        {
                            sdeFeatureBuffer.set_Value(index, feature.get_Value(i));
                        }
                    }
                    sdeFeatureCursor.InsertFeature(sdeFeatureBuffer);
                    sdeFeatureCursor.Flush();
                    feature = featureCursor.NextFeature();
                    target.Progress++;
                }
                featureCursor.Flush();
                target.IsFinished = true;
                target.IsBusy     = false;
            }
        }
Beispiel #27
0
        private IFeatureClass CreateFeatureClass(IFeatureDataset featureDataset,TableStructureNode tableStructureNode, FeatureCodeNode featureCodeNode) 
        {
            try
            {
                if (featureDataset != null)
                {
                    IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
                    IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc;
         
                    ///创建数据表字段
                    IFieldChecker fieldChecker = new FieldCheckerClass();
                    IEnumFieldError enumFieldError = null;
                    IFields validatedFields = CreateFileds(tableStructureNode, featureCodeNode);
                    ///字段信息验证
                    IFields fixFields = null;
                    fieldChecker.ValidateWorkspace = featureDataset.Workspace;
                    fieldChecker.Validate(validatedFields, out enumFieldError, out fixFields);

                    ////创建FeatureClass
                    IFeatureClass featureClass = null;
                    if (tableStructureNode.IsGeometryTable)
                    {
                        ////创建非注记FeatureClass
                        if (featureCodeNode.GeometryType != "")
                        {
                            featureClass = featureDataset.CreateFeatureClass(featureCodeNode.TableName,
                               fixFields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID,
                               esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, "");
                        }
                        else
                        {
                            ///创建注记
                            IFormattedTextSymbol pTxtSymbo=new TextSymbolClass();

                            IFeatureWorkspaceAnno pFeatureWorkspaceAnno = this.m_pIDataset.Workspace as IFeatureWorkspaceAnno;

                            IGraphicsLayerScale pGraphSacle = new GraphicsLayerScaleClass();
                            pGraphSacle.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriFeet;
                            //pGraphSacle.ReferenceScale=1000;


                            ISymbolCollection pSymbolCollection = new SymbolCollectionClass();

                            IAnnotateLayerProperties pAnnoLayerProp = new LabelEngineLayerPropertiesClass();
                            pAnnoLayerProp.FeatureLinked = true;
                            pAnnoLayerProp.CreateUnplacedElements = false;
                            pAnnoLayerProp.DisplayAnnotation = true;
                            pAnnoLayerProp.UseOutput = true;

                            IAnnotationExpressionEngine pAnnoExpressionEngine =new AnnotationVBScriptEngineClass();
                            ILabelEngineLayerProperties pLabelEngineLayerProperties = pAnnoLayerProp as ILabelEngineLayerProperties;
                            pLabelEngineLayerProperties.ExpressionParser = pAnnoExpressionEngine;
                            pLabelEngineLayerProperties.Expression = "[DESCRIPTION]";
                            pLabelEngineLayerProperties.IsExpressionSimple = true;
                            pLabelEngineLayerProperties.Offset = 0;
                            pLabelEngineLayerProperties.SymbolID = 0;
                            pLabelEngineLayerProperties.Symbol = pTxtSymbo;

                            IAnnotateLayerTransformationProperties pAnnoLayerTransProp = pAnnoLayerProp as IAnnotateLayerTransformationProperties;
                            pAnnoLayerTransProp.ReferenceScale=200;
                            pAnnoLayerTransProp.Units= ESRI.ArcGIS.esriSystem.esriUnits.esriFeet;
                            pAnnoLayerTransProp.ScaleRatio=1;

                            IAnnotateLayerPropertiesCollection pAnnoLayerProptyCollection =new AnnotateLayerPropertiesCollectionClass();
                           pAnnoLayerProptyCollection.Add(pAnnoLayerProp);

                           featureClass= pFeatureWorkspaceAnno.CreateAnnotationClass(featureCodeNode.TableName,fixFields,ocDesc.InstanceCLSID
                               ,ocDesc.ClassExtensionCLSID,fcDesc.ShapeFieldName,"",featureDataset,null,
                               pAnnoLayerProptyCollection, pGraphSacle, pSymbolCollection,true);
                        }
                    }
                    else
                    {
                        ///创建非空间数据
                    }
                    return featureClass;
                }
                return null;
            }
            catch(Exception ex)
            {
                Logger.WriteErrorLog(ex);
                return null;
            }
        }
Beispiel #28
0
        public void MakeScratchPoints()
        {
            try
            {
                IMxDocument pmxdoc = ArcMap.Document as IMxDocument;
                IMap        pmap   = pmxdoc.FocusMap;

                ILayer pShorePoints = FindLayer(pmap, "ShorePoints");

                if (pShorePoints != null)
                {
                    pmap.DeleteLayer(pShorePoints);
                }


                IScratchWorkspaceFactory  workspaceFactory  = new FileGDBScratchWorkspaceFactoryClass();
                IScratchWorkspaceFactory2 workspaceFactory2 = workspaceFactory as IScratchWorkspaceFactory2;
                IWorkspace scratchWorkspace = workspaceFactory2.CreateNewScratchWorkspace();

                IFeatureWorkspace pFeatWorkspace = scratchWorkspace as IFeatureWorkspace;


                // This function creates a new feature class in a supplied feature dataset by building all of the
                // fields from scratch. IFeatureClassDescription (or IObjectClassDescription if the table is
                // created at the workspace level) can be used to get the required fields and are used to
                // get the InstanceClassID and ExtensionClassID.
                // Create new fields collection with the number of fields you plan to add. Must add at least two fields
                // for a feature class: Object ID and Shape field.
                IFields     fields     = new FieldsClass();
                IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
                fieldsEdit.FieldCount_2 = 3;

                // Create Object ID field.
                IField fieldUserDefined = new Field();

                IFieldEdit fieldEdit = (IFieldEdit)fieldUserDefined;
                fieldEdit.Name_2      = "OBJECTID";
                fieldEdit.AliasName_2 = "OBJECT ID";
                fieldEdit.Type_2      = esriFieldType.esriFieldTypeOID;
                fieldsEdit.set_Field(0, fieldUserDefined);

                // Create Shape field.
                fieldUserDefined = new Field();
                fieldEdit        = (IFieldEdit)fieldUserDefined;

                // Set up geometry definition for the Shape field.
                // You do not have to set the spatial reference, as it is inherited from the feature dataset.
                IGeometryDef     geometryDef     = new GeometryDefClass();
                IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
                geometryDefEdit.GeometryType_2     = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint;
                geometryDefEdit.SpatialReference_2 = pmap.SpatialReference;
                // By setting the grid size to 0, you are allowing ArcGIS to determine the appropriate grid sizes for the feature class.
                // If in a personal geodatabase, the grid size is 1,000. If in a file or ArcSDE geodatabase, the grid size
                // is based on the initial loading or inserting of features.
                geometryDefEdit.GridCount_2 = 1;
                geometryDefEdit.set_GridSize(0, 0);
                geometryDefEdit.HasM_2 = false;
                geometryDefEdit.HasZ_2 = false;

                // Set standard field properties.
                fieldEdit.Name_2        = "SHAPE";
                fieldEdit.Type_2        = esriFieldType.esriFieldTypeGeometry;
                fieldEdit.GeometryDef_2 = geometryDef;
                fieldEdit.IsNullable_2  = true;
                fieldEdit.Required_2    = true;
                fieldsEdit.set_Field(1, fieldUserDefined);

                // Create a field of type double to hold some information for the features.
                fieldUserDefined = new Field();

                fieldEdit              = (IFieldEdit)fieldUserDefined;
                fieldEdit.Name_2       = "ID";
                fieldEdit.AliasName_2  = "ID";
                fieldEdit.Editable_2   = true;
                fieldEdit.IsNullable_2 = false;
                fieldEdit.Precision_2  = 2;
                fieldEdit.Scale_2      = 5;
                fieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
                fieldsEdit.set_Field(2, fieldUserDefined);

                // Create a feature class description object to use for specifying the CLSID and EXTCLSID.
                IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
                IObjectClassDescription  ocDesc = (IObjectClassDescription)fcDesc;

                IFeatureClass pLineFClass = pFeatWorkspace.CreateFeatureClass("ShorePoints", fields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, "SHAPE", "");


                IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                pFeatureLayer.FeatureClass = pLineFClass;

                pFeatureLayer.Name = "ShorePoints";
                pmxdoc.AddLayer(pFeatureLayer);
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
        }
Beispiel #29
0
        /// <summary>
        /// Creates the feature class.
        /// </summary>
        /// <param name="featureWorkspace">The feature workspace.</param>
        /// <param name="nameOfFeatureClass">The name of feature class.</param>
        /// <param name="spatialReference">The spatial reference.</param>
        /// <returns>IFeatureClass for GPS Photos</returns>
        private IFeatureClass CreateFeatureClass(IFeatureWorkspace featureWorkspace, string nameOfFeatureClass, ISpatialReference spatialReference)
        {
            // This function creates a new stand-alone feature class in a supplied workspace by building all of the
            // fields from scratch. IFeatureClassDescription is used to get the InstanceClassID and ExtensionClassID.
            // Create new Fields collection with the number of fields you plan to add. Must add at least two fields
            // for a feature class; Object ID, and Shape field.
            IFields     fields     = new FieldsClass();
            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;

            fieldsEdit.FieldCount_2 = 10;

            // Create the Object ID field.
            IField     fieldUserDefined = new Field();
            IFieldEdit fieldEdit        = (IFieldEdit)fieldUserDefined;

            fieldEdit.Name_2      = "OBJECTID";
            fieldEdit.AliasName_2 = "OBJECT ID";
            fieldEdit.Type_2      = esriFieldType.esriFieldTypeOID;
            fieldsEdit.set_Field(0, fieldUserDefined);

            // Create the Shape field.
            fieldUserDefined = new Field();
            fieldEdit        = (IFieldEdit)fieldUserDefined;

            // Set up the geometry definition for the Shape field.
            IGeometryDef     geometryDef     = new GeometryDefClass();
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint;

            // By setting the grid size to 0, you're allowing ArcGIS to determine the appropriate grid sizes for the feature class.
            // If in a personal geodatabase, the grid size will be 1000. If in a file or ArcSDE geodatabase, the grid size
            // will be based on the initial loading or inserting of features.
            geometryDefEdit.GridCount_2 = 1;
            geometryDefEdit.set_GridSize(0, 0);
            geometryDefEdit.HasM_2 = false;
            geometryDefEdit.HasZ_2 = false;

            // Assign the spatial reference that was passed in, possibly from
            // IGeodatabase.SpatialReference for the containing feature dataset.
            if (spatialReference != null)
            {
                geometryDefEdit.SpatialReference_2 = spatialReference;
            }

            // Set standard field properties.
            fieldEdit.Name_2        = "SHAPE";
            fieldEdit.Type_2        = esriFieldType.esriFieldTypeGeometry;
            fieldEdit.GeometryDef_2 = geometryDef;
            fieldEdit.IsNullable_2  = true;
            fieldEdit.Required_2    = true;
            fieldsEdit.set_Field(1, fieldUserDefined);

            // Filename field
            fieldUserDefined       = new Field();
            fieldEdit              = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2       = "Filename";
            fieldEdit.AliasName_2  = "Filename";
            fieldEdit.Editable_2   = true;
            fieldEdit.IsNullable_2 = true;
            fieldEdit.Length_2     = 124;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.set_Field(2, fieldUserDefined);

            // DateTime Photo Taken field
            fieldUserDefined       = new Field();
            fieldEdit              = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2       = "DatePhotoTaken";
            fieldEdit.AliasName_2  = "DatePhotoTaken";
            fieldEdit.Editable_2   = true;
            fieldEdit.IsNullable_2 = true;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeDate;
            fieldsEdit.set_Field(3, fieldUserDefined);

            // Modified
            fieldUserDefined       = new Field();
            fieldEdit              = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2       = "FileLastModified";
            fieldEdit.AliasName_2  = "FileLastModified";
            fieldEdit.Editable_2   = true;
            fieldEdit.IsNullable_2 = true;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeDate;
            fieldsEdit.set_Field(4, fieldUserDefined);

            // latitude field
            fieldUserDefined       = new Field();
            fieldEdit              = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2       = "Latitude";
            fieldEdit.AliasName_2  = "Latitude";
            fieldEdit.Editable_2   = true;
            fieldEdit.IsNullable_2 = true;
            fieldEdit.Precision_2  = 10;
            fieldEdit.Scale_2      = 6;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
            fieldsEdit.set_Field(5, fieldUserDefined);

            // longitude field
            fieldUserDefined       = new Field();
            fieldEdit              = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2       = "Longitude";
            fieldEdit.AliasName_2  = "Longitude";
            fieldEdit.Editable_2   = true;
            fieldEdit.IsNullable_2 = true;
            fieldEdit.Precision_2  = 10;
            fieldEdit.Scale_2      = 6;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
            fieldsEdit.set_Field(6, fieldUserDefined);

            // Magnetic North
            fieldUserDefined       = new Field();
            fieldEdit              = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2       = "MagneticNorth";
            fieldEdit.AliasName_2  = "Magnetic North";
            fieldEdit.Editable_2   = true;
            fieldEdit.IsNullable_2 = true;
            fieldEdit.Precision_2  = 5;
            fieldEdit.Scale_2      = 2;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeSingle;
            fieldsEdit.set_Field(7, fieldUserDefined);

            // fullpath field
            fieldUserDefined       = new Field();
            fieldEdit              = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2       = "FullPath";
            fieldEdit.AliasName_2  = "FullPath";
            fieldEdit.Editable_2   = true;
            fieldEdit.IsNullable_2 = true;
            fieldEdit.Length_2     = 255;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.set_Field(8, fieldUserDefined);

            // ImageHTML
            fieldUserDefined       = new Field();
            fieldEdit              = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2       = "PhotoBLOB";
            fieldEdit.AliasName_2  = "PhotoBLOB";
            fieldEdit.Editable_2   = true;
            fieldEdit.IsNullable_2 = true;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeBlob;
            fieldsEdit.set_Field(9, fieldUserDefined);

            IFeatureClassDescription featureclassDesc = new FeatureClassDescriptionClass();
            IObjectClassDescription  objectclassDesc  = (IObjectClassDescription)featureclassDesc;

            return(featureWorkspace.CreateFeatureClass(
                       nameOfFeatureClass,
                       fields,
                       objectclassDesc.InstanceCLSID,
                       objectclassDesc.ClassExtensionCLSID,
                       esriFeatureType.esriFTSimple,
                       featureclassDesc.ShapeFieldName,
                       string.Empty));
        }
        private void CreateSettingsTable(IFeatureWorkspace fwspc)
        {
            if (MessageBox.Show(String.Format("There is no settings table in this workspace.{0}Would you like to create one?", Environment.NewLine), "Settings Table", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                try
                {
                    IFields     flds     = new FieldsClass();
                    IFieldsEdit fldsEdit = (IFieldsEdit)flds;
                    fldsEdit.FieldCount_2 = 3;

                    IField     oidfld     = new FieldClass();
                    IFieldEdit oidfldEdit = (IFieldEdit)oidfld;
                    oidfldEdit.Name_2      = "OBJECTID";
                    oidfldEdit.AliasName_2 = "ObjectID";
                    oidfldEdit.Type_2      = esriFieldType.esriFieldTypeOID;

                    IField     keyfld     = new FieldClass();
                    IFieldEdit keyfldEdit = (IFieldEdit)keyfld;
                    keyfldEdit.AliasName_2 = "AKEY";
                    keyfldEdit.Name_2      = "AKEY";
                    keyfldEdit.Type_2      = esriFieldType.esriFieldTypeString;
                    keyfldEdit.Length_2    = 255;

                    IField     valuefld     = new FieldClass();
                    IFieldEdit valuefldEdit = (IFieldEdit)valuefld;
                    valuefldEdit.AliasName_2 = "AVALUE";
                    valuefldEdit.Name_2      = "AVALUE";
                    valuefldEdit.Type_2      = esriFieldType.esriFieldTypeString;
                    valuefldEdit.Length_2    = 255;

                    fldsEdit.set_Field(0, oidfld);
                    fldsEdit.set_Field(1, keyfld);
                    fldsEdit.set_Field(2, valuefld);

                    ESRI.ArcGIS.esriSystem.UID AddressingSettingsUID = new ESRI.ArcGIS.esriSystem.UID();
                    AddressingSettingsUID.Value = AddressingSettingsGUID;

                    ESRI.ArcGIS.esriSystem.UID extclsid = new ESRI.ArcGIS.esriSystem.UID();
                    extclsid.Value = "esriGeoDatabase.Object";

                    IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
                    IObjectClassDescription  ocDesc = (IObjectClassDescription)fcDesc;

                    SettingsTable = fwspc.CreateTable("AddressingSettings", flds, AddressingSettingsUID, null, null);
                }
                catch (Exception ex)
                {
                    throw (ex);
                }



                Globals.SettingsTable = SettingsTable;

                ICursor cursor = SettingsTable.Search(null, false);
                try
                {
                    IRow row = cursor.NextRow();
                    System.Collections.Generic.Dictionary <string, string> settings = new System.Collections.Generic.Dictionary <string, string>();
                    while (row != null)
                    {
                        settings[row.get_Value(1).ToString()] = row.get_Value(2).ToString();
                        row = cursor.NextRow();
                    }

                    Globals.Settings = settings;
                }
                catch
                {
                    cursor = null;
                }
            }
            else
            {
                UseExtension = false;
            }
        }