// ArcGIS Snippet Title: // Create Table // // Long Description: // Creates a dataset in a workspace. // // Add the following references to the project: // ESRI.ArcGIS.Geodatabase // ESRI.ArcGIS.Geometry // ESRI.ArcGIS.System // // Intended ArcGIS Products for this snippet: // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView) // ArcGIS Engine // ArcGIS Server // // Applicable ArcGIS Product Versions: // 9.2 // 9.3 // 9.3.1 // 10.0 // // Required ArcGIS Extensions: // (NONE) // // Notes: // This snippet is intended to be inserted at the base level of a Class. // It is not intended to be nested within an existing Uitvoeren. // ///<summary>Creates a table with some default fields.</summary> /// ///<param name="workspace">An IWorkspace2 interface</param> ///<param name="tableName">A System.String of the table name in the workspace. Example: "owners"</param> ///<param name="fields">An IFields interface or Nothing</param> /// ///<returns>An ITable interface or Nothing</returns> /// ///<remarks> ///Notes: ///(1) If an IFields interface is supplied for the 'fields' collection it will be used to create the /// table. If a Nothing value is supplied for the 'fields' collection, a table will be created using /// default values in the method. ///(2) If a table with the supplied 'tableName' exists in the workspace an ITable will be returned. /// if table does not exit a new one will be created. ///</remarks> public ESRI.ArcGIS.Geodatabase.ITable CreateOrOpenTableLog(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, System.String tableName, ESRI.ArcGIS.Geodatabase.IFields fields) { // create the behavior clasid for the featureclass ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass(); if (workspace == null) { return(null); // valid feature workspace not passed in as an argument to the method } ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast ESRI.ArcGIS.Geodatabase.ITable table; if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTTable, tableName)) { // table with that name already exists return that table table = featureWorkspace.OpenTable(tableName); return(table); } uid.Value = "esriGeoDatabase.Object"; ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass(); // if a fields collection is not passed in then supply our own if (fields == null) { // create the fields using the required fields method fields = objectClassDescription.RequiredFields; ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast fieldsEdit.AddField(this.CreateFieldInt("ID")); fieldsEdit.AddField(this.CreateFieldInt("index")); fieldsEdit.AddField(this.CreateFieldDouble("X_From", 8, 2)); fieldsEdit.AddField(this.CreateFieldDouble("Y_From", 8, 2)); fieldsEdit.AddField(this.CreateFieldDouble("M_From", 8, 2)); fieldsEdit.AddField(this.CreateFieldDouble("X_To", 8, 2)); fieldsEdit.AddField(this.CreateFieldDouble("Y_To", 8, 2)); fieldsEdit.AddField(this.CreateFieldDouble("M_To", 8, 2)); // add field to field collection fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast } // Use IFieldChecker to create a validated fields collection. ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass(); ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null; ESRI.ArcGIS.Geodatabase.IFields validatedFields = null; fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace; 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 and return the table table = featureWorkspace.CreateTable(tableName, validatedFields, uid, null, ""); return(table); }
// Create 3 feature classes to hold the point, polyline, and polygon transactions private Dictionary <esriGeometryType, IFeatureClass> CreateFCS(string path) { // Connect to the output file GDB IWorkspaceFactory wsFact = new FileGDBWorkspaceFactory(); IWorkspace ws = wsFact.OpenFromFile(path, this.Handle.ToInt32()); IFeatureWorkspace featws = ws as IFeatureWorkspace; // Get the coded value domain for the transaction type, creating if necessary IDomain domain = GetOrCreateDomain(ws); Dictionary <esriGeometryType, IFeatureClass> dictionary = new Dictionary <esriGeometryType, IFeatureClass>(); foreach (var geomType in new esriGeometryType[] { esriGeometryType.esriGeometryPoint, esriGeometryType.esriGeometryPolyline, esriGeometryType.esriGeometryPolygon }) { // Create the feature classes string fcName = Enum.GetName(typeof(esriGeometryType), geomType) + "_TransactionsExportedAt" + DateTime.Now.ToString("yyyyMMdd_HHmm"); UID tableUID = new UIDClass(); tableUID.Value = "esriGeoDatabase.Feature"; // Get the fields for this geometry type IFields fields = GetFields(geomType, domain); // Validate the fields ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass(); ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null; ESRI.ArcGIS.Geodatabase.IFields validatedFields = null; fieldChecker.ValidateWorkspace = ws; fieldChecker.Validate(fields, out enumFieldError, out validatedFields); IFieldError err; while (enumFieldError != null && (err = enumFieldError.Next()) != null) { // If the field validation failed, display an error (since fields are mostly hardcoded, this shouldn't really happen) MessageBox.Show(Enum.GetName(typeof(esriFieldNameErrorType), err.FieldError), "Field Error"); } dictionary.Add(geomType, featws.CreateFeatureClass(fcName, validatedFields, tableUID, null, esriFeatureType.esriFTSimple, "SHAPE", "DEFAULT")); } return(dictionary); }
// ArcGIS Snippet Title: // Create Table // // Long Description: // Creates a dataset in a workspace. // // Add the following references to the project: // ESRI.ArcGIS.Geodatabase // ESRI.ArcGIS.Geometry // ESRI.ArcGIS.System // // Intended ArcGIS Products for this snippet: // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView) // ArcGIS Engine // ArcGIS Server // // Applicable ArcGIS Product Versions: // 9.2 // 9.3 // 9.3.1 // 10.0 // // Required ArcGIS Extensions: // (NONE) // // Notes: // This snippet is intended to be inserted at the base level of a Class. // It is not intended to be nested within an existing Uitvoeren. // ///<summary>Creates a table with some default fields.</summary> /// ///<param name="workspace">An IWorkspace2 interface</param> ///<param name="tableName">A System.String of the table name in the workspace. Example: "owners"</param> ///<param name="fields">An IFields interface or Nothing</param> /// ///<returns>An ITable interface or Nothing</returns> /// ///<remarks> ///Notes: ///(1) If an IFields interface is supplied for the 'fields' collection it will be used to create the /// table. If a Nothing value is supplied for the 'fields' collection, a table will be created using /// default values in the method. ///(2) If a table with the supplied 'tableName' exists in the workspace an ITable will be returned. /// if table does not exit a new one will be created. ///</remarks> public ESRI.ArcGIS.Geodatabase.ITable CreateOrOpenTableLog(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, System.String tableName, ESRI.ArcGIS.Geodatabase.IFields fields) { // create the behavior clasid for the featureclass ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass(); if (workspace == null) return null; // valid feature workspace not passed in as an argument to the method ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast ESRI.ArcGIS.Geodatabase.ITable table; if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTTable, tableName)) { // table with that name already exists return that table table = featureWorkspace.OpenTable(tableName); return table; } uid.Value = "esriGeoDatabase.Object"; ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass(); // if a fields collection is not passed in then supply our own if (fields == null) { // create the fields using the required fields method fields = objectClassDescription.RequiredFields; ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast fieldsEdit.AddField(this.CreateFieldInt("ID")); fieldsEdit.AddField(this.CreateFieldInt("index")); fieldsEdit.AddField(this.CreateFieldDouble("X_From", 8, 2)); fieldsEdit.AddField(this.CreateFieldDouble("Y_From", 8, 2)); fieldsEdit.AddField(this.CreateFieldDouble("M_From", 8, 2)); fieldsEdit.AddField(this.CreateFieldDouble("X_To", 8, 2)); fieldsEdit.AddField(this.CreateFieldDouble("Y_To", 8, 2)); fieldsEdit.AddField(this.CreateFieldDouble("M_To", 8, 2)); // add field to field collection fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast } // Use IFieldChecker to create a validated fields collection. ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass(); ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null; ESRI.ArcGIS.Geodatabase.IFields validatedFields = null; fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace; 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 and return the table table = featureWorkspace.CreateTable(tableName, validatedFields, uid, null, ""); return table; }
public static IFeatureClass CreateFeatureClassInPGDB(IWorkspace2 workspace, IFeatureDataset featureDataset, string featureClassName, IFields fields, UID CLSID, UID CLSEXT, string strConfigKeyword, esriGeometryType esriGeometryType) { if (featureClassName == "") return null; // name was not passed in ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass; ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, featureClassName)) //feature class with that name already exists { featureClass = featureWorkspace.OpenFeatureClass(featureClassName); return featureClass; } // assign the class id value if not assigned if (CLSID == null) { CLSID = new ESRI.ArcGIS.esriSystem.UIDClass(); CLSID.Value = "esriGeoDatabase.Feature"; } ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass(); // if a fields collection is not passed in then supply our own if (fields == null) { // create the fields using the required fields method fields = objectClassDescription.RequiredFields; ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast ESRI.ArcGIS.Geodatabase.IField field = new ESRI.ArcGIS.Geodatabase.FieldClass(); // create a user defined text field ESRI.ArcGIS.Geodatabase.IFieldEdit fieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)field; // Explicit Cast // setup field properties fieldEdit.Name_2 = "SampleField"; fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString; fieldEdit.IsNullable_2 = true; fieldEdit.AliasName_2 = "Sample Field Column"; fieldEdit.DefaultValue_2 = "test"; fieldEdit.Editable_2 = true; fieldEdit.Length_2 = 100; // add field to field collection fieldsEdit.AddField(field); fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast } System.String strShapeField = ""; // locate the shape field for (int j = 0; j < fields.FieldCount; j++) { if (fields.get_Field(j).Type == esriFieldType.esriFieldTypeGeometry) { strShapeField = fields.get_Field(j).Name; ((IGeometryDefEdit)fields.get_Field(j).GeometryDef).GeometryType_2 = esriGeometryType; } } // Use IFieldChecker to create a validated fields collection. ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass(); ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null; ESRI.ArcGIS.Geodatabase.IFields validatedFields = null; fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace; fieldChecker.Validate(fields, out enumFieldError, out validatedFields); // The enumFieldError enumerator can be inspected at this point to determine // which fields were modified during validation. // finally create and return the feature class if (featureDataset == null)// if no feature dataset passed in, create at the workspace level { featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword); } else { featureClass = featureDataset.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword); } return featureClass; }
private ESRI.ArcGIS.Geodatabase.IFeatureClass CreatePointFeatureClass(System.String featureClassName, ESRI.ArcGIS.Geodatabase.IFields fields, ESRI.ArcGIS.esriSystem.UID CLSID) { if (featureClassName == "") return null; // name was not passed in IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass(); // Create a new in-memory workspace. This returns a name object. IWorkspaceName workspaceName = workspaceFactory.Create(null, "OSMPointsWorkspace", null, 0); IName name = (IName)workspaceName; // Open the workspace through the name object. IWorkspace workspace = (IWorkspace)name.Open(); ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = null; ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast // assign the class id value if not assigned if (CLSID == null) { CLSID = new ESRI.ArcGIS.esriSystem.UIDClass(); CLSID.Value = "esriGeoDatabase.Feature"; } ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass(); // if a fields collection is not passed in then supply our own if (fields == null) { // create the fields using the required fields method fields = objectClassDescription.RequiredFields; ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast // add the OSM ID field IFieldEdit osmIDField = new FieldClass() as IFieldEdit; osmIDField.Name_2 = "OSMID"; osmIDField.Type_2 = esriFieldType.esriFieldTypeString; osmIDField.Length_2 = 20; fieldsEdit.AddField((IField)osmIDField); // add the field for the tag cloud for all other tag/value pairs IFieldEdit osmXmlTagsField = new FieldClass() as IFieldEdit; osmXmlTagsField.Name_2 = "osmTags"; osmXmlTagsField.Type_2 = esriFieldType.esriFieldTypeBlob; fieldsEdit.AddField((IField)osmXmlTagsField); // user, uid, visible, version, changeset, timestamp IFieldEdit osmuserField = new FieldClass() as IFieldEdit; osmuserField.Name_2 = "osmuser"; osmuserField.Type_2 = esriFieldType.esriFieldTypeString; osmuserField.Length_2 = 100; fieldsEdit.AddField((IField) osmuserField); IFieldEdit osmuidField = new FieldClass() as IFieldEdit; osmuidField.Name_2 = "osmuid"; osmuidField.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.AddField((IField)osmuidField); IFieldEdit osmvisibleField = new FieldClass() as IFieldEdit; osmvisibleField.Name_2 = "osmvisible"; osmvisibleField.Type_2 = esriFieldType.esriFieldTypeString; osmvisibleField.Length_2 = 20; fieldsEdit.AddField((IField)osmvisibleField); IFieldEdit osmversionField = new FieldClass() as IFieldEdit; osmversionField.Name_2 = "osmversion"; osmversionField.Type_2 = esriFieldType.esriFieldTypeSmallInteger; fieldsEdit.AddField((IField)osmversionField); IFieldEdit osmchangesetField = new FieldClass() as IFieldEdit; osmchangesetField.Name_2 = "osmchangeset"; osmchangesetField.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.AddField((IField)osmchangesetField); IFieldEdit osmtimestampField = new FieldClass() as IFieldEdit; osmtimestampField.Name_2 = "osmtimestamp"; osmtimestampField.Type_2 = esriFieldType.esriFieldTypeDate; fieldsEdit.AddField((IField)osmtimestampField); IFieldEdit osmrelationIDField = new FieldClass() as IFieldEdit; osmrelationIDField.Name_2 = "osmMemberOf"; osmrelationIDField.Type_2 = esriFieldType.esriFieldTypeBlob; fieldsEdit.AddField((IField)osmrelationIDField); IFieldEdit hasOSMTagsField = new FieldClass() as IFieldEdit; hasOSMTagsField.Name_2 = "hasOSMTags"; IFieldEdit osmSupportingElementField = new FieldClass() as IFieldEdit; osmSupportingElementField.Name_2 = "osmSupportingElement"; osmSupportingElementField.Type_2 = esriFieldType.esriFieldTypeString; osmSupportingElementField.Length_2 = 5; fieldsEdit.AddField((IField) osmSupportingElementField); IFieldEdit wayRefCountField = new FieldClass() as IFieldEdit; wayRefCountField.Name_2 = "wayRefCount"; wayRefCountField.Type_2 = esriFieldType.esriFieldTypeInteger; wayRefCountField.DefaultValue_2 = 0; fieldsEdit.AddField((IField)wayRefCountField); fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast } System.String strShapeField = ""; // locate the shape field for (int j = 0; j < fields.FieldCount; j++) { if (fields.get_Field(j).Type == ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry) { strShapeField = fields.get_Field(j).Name; // redefine geometry type IFieldEdit shapeField = fields.get_Field(j) as IFieldEdit; IGeometryDefEdit geometryDef = new GeometryDefClass() as IGeometryDefEdit; geometryDef.GeometryType_2 = esriGeometryType.esriGeometryPoint; geometryDef.HasZ_2 = false; geometryDef.HasM_2 = false; geometryDef.GridCount_2 = 1; geometryDef.set_GridSize(0, 1); ISpatialReferenceFactory spatialRefFactory = new SpatialReferenceEnvironmentClass(); ISpatialReference wgs84 = spatialRefFactory.CreateGeographicCoordinateSystem((int) esriSRGeoCSType.esriSRGeoCS_WGS1984) as ISpatialReference; geometryDef.SpatialReference_2 = wgs84; shapeField.GeometryDef_2 = (IGeometryDef)geometryDef; break; } } // Use IFieldChecker to create a validated fields collection. ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass(); ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null; ESRI.ArcGIS.Geodatabase.IFields validatedFields = null; fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace; fieldChecker.Validate(fields, out enumFieldError, out validatedFields); // The enumFieldError enumerator can be inspected at this point to determine // which fields were modified during validation. // finally create and return the feature class try { featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, null, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, ""); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } return featureClass; }
public IFeatureClass createFeatureClassInMemory(string strName, IFields FeatureFields, IWorkspace pWS, esriFeatureType featType) { ESRI.ArcGIS.esriSystem.UID CLSID = null; //ESRI.ArcGIS.esriSystem.UID CLSEXT = null; IFeatureWorkspace pFWS = null; ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = null; ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null; ESRI.ArcGIS.Geodatabase.IFields validatedFields = null; try { //CLSEXT = null; pFWS = (IFeatureWorkspace)pWS; if (CLSID == null) { CLSID = new ESRI.ArcGIS.esriSystem.UIDClass(); CLSID.Value = "esriGeoDatabase.Feature"; } fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass(); enumFieldError = null; validatedFields = null; fieldChecker.ValidateWorkspace = pWS; fieldChecker.Validate(FeatureFields, out enumFieldError, out validatedFields); bool FCCreated = false; IFeatureClass newFeat = null; int loopCnt = 0; while (FCCreated == false) { try { if (loopCnt == 0) { loopCnt = loopCnt + 1; newFeat = pFWS.CreateFeatureClass(strName, validatedFields, null, null, featType, "SHAPE", ""); } else { loopCnt = loopCnt + 1; newFeat = pFWS.CreateFeatureClass(strName + (loopCnt - 1).ToString(), validatedFields, null, null, featType, "SHAPE", ""); } FCCreated = true; } catch { FCCreated = false; } if (loopCnt == 100) FCCreated = true; } return newFeat; } catch { return null; } finally { CLSID = null; pFWS = null; fieldChecker = null; enumFieldError = null; validatedFields = null; } }
public IFeatureClass createFeatureClassInMemory(string strName, IFields FeatureFields, IWorkspace pWS, esriFeatureType featType) { ESRI.ArcGIS.esriSystem.UID CLSID = null; //ESRI.ArcGIS.esriSystem.UID CLSEXT = null; IFeatureWorkspace pFWS = null; ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = null; ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null; ESRI.ArcGIS.Geodatabase.IFields validatedFields = null; try { //CLSEXT = null; pFWS = (IFeatureWorkspace)pWS; if (CLSID == null) { CLSID = new ESRI.ArcGIS.esriSystem.UIDClass(); CLSID.Value = "esriGeoDatabase.Feature"; } fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass(); enumFieldError = null; validatedFields = null; fieldChecker.ValidateWorkspace = pWS; fieldChecker.Validate(FeatureFields, out enumFieldError, out validatedFields); bool FCCreated = false; IFeatureClass newFeat = null; int loopCnt = 0; while (FCCreated == false) { try { if (loopCnt == 0) { loopCnt = loopCnt + 1; newFeat = pFWS.CreateFeatureClass(strName, validatedFields, null, null, featType, "SHAPE", ""); } else { loopCnt = loopCnt + 1; newFeat = pFWS.CreateFeatureClass(strName + (loopCnt - 1).ToString(), validatedFields, null, null, featType, "SHAPE", ""); } FCCreated = true; } catch { FCCreated = false; } if (loopCnt == 100) { FCCreated = true; } } return(newFeat); } catch { return(null); } finally { CLSID = null; pFWS = null; fieldChecker = null; enumFieldError = null; validatedFields = null; } }
///<summary>Simple helper to create a featureclass in a geodatabase.</summary> /// ///<param name="workspace">An IWorkspace2 interface</param> ///<param name="featureDataset">An IFeatureDataset interface or Nothing</param> ///<param name="featureClassName">A System.String that contains the name of the feature class to open or create. Example: "states"</param> ///<param name="fields">An IFields interface</param> ///<param name="CLSID">A UID value or Nothing. Example "esriGeoDatabase.Feature" or Nothing</param> ///<param name="CLSEXT">A UID value or Nothing (this is the class extension if you want to reference a class extension when creating the feature class).</param> ///<param name="strConfigKeyword">An empty System.String or RDBMS table string for ArcSDE. Example: "myTable" or ""</param> /// ///<returns>An IFeatureClass interface or a Nothing</returns> /// ///<remarks> /// (1) If a 'featureClassName' already exists in the workspace a reference to that feature class /// object will be returned. /// (2) If an IFeatureDataset is passed in for the 'featureDataset' argument the feature class /// will be created in the dataset. If a Nothing is passed in for the 'featureDataset' /// argument the feature class will be created in the workspace. /// (3) When creating a feature class in a dataset the spatial reference is inherited /// from the dataset object. /// (4) If an IFields interface is supplied for the 'fields' collection it will be used to create the /// table. If a Nothing value is supplied for the 'fields' collection, a table will be created using /// default values in the method. /// (5) The 'strConfigurationKeyword' parameter allows the application to control the physical layout /// for this table in the underlying RDBMS—for example, in the case of an Oracle database, the /// configuration keyword controls the tablespace in which the table is created, the initial and /// next extents, and other properties. The 'strConfigurationKeywords' for an ArcSDE instance are /// set up by the ArcSDE data administrator, the list of available keywords supported by a workspace /// may be obtained using the IWorkspaceConfiguration interface. For more information on configuration /// keywords, refer to the ArcSDE documentation. When not using an ArcSDE table use an empty /// string (ex: ""). ///</remarks> internal ESRI.ArcGIS.Geodatabase.IFeatureClass CreatePolygonFeatureClass(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, ESRI.ArcGIS.Geodatabase.IFeatureDataset featureDataset, System.String featureClassName, ESRI.ArcGIS.Geodatabase.IFields fields, ESRI.ArcGIS.esriSystem.UID CLSID, ESRI.ArcGIS.esriSystem.UID CLSEXT, System.String strConfigKeyword, OSMDomains osmDomains, string metadataAbstract, string metadataPurpose) { if (featureClassName == "") return null; // name was not passed in ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = null; try { ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, featureClassName)) //feature class with that name already exists { // if a feature class with the same name already exists delete it.... featureClass = featureWorkspace.OpenFeatureClass(featureClassName); if (!DeleteDataset((IDataset)featureClass)) { return featureClass; } } // assign the class id value if not assigned if (CLSID == null) { CLSID = new ESRI.ArcGIS.esriSystem.UIDClass(); CLSID.Value = "esriGeoDatabase.Feature"; } ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass(); // if a fields collection is not passed in then supply our own if (fields == null) { // create the fields using the required fields method fields = objectClassDescription.RequiredFields; ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast // add the domain driven string field for the OSM features foreach (var domainAttribute in osmDomains.domain) { IFieldEdit domainField = new FieldClass() as IFieldEdit; domainField.Name_2 = domainAttribute.name; domainField.Type_2 = esriFieldType.esriFieldTypeString; domainField.Required_2 = true; domainField.Length_2 = 30; try { domainField.Domain_2 = ((IWorkspaceDomains)workspace).get_DomainByName(domainAttribute.name + "_ply"); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); System.Diagnostics.Debug.WriteLine(ex.StackTrace); } fieldsEdit.AddField((IField)domainField); } // add the OSM ID field IFieldEdit osmIDField = new FieldClass() as IFieldEdit; osmIDField.Name_2 = "OSMID"; osmIDField.Type_2 = esriFieldType.esriFieldTypeString; osmIDField.Length_2 = 20; osmIDField.Required_2 = true; fieldsEdit.AddField((IField)osmIDField); // add the field for the tag cloud for all other tag/value pairs IFieldEdit osmXmlTagsField = new FieldClass() as IFieldEdit; osmXmlTagsField.Name_2 = "osmTags"; osmXmlTagsField.Required_2 = true; //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace) //{ osmXmlTagsField.Type_2 = esriFieldType.esriFieldTypeBlob; //} //else //{ // osmXmlTagsField.Type_2 = esriFieldType.esriFieldTypeXML; //} fieldsEdit.AddField((IField)osmXmlTagsField); // user, uid, visible, version, changeset, timestamp IFieldEdit osmuserField = new FieldClass() as IFieldEdit; osmuserField.Name_2 = "osmuser"; osmuserField.Type_2 = esriFieldType.esriFieldTypeString; osmuserField.Required_2 = true; osmuserField.Length_2 = 100; fieldsEdit.AddField((IField)osmuserField); IFieldEdit osmuidField = new FieldClass() as IFieldEdit; osmuidField.Name_2 = "osmuid"; osmuidField.Required_2 = true; osmuidField.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.AddField((IField)osmuidField); IFieldEdit osmvisibleField = new FieldClass() as IFieldEdit; osmvisibleField.Name_2 = "osmvisible"; osmvisibleField.Required_2 = true; osmvisibleField.Type_2 = esriFieldType.esriFieldTypeString; osmvisibleField.Length_2 = 20; fieldsEdit.AddField((IField)osmvisibleField); IFieldEdit osmversionField = new FieldClass() as IFieldEdit; osmversionField.Name_2 = "osmversion"; osmversionField.Required_2 = true; osmversionField.Type_2 = esriFieldType.esriFieldTypeSmallInteger; fieldsEdit.AddField((IField)osmversionField); IFieldEdit osmchangesetField = new FieldClass() as IFieldEdit; osmchangesetField.Name_2 = "osmchangeset"; osmchangesetField.Required_2 = true; osmchangesetField.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.AddField((IField)osmchangesetField); IFieldEdit osmtimestampField = new FieldClass() as IFieldEdit; osmtimestampField.Name_2 = "osmtimestamp"; osmtimestampField.Required_2 = true; osmtimestampField.Type_2 = esriFieldType.esriFieldTypeDate; fieldsEdit.AddField((IField)osmtimestampField); IFieldEdit osmrelationIDField = new FieldClass() as IFieldEdit; osmrelationIDField.Name_2 = "osmMemberOf"; osmrelationIDField.Required_2 = true; //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace) //{ osmrelationIDField.Type_2 = esriFieldType.esriFieldTypeBlob; //} //else //{ // osmrelationIDField.Type_2 = esriFieldType.esriFieldTypeXML; //} fieldsEdit.AddField((IField)osmrelationIDField); //IFieldEdit osmrelationsField = new FieldClass() as IFieldEdit; //osmrelationsField.Name_2 = "osmMembers"; //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace) //{ // osmrelationsField.Type_2 = esriFieldType.esriFieldTypeBlob; //} //else //{ // osmrelationsField.Type_2 = esriFieldType.esriFieldTypeXML; //} //fieldsEdit.AddField((IField)osmrelationsField); IFieldEdit osmSupportingElementField = new FieldClass() as IFieldEdit; osmSupportingElementField.Name_2 = "osmSupportingElement"; osmSupportingElementField.Type_2 = esriFieldType.esriFieldTypeString; osmSupportingElementField.Length_2 = 5; osmSupportingElementField.DefaultValue_2 = "no"; osmSupportingElementField.Required_2 = true; fieldsEdit.AddField((IField)osmSupportingElementField); IFieldEdit osmMembersField = new FieldClass() as IFieldEdit; osmMembersField.Name_2 = "osmMembers"; //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace) //{ osmMembersField.Type_2 = esriFieldType.esriFieldTypeBlob; osmMembersField.Required_2 = true; //} //else //{ // osmMembersField.Type_2 = esriFieldType.esriFieldTypeXML; //} fieldsEdit.AddField((IField)osmMembersField); //IFieldEdit osmTrackChangesField = new FieldClass() as IFieldEdit; //osmTrackChangesField.Name_2 = "osmTrackChanges"; //osmTrackChangesField.Required_2 = true; //osmTrackChangesField.Type_2 = esriFieldType.esriFieldTypeSmallInteger; //osmTrackChangesField.DefaultValue_2 = 0; //fieldsEdit.AddField((IField)osmTrackChangesField); fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast } System.String strShapeField = ""; // locate the shape field for (int j = 0; j < fields.FieldCount; j++) { if (fields.get_Field(j).Type == ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry) { strShapeField = fields.get_Field(j).Name; // redefine geometry type IFieldEdit shapeField = fields.get_Field(j) as IFieldEdit; IGeometryDefEdit geometryDef = new GeometryDefClass() as IGeometryDefEdit; geometryDef.GeometryType_2 = esriGeometryType.esriGeometryPolygon; geometryDef.HasZ_2 = false; geometryDef.HasM_2 = false; geometryDef.GridCount_2 = 1; geometryDef.set_GridSize(0, 0); geometryDef.SpatialReference_2 = ((IGeoDataset)featureDataset).SpatialReference; shapeField.GeometryDef_2 = (IGeometryDef)geometryDef; break; } } // Use IFieldChecker to create a validated fields collection. ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass(); ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null; ESRI.ArcGIS.Geodatabase.IFields validatedFields = null; fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace; fieldChecker.Validate(fields, out enumFieldError, out validatedFields); // The enumFieldError enumerator can be inspected at this point to determine // which fields were modified during validation. // finally create and return the feature class if (featureDataset == null)// if no feature dataset passed in, create at the workspace level { featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword); IPropertySet extensionPropertySet = new PropertySetClass(); extensionPropertySet.SetProperty("VERSION", OSMClassExtensionManager.Version); ((IClassSchemaEdit2)featureClass).AlterClassExtensionProperties(extensionPropertySet); } else { featureClass = featureDataset.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword); IPropertySet extensionPropertySet = new PropertySetClass(); extensionPropertySet.SetProperty("VERSION", OSMClassExtensionManager.Version); ((IClassSchemaEdit2)featureClass).AlterClassExtensionProperties(extensionPropertySet); } // create the openstreetmap spcific metadata _osmUtility.CreateOSMMetadata((IDataset)featureClass, metadataAbstract, metadataPurpose); // the change at release 2.1 requires a new model name IModelInfo fcModelInfo = featureClass as IModelInfo; if (fcModelInfo != null) { fcModelInfo.ModelName = OSMClassExtensionManager.OSMModelName; } } catch { throw; } return featureClass; }
internal ESRI.ArcGIS.Geodatabase.ITable CreateRevisionTable(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, System.String tableName, ESRI.ArcGIS.Geodatabase.IFields fields, string storageKeyword) { // create the behavior clasid for the featureclass ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass(); if (workspace == null) return null; // valid feature workspace not passed in as an argument to the method ESRI.ArcGIS.Geodatabase.ITable table = null; try { ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTTable, tableName)) { // if a table with the same name already exists delete it....if that is not possible return the current instance table = featureWorkspace.OpenTable(tableName); if (!DeleteDataset((IDataset)table)) { return table; } } uid.Value = "esriGeoDatabase.Object"; ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass(); // if a fields collection is not passed in then supply our own if (fields == null) { // create the fields using the required fields method fields = objectClassDescription.RequiredFields; ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast // IFieldEdit osmChangesetField = new FieldClass() as IFieldEdit; osmChangesetField.Name_2 = "osmchangeset"; osmChangesetField.Required_2 = true; osmChangesetField.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.AddField((IField)osmChangesetField); IFieldEdit osmActionField = new FieldClass() as IFieldEdit; osmActionField.Name_2 = "osmaction"; osmActionField.Required_2 = true; osmActionField.Type_2 = esriFieldType.esriFieldTypeString; osmActionField.Length_2 = 10; fieldsEdit.AddField((IField)osmActionField); IFieldEdit osmElementTypeField = new FieldClass() as IFieldEdit; osmElementTypeField.Name_2 = "osmelementtype"; osmElementTypeField.Required_2 = true; osmElementTypeField.Type_2 = esriFieldType.esriFieldTypeString; osmElementTypeField.Length_2 = 10; fieldsEdit.AddField((IField)osmElementTypeField); IFieldEdit osmVersionField = new FieldClass() as IFieldEdit; osmVersionField.Name_2 = "osmversion"; osmVersionField.Required_2 = true; osmVersionField.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.AddField((IField)osmVersionField); IFieldEdit fcNameField = new FieldClass() as IFieldEdit; fcNameField.Name_2 = "sourcefcname"; fcNameField.Required_2 = true; fcNameField.Type_2 = esriFieldType.esriFieldTypeString; fcNameField.Length_2 = 50; fieldsEdit.AddField((IField)fcNameField); IFieldEdit osmOldIDField = new FieldClass() as IFieldEdit; osmOldIDField.Name_2 = "osmoldid"; osmOldIDField.Required_2 = true; osmOldIDField.Type_2 = esriFieldType.esriFieldTypeString; osmOldIDField.Length_2 = 20; fieldsEdit.AddField((IField)osmOldIDField); IFieldEdit osmNewIDField = new FieldClass() as IFieldEdit; osmNewIDField.Name_2 = "osmnewid"; osmNewIDField.Required_2 = true; osmNewIDField.Type_2 = esriFieldType.esriFieldTypeString; osmNewIDField.Length_2 = 20; fieldsEdit.AddField((IField)osmNewIDField); IFieldEdit latField = new FieldClass() as IFieldEdit; latField.Name_2 = "osmlat"; latField.Required_2 = true; latField.Type_2 = esriFieldType.esriFieldTypeDouble; latField.Scale_2 = 10; fieldsEdit.AddField((IField)latField); IFieldEdit lonField = new FieldClass() as IFieldEdit; lonField.Name_2 = "osmlon"; lonField.Required_2 = true; lonField.Type_2 = esriFieldType.esriFieldTypeDouble; lonField.Scale_2 = 10; fieldsEdit.AddField((IField)lonField); IFieldEdit statusField = new FieldClass() as IFieldEdit; statusField.Name_2 = "osmstatus"; statusField.Required_2 = true; statusField.Type_2 = esriFieldType.esriFieldTypeString; statusField.Length_2 = 40; fieldsEdit.AddField((IField)statusField); IFieldEdit statusCodeField = new FieldClass() as IFieldEdit; statusCodeField.Name_2 = "osmstatuscode"; statusCodeField.Required_2 = true; statusCodeField.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.AddField((IField)statusCodeField); IFieldEdit errorMessageField = new FieldClass() as IFieldEdit; errorMessageField.Name_2 = "osmerrormessage"; errorMessageField.Required_2 = true; errorMessageField.Type_2 = esriFieldType.esriFieldTypeString; errorMessageField.Length_2 = 255; fieldsEdit.AddField((IField)errorMessageField); fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast } // Use IFieldChecker to create a validated fields collection. ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass(); ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null; ESRI.ArcGIS.Geodatabase.IFields validatedFields = null; fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace; 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 and return the table table = featureWorkspace.CreateTable(tableName, validatedFields, uid, null, storageKeyword); } catch { throw; } return table; }
// ArcGIS Snippet Title: // Create Table // // Long Description: // Creates a dataset in a workspace. // // Add the following references to the project: // ESRI.ArcGIS.Geodatabase // ESRI.ArcGIS.Geometry // ESRI.ArcGIS.System // // Intended ArcGIS Products for this snippet: // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView) // ArcGIS Engine // ArcGIS Server // // Applicable ArcGIS Product Versions: // 9.2 // 9.3 // 9.3.1 // 10.0 // // Required ArcGIS Extensions: // (NONE) // // Notes: // This snippet is intended to be inserted at the base level of a Class. // It is not intended to be nested within an existing Method. // ///<summary>Creates a table with some default fields.</summary> /// ///<param name="workspace">An IWorkspace2 interface</param> ///<param name="tableName">A System.String of the table name in the workspace. Example: "owners"</param> ///<param name="fields">An IFields interface or Nothing</param> /// ///<returns>An ITable interface or Nothing</returns> /// ///<remarks> ///Notes: ///(1) If an IFields interface is supplied for the 'fields' collection it will be used to create the /// table. If a Nothing value is supplied for the 'fields' collection, a table will be created using /// default values in the method. ///(2) If a table with the supplied 'tableName' exists in the workspace an ITable will be returned. /// if table does not exit a new one will be created. ///</remarks> internal ESRI.ArcGIS.Geodatabase.ITable CreateRelationTable(ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace, System.String tableName, ESRI.ArcGIS.Geodatabase.IFields fields, string storageKeyword, string metadataAbstract, string metadataPurpose) { // create the behavior clasid for the featureclass ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass(); if (workspace == null) return null; // valid feature workspace not passed in as an argument to the method ESRI.ArcGIS.Geodatabase.ITable table = null; try { ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTTable, tableName)) { // if a table with the same name already exists delete it.... table = featureWorkspace.OpenTable(tableName); if (!DeleteDataset((IDataset)table)) { return table; } } uid.Value = "esriGeoDatabase.Object"; ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.ObjectClassDescriptionClass(); // if a fields collection is not passed in then supply our own if (fields == null) { // create the fields using the required fields method fields = objectClassDescription.RequiredFields; ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast // create OSM base fields the osm administrative fields // add the OSM ID field IFieldEdit osmIDField = new FieldClass() as IFieldEdit; osmIDField.Name_2 = "OSMID"; osmIDField.Required_2 = true; osmIDField.Type_2 = esriFieldType.esriFieldTypeString; osmIDField.Length_2 = 20; fieldsEdit.AddField((IField)osmIDField); // user, uid, visible, version, changeset, timestamp IFieldEdit osmuserField = new FieldClass() as IFieldEdit; osmuserField.Name_2 = "osmuser"; osmuserField.Required_2 = true; osmuserField.Type_2 = esriFieldType.esriFieldTypeString; osmuserField.Length_2 = 100; fieldsEdit.AddField((IField)osmuserField); IFieldEdit osmuidField = new FieldClass() as IFieldEdit; osmuidField.Name_2 = "osmuid"; osmuidField.Required_2 = true; osmuidField.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.AddField((IField)osmuidField); IFieldEdit osmvisibleField = new FieldClass() as IFieldEdit; osmvisibleField.Name_2 = "osmvisible"; osmvisibleField.Required_2 = true; osmvisibleField.Type_2 = esriFieldType.esriFieldTypeString; osmvisibleField.Length_2 = 20; fieldsEdit.AddField((IField)osmvisibleField); IFieldEdit osmversionField = new FieldClass() as IFieldEdit; osmversionField.Name_2 = "osmversion"; osmversionField.Required_2 = true; osmversionField.Type_2 = esriFieldType.esriFieldTypeSmallInteger; fieldsEdit.AddField((IField)osmversionField); IFieldEdit osmchangesetField = new FieldClass() as IFieldEdit; osmchangesetField.Name_2 = "osmchangeset"; osmchangesetField.Required_2 = true; osmchangesetField.Type_2 = esriFieldType.esriFieldTypeInteger; fieldsEdit.AddField((IField)osmchangesetField); IFieldEdit osmtimestampField = new FieldClass() as IFieldEdit; osmtimestampField.Name_2 = "osmtimestamp"; osmtimestampField.Required_2 = true; osmtimestampField.Type_2 = esriFieldType.esriFieldTypeDate; fieldsEdit.AddField((IField)osmtimestampField); IFieldEdit osmrelationIDField = new FieldClass() as IFieldEdit; osmrelationIDField.Name_2 = "osmMemberOf"; osmrelationIDField.Required_2 = true; //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace) //{ osmrelationIDField.Type_2 = esriFieldType.esriFieldTypeBlob; //} //else //{ // osmrelationIDField.Type_2 = esriFieldType.esriFieldTypeXML; //} fieldsEdit.AddField((IField)osmrelationIDField); IFieldEdit osmMembersField = new FieldClass() as IFieldEdit; osmMembersField.Name_2 = "osmMembers"; //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace) //{ osmMembersField.Required_2 = true; osmMembersField.Type_2 = esriFieldType.esriFieldTypeBlob; //} //else //{ // osmMembersField.Type_2 = esriFieldType.esriFieldTypeXML; //} fieldsEdit.AddField((IField)osmMembersField); // add the field for the tag cloud for all other tag/value pairs IFieldEdit osmXmlTagsField = new FieldClass() as IFieldEdit; osmXmlTagsField.Name_2 = "osmTags"; osmXmlTagsField.Required_2 = true; //if (((IWorkspace)workspace).Type == esriWorkspaceType.esriLocalDatabaseWorkspace) //{ osmXmlTagsField.Type_2 = esriFieldType.esriFieldTypeBlob; //} //else //{ // osmXmlTagsField.Type_2 = esriFieldType.esriFieldTypeXML; //} fieldsEdit.AddField((IField)osmXmlTagsField); //IFieldEdit osmTrackChangesField = new FieldClass() as IFieldEdit; //osmTrackChangesField.Name_2 = "osmTrackChanges"; //osmTrackChangesField.Required_2 = true; //osmTrackChangesField.Type_2 = esriFieldType.esriFieldTypeSmallInteger; //osmTrackChangesField.DefaultValue_2 = 0; //fieldsEdit.AddField((IField)osmTrackChangesField); fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast } // Use IFieldChecker to create a validated fields collection. ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass(); ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null; ESRI.ArcGIS.Geodatabase.IFields validatedFields = null; fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace; 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 and return the table table = featureWorkspace.CreateTable(tableName, validatedFields, uid, null, storageKeyword); // create the openstreetmap spcific metadata _osmUtility.CreateOSMMetadata((IDataset)table, metadataAbstract, metadataPurpose); } catch { throw; } return table; }
public static IFeatureClass CreateFeatureClassInPGDB(IWorkspace2 workspace, IFeatureDataset featureDataset, string featureClassName, IFields fields, UID CLSID, UID CLSEXT, string strConfigKeyword, esriGeometryType esriGeometryType) { if (featureClassName == "") { return(null); // name was not passed in } ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass; ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, featureClassName)) //feature class with that name already exists { featureClass = featureWorkspace.OpenFeatureClass(featureClassName); return(featureClass); } // assign the class id value if not assigned if (CLSID == null) { CLSID = new ESRI.ArcGIS.esriSystem.UIDClass(); CLSID.Value = "esriGeoDatabase.Feature"; } ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass(); // if a fields collection is not passed in then supply our own if (fields == null) { // create the fields using the required fields method fields = objectClassDescription.RequiredFields; ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast ESRI.ArcGIS.Geodatabase.IField field = new ESRI.ArcGIS.Geodatabase.FieldClass(); // create a user defined text field ESRI.ArcGIS.Geodatabase.IFieldEdit fieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)field; // Explicit Cast // setup field properties fieldEdit.Name_2 = "SampleField"; fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString; fieldEdit.IsNullable_2 = true; fieldEdit.AliasName_2 = "Sample Field Column"; fieldEdit.DefaultValue_2 = "test"; fieldEdit.Editable_2 = true; fieldEdit.Length_2 = 100; // add field to field collection fieldsEdit.AddField(field); fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast } System.String strShapeField = ""; // locate the shape field for (int j = 0; j < fields.FieldCount; j++) { if (fields.get_Field(j).Type == esriFieldType.esriFieldTypeGeometry) { strShapeField = fields.get_Field(j).Name; ((IGeometryDefEdit)fields.get_Field(j).GeometryDef).GeometryType_2 = esriGeometryType; } } // Use IFieldChecker to create a validated fields collection. ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass(); ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null; ESRI.ArcGIS.Geodatabase.IFields validatedFields = null; fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace; fieldChecker.Validate(fields, out enumFieldError, out validatedFields); // The enumFieldError enumerator can be inspected at this point to determine // which fields were modified during validation. // finally create and return the feature class if (featureDataset == null)// if no feature dataset passed in, create at the workspace level { featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword); } else { featureClass = featureDataset.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword); } return(featureClass); }