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; }
public static void ExportLayerToUploadableRaster(string outputFilePath, string name, ILayer source) { try { // cast the selected/requested layer into a raster layer ESRI.ArcGIS.Carto.IRasterLayer rasterLayer = (IRasterLayer)source; // create a new raster to raster converter utility ESRI.ArcGIS.DataManagementTools.CopyRaster raster2raster = new ESRI.ArcGIS.DataManagementTools.CopyRaster(); // set the input raster layer raster2raster.in_raster = rasterLayer; // set the output path and Shapefile name /* The name and location of the raster dataset to be created. * .bil—Esri BIL * .bip—Esri BIP * .bmp—BMP * .bsq—Esri BSQ * .dat—ENVI DAT * .gif—GIF * .img—ERDAS IMAGINE * .jpg—JPEG * .jp2—JPEG 2000 * .png—PNG * .tif—TIFF * no extension for Esri Grid */ raster2raster.out_rasterdataset = outputFilePath + "\\" + name + ".tif"; // create a new GeoProcessor Geoprocessor geoprocessor = new Geoprocessor(); geoprocessor.TemporaryMapLayers = true; // execute the RasterToOtherFormat geoprocessor.Execute(raster2raster, null); } catch (Exception ex) { // an error occured System.Windows.Forms.MessageBox.Show("Error: " + ex.Message); } }