public bool AddNewFields(myFieldEdit myField, IFieldsEdit pFields) { try { IFieldEdit pField = new FieldClass(); if (myField.name.ToLower() == "objectid") { pField.Type_2 = esriFieldType.esriFieldTypeInteger; } else { pField.Type_2 = (esriFieldType)Enum.Parse(typeof(esriFieldType), myField.type); } //esriFieldType.esriFieldTypeInteger; pField.Name_2 = myField.name; if (myField.length != 0) { pField.Length_2 = myField.length; } pFields.AddField(pField); } catch (Exception ex) { throw; } return(true); }
public bool setNameAndGeotype(string className, esriGeometryType geoType, int sr, List <myFieldEdit> jsonFields, List <myFeatures> jsonFeatures) { this.FeatureClassName = className; this.GeometryType = geoType; //(esriGeometryType)Enum.Parse(typeof(esriGeometryType),geoType); ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass(); ISpatialReference spatialReference = spatialReferenceFactory.CreateProjectedCoordinateSystem(sr); //添加字段 IGeometryDefEdit pGeomDef = new GeometryDefClass(); pGeomDef.GeometryType_2 = this.GeometryType; pGeomDef.SpatialReference_2 = spatialReference; //new UnknownCoordinateSystemClass();// this.Fields = new FieldsClass(); IFieldEdit pField = new FieldClass(); pField.Type_2 = esriFieldType.esriFieldTypeGeometry; pField.GeometryDef_2 = pGeomDef; pField.Name_2 = "Shape "; this.Fields.AddField(pField); for (int i = 0; i < jsonFields.Count; i++) { myFieldEdit myField = jsonFields[i]; AddNewFields(myField, this.Fields); } string folderName = GetFloderName(); IFeatureWorkspace pFeatureWorkspace = CreateFeatureWorkSpace(folderName); IFeatureClass pFeatureClass = CreateFeatureClass(pFeatureWorkspace, this.FeatureClassName, spatialReference, esriFeatureType.esriFTSimple, this.GeometryType, this.Fields, null, null, ""); AddFeatures(pFeatureClass, jsonFeatures, jsonFields); MessageBox.Show("添加成功"); return(true); }