예제 #1
0
        private void UploadToGoogleMapsEngine_Load(object sender, EventArgs e)
        {
            // establish a reference to the running ArcMap instance
            ESRI.ArcGIS.ArcMapUI.IMxDocument mxDoc = (ESRI.ArcGIS.ArcMapUI.IMxDocument)ArcMap.Application.Document;

            // retrieve a reference to the selected layer
            ESRI.ArcGIS.Carto.ILayer selectedLayer = mxDoc.SelectedLayer;

            // get the data layer of this feature layer
            ESRI.ArcGIS.Carto.IDataLayer2 dataLayer
                = (ESRI.ArcGIS.Carto.IDataLayer2)selectedLayer;
            ESRI.ArcGIS.Geodatabase.IDatasetName datasetName
                = (ESRI.ArcGIS.Geodatabase.IDatasetName)dataLayer.DataSourceName;

            // add a script manager to the browser
            // in order to capture select events
            webBrowser.ObjectForScripting = new BrowerScriptManager(this);

            // fetch the upload_dialog_html resource
            log.Debug("fetch the upload_dialog_html resource");
            string uploadhtml = Properties.Resources.upload_dialog_html;

            // populate the source dataset information
            uploadhtml = uploadhtml.Replace("{sourcename}", datasetName.Name);
            uploadhtml = uploadhtml.Replace("{sourceworkspace}", datasetName.WorkspaceName.PathName);

            // configure raster/vector specific information
            if (selectedLayer is ESRI.ArcGIS.Carto.IFeatureLayer)
            {
                // cast the selected layer into a feature layer
                ESRI.ArcGIS.Carto.IFeatureLayer featureLayer
                    = (ESRI.ArcGIS.Carto.IFeatureLayer)selectedLayer;

                // set the source vector type
                uploadhtml = uploadhtml.Replace("{sourcetype}", featureLayer.DataSourceType);

                // set the variable upload type to vector
                uploadType = "vector";
            }
            else if (selectedLayer is ESRI.ArcGIS.Carto.IRasterLayer)
            {
                // cast the selected layer into a raster layer
                ESRI.ArcGIS.Carto.IRasterLayer rasterLayer
                    = (ESRI.ArcGIS.Carto.IRasterLayer)selectedLayer;

                // set the source raster type
                uploadhtml = uploadhtml.Replace("{sourcetype}", "Raster: "
                                                + rasterLayer.RowCount + " rows, " + rasterLayer.ColumnCount + " columns, "
                                                + rasterLayer.BandCount + " bands");

                // set the variable upload type to raster
                uploadType = "raster";
            }

            // set the upload html
            log.Debug("Setting the HTML to the web browser on the dialog.");
            this.webBrowser.DocumentText = uploadhtml;
        }
예제 #2
0
        internal void removeLayerByName(String datasetName, String workspacePathName)
        {
            if (m_map.LayerCount > 0)
            {
                // go through each layer in the Table of Contents
                for (int i = 0; i < m_map.LayerCount; i++)
                {
                    // get the layer
                    ILayer layer = m_map.get_Layer(i);

                    // get the data layer of this feature layer
                    ESRI.ArcGIS.Carto.IDataLayer2 dataLayer
                        = (ESRI.ArcGIS.Carto.IDataLayer2)layer;
                    ESRI.ArcGIS.Geodatabase.IDatasetName layerDatasetName
                        = (ESRI.ArcGIS.Geodatabase.IDatasetName)dataLayer.DataSourceName;

                    // create two workspace directory info objects to compare
                    System.IO.DirectoryInfo layerWorkspaceDir
                        = new DirectoryInfo(layerDatasetName.WorkspaceName.PathName);
                    System.IO.DirectoryInfo requestedWorkspaceDir
                        = new DirectoryInfo(workspacePathName);

                    // compare the layer name and workspace
                    if (String.Compare(layerDatasetName.Name,
                                       datasetName,
                                       StringComparison.InvariantCultureIgnoreCase) == 0 &&
                        layerWorkspaceDir.Exists &&
                        requestedWorkspaceDir.Exists &&
                        String.Compare(layerWorkspaceDir.FullName.TrimEnd('\\'),
                                       requestedWorkspaceDir.FullName.TrimEnd('\\'),
                                       StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        // delete the layer
                        m_map.DeleteLayer(layer);

                        // remove reference to layer name objects
                        layerDatasetName = null;
                        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(dataLayer);
                        dataLayer = null;

                        // release the layer object
                        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(layer);
                        layer = null;

                        return;
                    }
                }
            }
        }