/// <summary> /// 把DataTable转为ITable ,tempPath 不含文件名的w文件夹路径 /// </summary> /// <param name="mTable"></param> /// <returns></returns> private ITable DataTableToITable(DataTable mTable, string xFieldName, string yFieldName, string tempPath) { try { #region 新建表字段 IField pField = null; IFields fields = new FieldsClass(); IFieldsEdit fieldsEdit = (IFieldsEdit)fields; fieldsEdit.FieldCount_2 = 2; //添加X字段 pField = new FieldClass(); IFieldEdit fieldEdit = (IFieldEdit)pField; fieldEdit.Name_2 = "X"; fieldEdit.AliasName_2 = "X"; //设置字段类型 fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; fieldEdit.Editable_2 = true; fieldsEdit.set_Field(0, pField); //添加Y字段 IField pField1 = new FieldClass(); IFieldEdit fieldEdit1 = (IFieldEdit)pField1; fieldEdit1.Name_2 = "Y"; fieldEdit1.AliasName_2 = "Y"; fieldEdit1.Type_2 = esriFieldType.esriFieldTypeDouble; fieldEdit1.Editable_2 = true; fieldsEdit.set_Field(1, pField1); #endregion ShapefileWorkspaceFactoryClass class2 = new ShapefileWorkspaceFactoryClass(); ESRI.ArcGIS.Geodatabase.IWorkspace pWorkspace = class2.OpenFromFile(tempPath, 0); IFeatureWorkspace pFWS = pWorkspace as IFeatureWorkspace; //删除已有的 if (System.IO.File.Exists(tempPath + "点数据.dbf")) { System.IO.File.Delete(tempPath + "点数据.dbf"); } //创建空表 ITable pTable = pFWS.CreateTable("点数据", fieldsEdit, null, null, ""); //遍历DataTable中数据,然后转换为ITable中的数据 int xRowIndex = pTable.Fields.FindField("X"); int yRowIndex = pTable.Fields.FindField("Y"); for (int k = 0; k < mTable.Rows.Count; k++) { //ITable 的记录 IRow row = pTable.CreateRow(); DataRow pRrow = mTable.Rows[k]; row.set_Value(xRowIndex, pRrow[xFieldName]); row.set_Value(yRowIndex, pRrow[yFieldName]); row.Store(); } return(pTable); } catch { return(null); } }
public static void Execute(IFeatureClass featureClass, String indexName, String nameOfField) { // Ensure the feature class contains the specified field. int fieldIndex = featureClass.FindField(nameOfField); if (fieldIndex == -1) { throw new ArgumentException("The specified field does not exist in the feature class."); } // Get the specified field from the feature class. IFields featureClassFields = featureClass.Fields; IField field = featureClassFields.get_Field(fieldIndex); // Create a fields collection and add the specified field to it. IFields fields = new FieldsClass(); IFieldsEdit fieldsEdit = (IFieldsEdit)fields; fieldsEdit.FieldCount_2 = 1; fieldsEdit.set_Field(0, field); // Create an index and cast to the IIndexEdit interface. IIndex index = new IndexClass(); IIndexEdit indexEdit = (IIndexEdit)index; // Set the index's properties, including the associated fields. indexEdit.Fields_2 = fields; indexEdit.IsAscending_2 = false; indexEdit.IsUnique_2 = false; indexEdit.Name_2 = indexName; // Add the index to the feature class. featureClass.AddIndex(index); }
public IFields createReferencePointFields(string ReferenceFieldName, string OriginalLineIDFieldName, ISpatialReference pSpatRef) { //Create field object and set number of fields IFields pFields = new FieldsClass(); IFieldsEdit pFieldsEdit = pFields as IFieldsEdit; pFieldsEdit.FieldCount_2 = 4; //Create objectID field IField pField = new FieldClass(); IFieldEdit pFieldEdit = pField as IFieldEdit; pFieldEdit.Name_2 = "OBJECTID"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; pFieldsEdit.set_Field(0, pField); //Create Shape field pField = new FieldClass(); pFieldEdit = pField as IFieldEdit; pFieldEdit.Name_2 = "SHAPE"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; IGeometryDef pGeomDef = new GeometryDefClass(); IGeometryDefEdit pGeomDefEdit = pGeomDef as IGeometryDefEdit; pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint; pGeomDefEdit.SpatialReference_2 = pSpatRef; pGeomDefEdit.HasZ_2 = true; pFieldEdit.GeometryDef_2 = pGeomDef; pFieldsEdit.set_Field(1, pField); //Create reference id field pField = new FieldClass(); pFieldEdit = pField as IFieldEdit; pFieldEdit.Name_2 = ReferenceFieldName; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; pFieldsEdit.set_Field(2, pField); //Create reference id field pField = new FieldClass(); pFieldEdit = pField as IFieldEdit; pFieldEdit.Name_2 = OriginalLineIDFieldName; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; pFieldsEdit.set_Field(3, pField); return(pFields); }
private IFields CreateChainFields() { IFields flds = new FieldsClass(); IFieldsEdit eflds = flds as IFieldsEdit; eflds.FieldCount_2 = 7; IField oid_field = new FieldClass(); IFieldEdit eOid = (IFieldEdit)oid_field; eOid.Name_2 = "ObjectID"; eOid.AliasName_2 = "ObjectID"; eOid.Type_2 = esriFieldType.esriFieldTypeOID; eflds.set_Field(0, oid_field); //Create A geometry Definition for the layer IGeometryDef geomDef = new GeometryDefClass(); IGeometryDefEdit egeomDef = (IGeometryDefEdit)geomDef; egeomDef.GeometryType_2 = esriGeometryType.esriGeometryPolyline; egeomDef.SpatialReference_2 = ArcMap.Document.FocusMap.SpatialReference; IField shap = new FieldClass(); IFieldEdit eshape = (IFieldEdit)shap; eshape.Type_2 = esriFieldType.esriFieldTypeGeometry; eshape.Name_2 = "Shape"; eshape.AliasName_2 = "Shape"; eshape.GeometryDef_2 = geomDef; eflds.set_Field(1, shap); IField FromLeft = CreateIntegerField("FromLeft"); eflds.set_Field(2, FromLeft); IField ToLeft = CreateIntegerField("ToLeft"); eflds.set_Field(3, ToLeft); IField FromRight = CreateIntegerField("FromRight"); eflds.set_Field(4, FromRight); IField ToRight = CreateIntegerField("ToRight"); eflds.set_Field(5, ToRight); IField CLID = CreateIntegerField("CLID"); eflds.set_Field(6, CLID); return(flds); }
private IFields CreateErrorTableFields() { IFields flds = new FieldsClass(); IFieldsEdit eflds = flds as IFieldsEdit; eflds.FieldCount_2 = 3; IField oid_field = new FieldClass(); IFieldEdit eOid = (IFieldEdit)oid_field; eOid.Name_2 = "ObjectID"; eOid.AliasName_2 = "ObjectID"; eOid.Type_2 = esriFieldType.esriFieldTypeOID; eflds.set_Field(0, oid_field); IField fkey = new FieldClass(); IFieldEdit efkey = (IFieldEdit)fkey; efkey.Name_2 = "FKEY"; efkey.Type_2 = esriFieldType.esriFieldTypeInteger; efkey.AliasName_2 = "FKEY"; eflds.set_Field(1, fkey); IField flderror = new FieldClass(); IFieldEdit eflder = (IFieldEdit)flderror; eflder.AliasName_2 = "Error"; eflder.Name_2 = "Error"; eflder.Type_2 = esriFieldType.esriFieldTypeString; eflder.Length_2 = 255; eflds.set_Field(2, flderror); return(flds); }
public void MergeOnto(IFields ffs) { IFieldsEdit fe = ffs as IFieldsEdit; List <AoField> to_append = new List <AoField>(); foreach (AoField f in m_fields) { int idx = fe.FindField(f.Name); if (idx == -1) // already there. { to_append.Add(f); } else // new { fe.set_Field(idx, f.Field); } } foreach (AoField f in to_append) { fe.AddField(f.Field); } }
/// <summary> /// /// </summary> /// <param name="featureDataset"></param> /// <param name="strNameOfFeatureClass"></param> /// <returns></returns> public static IFeatureClass CreateCurveFeatureClass(IFeatureDataset featureDataset, String strNameOfFeatureClass) { // 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 = 10; // Create Object ID field. IField fieldUserDefined = new Field(); IFieldEdit fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "OBJECTID"; fieldEdit.AliasName_2 = "OBJECTID"; 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.esriGeometryPolyline; // 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 FromLayer fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "FROMLAYER"; fieldEdit.AliasName_2 = "The layer where these curves were identified from"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(2, fieldUserDefined); // Create StreetID Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "STREETID"; fieldEdit.AliasName_2 = "Polyline ID of the street where the curve is located"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.set_Field(3, fieldUserDefined); // Create StreetName Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "STREETNAME"; fieldEdit.AliasName_2 = "Name of the street where the curve is located"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(4, fieldUserDefined); // Create StreetDirc Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "STREETDIRC"; fieldEdit.AliasName_2 = "Direction of the street"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(5, fieldUserDefined); // Create CurveIndex Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "CURVEINDEX"; fieldEdit.AliasName_2 = "Index of the curve within the street"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.set_Field(6, fieldUserDefined); // Create Length fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "LENGTH"; fieldEdit.AliasName_2 = "Length of the curve"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 2; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; fieldsEdit.set_Field(7, fieldUserDefined); // Create Radius Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "RADIUS"; fieldEdit.AliasName_2 = "Radius of the curve"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 2; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; fieldsEdit.set_Field(8, fieldUserDefined); // Create Angle Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "ANGLE"; fieldEdit.AliasName_2 = "Central Angle of the curve"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 3; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; fieldsEdit.set_Field(9, fieldUserDefined); // 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, fields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, "SHAPE", "")); }
//创建要素类 private bool CreateFeatureLayer(string FName) { try { IFields fields = new FieldsClass(); IFieldsEdit fieldsEdit = (IFieldsEdit)fields; fieldsEdit.FieldCount_2 = 2; IField fieldUserDefined = new Field(); IFieldEdit fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "FID"; fieldEdit.AliasName_2 = "OBJECT ID"; fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; fieldsEdit.set_Field(0, fieldUserDefined); fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; IGeometryDef geometryDef = new GeometryDefClass(); IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef; geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon; geometryDefEdit.GridCount_2 = 1; geometryDefEdit.set_GridSize(0, 0); geometryDefEdit.HasM_2 = false; geometryDefEdit.HasZ_2 = false; if (spatialReference != null) { geometryDefEdit.SpatialReference_2 = spatialReference; } 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); UID CLSID = new UIDClass { Value = "esriGeoDatabase.Feature" }; Thread.Sleep(1000); string tmpLyrName = DateTime.Now.ToString("yyyyMMddHHmmss"); IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(tmpLyrName, fields, CLSID, null, esriFeatureType.esriFTSimple, fields.get_Field(1).Name, ""); ROIFileNames.Add(tmpLyrName); IFeatureLayer featureLayer = new FeatureLayerClass(); featureLayer.FeatureClass = featureClass; featureLayer.Name = FName; featureLayer.Visible = true; ILayerEffects layerEffects = featureLayer as ILayerEffects; layerEffects.Transparency = 55; m_mapControl.ActiveView.FocusMap.AddLayer(featureLayer); m_mapControl.ActiveView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeography, null, null); return(true); } catch (Exception err) { MessageBox.Show(err.ToString()); return(false); } }
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); } }
private IFeatureClass MakePointFC() { string strFCName; try { IGxCatalogDefaultDatabase Defaultgdb = ArcMap.Application as IGxCatalogDefaultDatabase; Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory"); IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); IWorkspace pWorkspace = workspaceFactory.OpenFromFile(Defaultgdb.DefaultDatabaseName.PathName, 0); IFeatureWorkspace workspace = pWorkspace as IFeatureWorkspace; UID CLSID = new UID(); CLSID.Value = "esriGeodatabase.Feature"; IFields pFields = new FieldsClass(); IFieldsEdit pFieldsEdit = pFields as IFieldsEdit; pFieldsEdit.FieldCount_2 = 6; IGeoDataset geoDataset = ArcMap.Document.ActiveView.FocusMap.get_Layer(0) as IGeoDataset; IGeometryDef pGeomDef = new GeometryDef(); IGeometryDefEdit pGeomDefEdit = pGeomDef as IGeometryDefEdit; pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint; pGeomDefEdit.SpatialReference_2 = geoDataset.SpatialReference; IField pField; IFieldEdit pFieldEdit; //pField = new FieldClass(); //pFieldEdit = pField as IFieldEdit; //pFieldEdit.AliasName_2 = "ObjectID"; //pFieldEdit.Name_2 = "ObjectID"; //pFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; //pFieldsEdit.set_Field(0, pFieldEdit); pField = new FieldClass(); pFieldEdit = pField as IFieldEdit; pFieldEdit.AliasName_2 = "SHAPE"; pFieldEdit.Name_2 = "SHAPE"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; pFieldEdit.GeometryDef_2 = pGeomDef; pFieldsEdit.set_Field(0, pFieldEdit); pField = new FieldClass(); pFieldEdit = pField as IFieldEdit; pFieldEdit.AliasName_2 = "LineOID"; pFieldEdit.Name_2 = "LineOID"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; pFieldsEdit.set_Field(1, pFieldEdit); pField = new FieldClass(); pFieldEdit = pField as IFieldEdit; pFieldEdit.AliasName_2 = "Distance"; pFieldEdit.Name_2 = "Distance"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; pFieldsEdit.set_Field(2, pFieldEdit); pField = new FieldClass(); pFieldEdit = pField as IFieldEdit; pFieldEdit.AliasName_2 = "Elevation"; pFieldEdit.Name_2 = "Elevation"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; pFieldsEdit.set_Field(3, pFieldEdit); pField = new FieldClass(); pFieldEdit = pField as IFieldEdit; pFieldEdit.AliasName_2 = "X"; pFieldEdit.Name_2 = "X"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; pFieldsEdit.set_Field(4, pFieldEdit); pField = new FieldClass(); pFieldEdit = pField as IFieldEdit; pFieldEdit.AliasName_2 = "Y"; pFieldEdit.Name_2 = "Y"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; pFieldsEdit.set_Field(5, pFieldEdit); strFCName = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetRandomFileName()); char[] chars = strFCName.ToCharArray(); if (Char.IsDigit(chars[0])) { strFCName = strFCName.Remove(0, 1); } KillExistingFeatureclass(strFCName); IFeatureClass pFeatureClass = workspace.CreateFeatureClass(strFCName, pFieldsEdit, CLSID, null, esriFeatureType.esriFTSimple, "SHAPE", ""); return(pFeatureClass); } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); return(null); } }
/// <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; } }
private IFeatureClass MakeInMemoryFeatureClass(FusionTable ft, esriGeometryType geomType) { try { ISpatialReferenceFactory pSpatialRefFactory = new SpatialReferenceEnvironmentClass(); IGeographicCoordinateSystem pGeographicCoordSys = pSpatialRefFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984); ISpatialReference pSpaRef = pGeographicCoordSys; pSpaRef.SetDomain(-180, 180, -90, 90); // Create an in-memory workspace factory. Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.InMemoryWorkspaceFactory"); IWorkspaceFactory workspaceFactory = Activator.CreateInstance(factoryType) as IWorkspaceFactory; // Create an in-memory workspace. IWorkspaceName workspaceName = workspaceFactory.Create("", "FusionTable", null, 0); // Cast for IName and open a reference to the in-memory workspace through the name object. IName name = workspaceName as IName; IWorkspace pWorkspace = name.Open() as IWorkspace; IFeatureWorkspace workspace = pWorkspace as IFeatureWorkspace; UID CLSID = new UID(); CLSID.Value = "esriGeodatabase.Feature"; IFields pFields = new FieldsClass(); IFieldsEdit pFieldsEdit = pFields as IFieldsEdit; pFieldsEdit.FieldCount_2 = ft.columns.Count + 1; IGeometryDef pGeomDef = new GeometryDef(); IGeometryDefEdit pGeomDefEdit = pGeomDef as IGeometryDefEdit; pGeomDefEdit.GeometryType_2 = geomType; pGeomDefEdit.SpatialReference_2 = pSpaRef; IField pField; IFieldEdit pFieldEdit; pField = new FieldClass(); pFieldEdit = pField as IFieldEdit; pFieldEdit.AliasName_2 = "SHAPE"; pFieldEdit.Name_2 = "SHAPE"; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; pFieldEdit.GeometryDef_2 = pGeomDef; pFieldsEdit.set_Field(0, pFieldEdit); int k = 1; int i = 0; foreach (string col in ft.columns) { pField = new FieldClass(); pFieldEdit = pField as IFieldEdit; pFieldEdit.AliasName_2 = ft.columns[i]; pFieldEdit.Name_2 = ft.columns[i]; pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; pFieldsEdit.set_Field(k, pFieldEdit); k++; i++; } string strFCName = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetRandomFileName()); char[] chars = strFCName.ToCharArray(); if (Char.IsDigit(chars[0])) { strFCName = strFCName.Remove(0, 1); } IFeatureClass pFeatureClass = workspace.CreateFeatureClass(strFCName, pFieldsEdit, CLSID, null, esriFeatureType.esriFTSimple, "SHAPE", ""); return(pFeatureClass); } catch (Exception ex) { MessageBox.Show(ex.Message); MessageBox.Show(ex.StackTrace); return(null); } }
public IFeatureClass CreateFeatureClass(string featureClassName, esriGeometryType geometryType, ISpatialReference spatialReference) { IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(System.IO.Path.GetTempPath(), 0); IFields fields = new FieldsClass(); IFieldsEdit fieldsEdit = (IFieldsEdit)fields; fieldsEdit.FieldCount_2 = 2; //Create the Object ID field. IField fieldUserDefined = new Field(); IFieldEdit fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "FID"; 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; switch (geometryType) { case esriGeometryType.esriGeometryPoint: geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint; break; case esriGeometryType.esriGeometryPolyline: geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline; break; case esriGeometryType.esriGeometryPolygon: geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon; break; default: break; } geometryDefEdit.GridCount_2 = 1; geometryDefEdit.set_GridSize(0, 0); geometryDefEdit.HasM_2 = false; geometryDefEdit.HasZ_2 = false; 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); UID CLSID = new UIDClass(); CLSID.Value = "esriGeoDatabase.Feature"; return(featureWorkspace.CreateFeatureClass(featureClassName, fields, CLSID, null, esriFeatureType.esriFTSimple, fields.get_Field(1).Name, "")); }
private static IFields GetCurveAreaFields(bool isShape, bool isDissolved) { IFields fields = new FieldsClass(); IFieldsEdit fieldsEdit = (IFieldsEdit)fields; if (isDissolved) { fieldsEdit.FieldCount_2 = 13; } else { fieldsEdit.FieldCount_2 = 20; } // Create Object ID field. IField fieldUserDefined = new Field(); IFieldEdit fieldEdit = (IFieldEdit)fieldUserDefined; if (isShape) { fieldEdit.Name_2 = "FID"; fieldEdit.AliasName_2 = "FID"; } else { fieldEdit.Name_2 = "OBJECTID"; fieldEdit.AliasName_2 = "OBJECTID"; } 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.esriGeometryPolyline; // 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); if (isDissolved) { // Create Route_Name Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "ROUTE_NAME"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(2, fieldUserDefined); // Create Route_DIRE Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "ROUTE_DIRE"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(3, fieldUserDefined); // Create FULL_NAME Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "FULL_NAME"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(4, fieldUserDefined); // Create CURVE_ID fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "CURV_ID"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.set_Field(5, fieldUserDefined); // Create CURV_TYPE Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "CURV_TYPE"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(6, fieldUserDefined); // Create CURV_DIRE Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "CURV_DIRE"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(7, fieldUserDefined); // Create CURV_LENG fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "CURV_LENG"; //fieldEdit.AliasName_2 = "Length of the curve area"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 2; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; fieldsEdit.set_Field(8, fieldUserDefined); // Create Radius Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "RADIUS"; //fieldEdit.AliasName_2 = "Radius of the curve area"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 2; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; fieldsEdit.set_Field(9, fieldUserDefined); // Create DEGREE Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "DEGREE"; //fieldEdit.AliasName_2 = "Central Angle of the curve area"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 3; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; fieldsEdit.set_Field(10, fieldUserDefined); // Create Transition Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "HAS_TRANS"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(11, fieldUserDefined); // Create INTSC_ANGLE Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "INTSC_ANGLE"; //fieldEdit.AliasName_2 = "Central Angle of the curve area"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 3; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; fieldsEdit.set_Field(12, fieldUserDefined); } else { // Create taslinkid fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "TASLINKID"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.set_Field(2, fieldUserDefined); // Create trnlinkid fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "TRNLINKID"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.set_Field(3, fieldUserDefined); // Create trnnode_f fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "TRNNODE_F"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.set_Field(4, fieldUserDefined); // Create trnnode_t fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "TRNNODE_T"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.set_Field(5, fieldUserDefined); // Create rtesys fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "RTESYS"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.set_Field(6, fieldUserDefined); // Create Route_Name Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "ROUTE_NAME"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(7, fieldUserDefined); // Create Route_DIRE Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "ROUTE_DIRE"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(8, fieldUserDefined); // Create FULL_NAME Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "FULL_NAME"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(9, fieldUserDefined); // Create OFFICIAL_N Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "OFFICIAL_N"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(10, fieldUserDefined); // Create VERS_DATE fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "VERS_DATE"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.set_Field(11, fieldUserDefined); // Create CURVE_ID fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "CURV_ID"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.set_Field(12, fieldUserDefined); // Create CURV_TYPE Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "CURV_TYPE"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(13, fieldUserDefined); // Create CURV_DIRE Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "CURV_DIRE"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(14, fieldUserDefined); // Create CURV_LENG fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "CURV_LENG"; //fieldEdit.AliasName_2 = "Length of the curve area"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 2; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; fieldsEdit.set_Field(15, fieldUserDefined); // Create Radius Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "RADIUS"; //fieldEdit.AliasName_2 = "Radius of the curve area"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 2; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; fieldsEdit.set_Field(16, fieldUserDefined); // Create DEGREE Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "DEGREE"; //fieldEdit.AliasName_2 = "Central Angle of the curve area"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 3; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; fieldsEdit.set_Field(17, fieldUserDefined); // Create Transition Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "HAS_TRANS"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 0; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(18, fieldUserDefined); // Create INTSC_ANGLE Field fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "INTSC_ANGLE"; //fieldEdit.AliasName_2 = "Central Angle of the curve area"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Precision_2 = 3; fieldEdit.Scale_2 = 5; fieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble; fieldsEdit.set_Field(19, fieldUserDefined); } return(fields); }
public static void IFieldsEdit_set_Field_2(IFieldsEdit ife, int Index, IField A_2) { // This is not directly accessible from VB.NET in VS2015 so we implement in C# ife.set_Field(Index, A_2); }
/// <summary> /// 初始化数据 /// </summary> public void InitData(object progress1) { ProgressBar progress = (ProgressBar)progress1; //耗时巨大的代码 // MainForm.baseData.InitData(progressBar1); ////////////////////////////////////////////////////////////////////////// //建立分区索引 IEnumIndex pEnumIndex = zoneLCA_FC.Indexes.FindIndexesByFieldName(zidField); IIndex pTemIndex = pEnumIndex.Next(); if (pTemIndex == null) { IIndex pIndex = new IndexClass(); IIndexEdit pIndexEdit = pIndex as IIndexEdit; IFields pFields = new FieldsClass(); IFieldsEdit pFieldsEdit = pFields as IFieldsEdit; int zidindex = zoneLCA_FC.Fields.FindField(zidField); IField pField = zoneLCA_FC.Fields.Field[zidindex]; pFieldsEdit.FieldCount_2 = 1; pFieldsEdit.set_Field(0, pField); pIndexEdit.Fields_2 = pFields; pIndexEdit.Name_2 = zidField; pIndexEdit.IsAscending_2 = true; zoneLCA_FC.AddIndex(pIndex); } //建立分类索引 IEnumIndex pEnumIndex1 = zoneLCA_FC.Indexes.FindIndexesByFieldName(codeField); IIndex pTemIndex1 = pEnumIndex1.Next(); if (pTemIndex == null) { IIndex pIndex = new IndexClass(); IIndexEdit pIndexEdit = pIndex as IIndexEdit; IFields pFields = new FieldsClass(); IFieldsEdit pFieldsEdit = pFields as IFieldsEdit; int codeindex = zoneLCA_FC.Fields.FindField(codeField); IField pField = zoneLCA_FC.Fields.Field[codeindex]; pFieldsEdit.FieldCount_2 = 1; pFieldsEdit.set_Field(0, pField); pIndexEdit.Fields_2 = pFields; pIndexEdit.Name_2 = codeField; pIndexEdit.IsAscending_2 = true; zoneLCA_FC.AddIndex(pIndex); } areaIndex = zoneLCA_FC.FindField("Shape_Area"); perimeterIndex = zoneLCA_FC.FindField("Shape_Length"); if (zone_FC != null) { areaIndex_zone = zone_FC.FindField("Shape_Area"); perimeterIndex_zone = zone_FC.FindField("Shape_Length"); } codeIndex = zoneLCA_FC.FindField(codeField); Utilities.Common.SetProgress(progress); IQueryDef pQueryDef; IRow pRow; ICursor pCursor; IWorkspace pWorkspace; IFeatureWorkspace pFeatureWorkspace; IDataset pDataset; pDataset = zoneLCA_FC as IDataset; pWorkspace = pDataset.Workspace; pFeatureWorkspace = pDataset.Workspace as IFeatureWorkspace; pQueryDef = pFeatureWorkspace.CreateQueryDef(); ////////////////////////////////////////////////////////////////////////// //添加分区唯一值 pQueryDef.SubFields = "DISTINCT(" + zidField + ")"; pQueryDef.Tables = pDataset.Name; pCursor = pQueryDef.Evaluate(); pRow = pCursor.NextRow(); while (pRow != null) { object obj = pRow.get_Value(0); zoneValue.Add(obj.ToString()); pRow = pCursor.NextRow(); if (progress.Value < progress.Maximum) { progress.Value++; } } ////////////////////////////////////////////////////////////////////////// //添加 分类唯一值 pQueryDef.SubFields = "DISTINCT(" + codeField + ")"; pQueryDef.Tables = pDataset.Name; pCursor = pQueryDef.Evaluate(); pRow = pCursor.NextRow(); while (pRow != null) { object obj = pRow.get_Value(0); ccValue.Add(obj.ToString()); pRow = pCursor.NextRow(); if (progress.Value < progress.Maximum) { progress.Value++; } } if (zone_FC != null) { string objectFiled = ""; objectFiled = zone_FC.Fields.Field[0].Name; pQueryDef.SubFields = (zone_FC as IDataset).Name + "." + objectFiled; //pQueryDef.SubFields = pDataset.Name + "." + zidField + "," + (zone_FC as IDataset).Name + "." + zidField + "," + (zone_FC as IDataset).Name + ".OBJECTID"; pQueryDef.Tables = (zone_FC as IDataset).Name; for (int i = 0; i < zoneValue.Count; i++) { pQueryDef.WhereClause = zidField + " = " + "'" + zoneValue[i] + "'"; pCursor = pQueryDef.Evaluate(); pRow = pCursor.NextRow(); while (pRow != null) { object obj1 = pRow.get_Value(0); // zoneValue.Add(obj.ToString()); zoneObjectID.Add((int)obj1); pRow = pCursor.NextRow(); if (progress.Value < progress.Maximum) { progress.Value++; } } } } string objectFiled1 = ""; objectFiled1 = zoneLCA_FC.Fields.Field[0].Name; ///////////////////////// //1 pQueryDef.SubFields = objectFiled1 + ",Shape_Area"; pQueryDef.Tables = pDataset.Name; for (int i = 0; i < zoneValue.Count; i++) { double area = 0.0; pQueryDef.WhereClause = zidField + "=\'" + zoneValue[i] + "\'"; pCursor = pQueryDef.Evaluate(); pRow = pCursor.NextRow(); List <int> pids = new List <int>(); while (pRow != null) { area += (double)pRow.get_Value(1); pids.Add((int)pRow.get_Value(0)); pRow = pCursor.NextRow(); // progress.Invoke((MethodInvoker)delegate() // { // if (progress.Value < progress.Maximum) // { // progress.Value++; // } // }); if (progress.Value < progress.Maximum) { progress.Value++; } } zoneArea.Add(area); patchIDs.Add(pids); } for (int i = 0; i < patchIDs.Count; i++) { patchIDArray.Add(GetZonePids(i)); // progress.Invoke((MethodInvoker)delegate() // { // if (progress.Value < progress.Maximum) // { // progress.Value++; // } // }); if (progress.Value < progress.Maximum) { progress.Value++; } } }
public IFeatureClass CreateFeatureClass(string geometryType, ISpatialReference spatialReference) { //IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass(); //string gdbName = "FGISTemp" + ".gdb"; //string gdbFullPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), gdbName); //IWorkspace workspace; //IFeatureWorkspace featureWorkspace; //if (System.IO.Directory.Exists(gdbFullPath)) //{ // featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(gdbFullPath, 0); //} //else //{ // IWorkspaceName workspaceName = workspaceFactory.Create(System.IO.Path.GetTempPath(), gdbName, null, 0); // IName name = (ESRI.ArcGIS.esriSystem.IName)workspaceName; // workspace = (IWorkspace)name.Open(); // featureWorkspace = workspace as IFeatureWorkspace; //} IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(System.IO.Path.GetTempPath(), 0); IFields fields = new FieldsClass(); IFieldsEdit fieldsEdit = (IFieldsEdit)fields; fieldsEdit.FieldCount_2 = 2; //Create the Object ID field. IField fieldUserDefined = new Field(); IFieldEdit fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "FID"; 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; switch (geometryType) { case "点": geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint; break; case "线": geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline; break; case "多边形": case "矩形": case "圆": geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon; break; default: break; } // 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); UID CLSID = new UIDClass(); CLSID.Value = "esriGeoDatabase.Feature"; return(featureWorkspace.CreateFeatureClass(tempFeatureLayerName, fields, CLSID, null, esriFeatureType.esriFTSimple, fields.get_Field(1).Name, "")); }
private static IFields GetCurveAreaFields(bool isShape, bool isDissolved, ESRI.ArcGIS.Geometry.ISpatialReference georef = null) { IFields fields = new FieldsClass(); IFieldsEdit fieldsEdit = (IFieldsEdit)fields; List <IField> fieldList = ClassLib.Fields.getFields(isDissolved); fieldsEdit.FieldCount_2 = fieldList.Count + 2; for (int i = 0; i < fieldList.Count; i++) { fieldsEdit.set_Field(i + 2, fieldList[i]); } // Create Object ID field. IField fieldUserDefined = new Field(); IFieldEdit fieldEdit = (IFieldEdit)fieldUserDefined; if (isShape) { fieldEdit.Name_2 = "FID"; fieldEdit.AliasName_2 = "FID"; } else { fieldEdit.Name_2 = "OBJECTID"; fieldEdit.AliasName_2 = "OBJECTID"; } 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.esriGeometryPolyline; // 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. if (!isShape) { geometryDefEdit.GridCount_2 = 1; geometryDefEdit.set_GridSize(0, 0); } geometryDefEdit.HasM_2 = false; geometryDefEdit.HasZ_2 = false; if (georef != null) { geometryDefEdit.SpatialReference_2 = georef; } // 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); return(fields); }
public static IFeatureClass createGoogleMapsEngineCatalogFeatureClass(ref log4net.ILog log, ref GoogleMapsEngineToolsExtensionForArcGIS ext) { try { // temporary directory to store workspace string workspacedirectory = ext.getLocalWorkspaceDirectory().FullName; // add the directory to the cleanup list // TODO: Replace with scratch ext.addTemporaryDirectory(new System.IO.DirectoryInfo(workspacedirectory)); // determine the workspace name for the geodatabase //string workspacefoldername = Properties.Settings.Default.extension_gdb_workspacename; // TODO: Use sctach workspace instead of creating a temporary one string workspacefoldername = "GME_Data_" + System.Guid.NewGuid().ToString().Replace("-", ""); // define a workspace to do work IWorkspace workspace = null; // attempt to open or create the workspace try { // check to see if the workspace already exists, if so, open it if (System.IO.Directory.Exists(workspacedirectory + "\\" + workspacefoldername)) { workspace = Extension.Data.GeodatabaseUtilities.openFileGeodatabaseWorkspace(ref log, workspacedirectory, workspacefoldername); ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(Properties.Resources.GeodatabaseUtilities_schema_FeatureClassName); ESRI.ArcGIS.Geodatabase.IDataset pdataset = (ESRI.ArcGIS.Geodatabase.IDataset)featureClass; if (pdataset.CanDelete()) { pdataset.Delete(); } pdataset = null; featureClass = null; featureWorkspace = null; // TODO: Open instead of delete/replace //if (arcgis.ext.gdb.GeodatabaseUtilities.deleteFileGeodatabaseWorkspace(workspacedirectory, workspacefoldername)) //workspace = arcgis.ext.gdb.GeodatabaseUtilities.createFileGeodatabaseWorkspace(workspacedirectory, workspacefoldername); } else { // workspace doesn't exist, create the workspace workspace = Extension.Data.GeodatabaseUtilities.createFileGeodatabaseWorkspace(ref log, workspacedirectory, workspacefoldername); } } catch (System.Exception ex) { // unable to create the fgdb or unable to delete the fc within the fgdb log.Error(ex); System.Windows.Forms.MessageBox.Show("Unable to create or delete an existing feature class."); } // verify the workspace is open if (workspace != null) { // create a new feature workspace to work spatially IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace; // create a spatial reference for the Google Earth Builder data (always in 4326) SpatialReferenceEnvironment sRefEnvGEB = new SpatialReferenceEnvironment(); ISpatialReference sGEBRef = sRefEnvGEB.CreateGeographicCoordinateSystem(4326); // for this feature class, create and determine the field IFields fields = new FieldsClass(); IFieldsEdit fieldsEdit = (IFieldsEdit)fields; fieldsEdit.FieldCount_2 = 10; //Create the Object ID field. IField fusrDefinedField = new Field(); IFieldEdit fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_OBJECTID_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_OBJECTID_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; fieldsEdit.set_Field(0, fusrDefinedField); //Create the CustomerId field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_CustomerId_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_CustomerId_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(1, fusrDefinedField); //Create the MapAssetId field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_MapAssetId_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_MapAssetId_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(2, fusrDefinedField); //Create the AssetId field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_AssetId_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_AssetId_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(3, fusrDefinedField); //Create the ParentAssetId field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_ParentAssetId_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_ParentAssetId_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(4, fusrDefinedField); //Create the AssetType field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_AssetType_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_AssetType_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(5, fusrDefinedField); //Create the AssetName field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_AssetName_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_AssetName_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(6, fusrDefinedField); //Create the AssetDescription field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_AssetDescription_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_AssetDescription_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(7, fusrDefinedField); //Create the MapSharedWith field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; fusrDefinedFieldEdit.Name_2 = Properties.Resources.GeodatabaseUtilities_schema_MapSharedWith_Name; fusrDefinedFieldEdit.AliasName_2 = Properties.Resources.GeodatabaseUtilities_schema_MapSharedWith_AliasName; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(8, fusrDefinedField); // Create the Shape field. fusrDefinedField = new Field(); fusrDefinedFieldEdit = (IFieldEdit)fusrDefinedField; // Set up the geometry definition for the Shape field. IGeometryDef geometryDef = new GeometryDefClass(); IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef; geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon; // 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. geometryDefEdit.SpatialReference_2 = sGEBRef; // Set standard field properties. fusrDefinedFieldEdit.Name_2 = "SHAPE"; fusrDefinedFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; fusrDefinedFieldEdit.GeometryDef_2 = geometryDef; fusrDefinedFieldEdit.IsNullable_2 = true; fusrDefinedFieldEdit.Required_2 = true; fieldsEdit.set_Field(9, fusrDefinedField); // Create a feature class description object to use for specifying the CLSID and EXTCLSID. IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass(); IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc; IFeatureClass fc = featureWorkspace.CreateFeatureClass( Properties.Resources.GeodatabaseUtilities_schema_FeatureClassName, // Feature Class Name fields, // Feature Class Fields (defined above) ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, // Shape Field Name "" // Keyword Configurations ); // return the feature class return(fc); } else { // end gracefully, maybe prompt the user that the toolbar wasn't able to create a workspcae throw new Exception("Unable to open local geodatabase."); } } catch (System.Exception ex) { // an error occured log.Error(ex); // throw an exception throw new Exception("An unknown exception occured while attempting to create a local feature class."); } }