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.");
            }
        }
Esempio n. 2
0
        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.");
            }
        }