public bool RunTool(string toolName, IVariantArray parameters, ITrackCancel TC, bool showResultDialog) { GeoProcessor gp = new GeoProcessor(); IGeoProcessorResult result = null; // Execute the tool try { result = (IGeoProcessorResult)gp.Execute(toolName, parameters, TC); string re = result.GetOutput(0).GetAsText(); if (showResultDialog) { ReturnMessages(result, ""); } if (result.MaxSeverity == 2) //error { return(false); } else { return(true); } } catch (COMException err) { MessageBox.Show(err.Message + " in RunTool"); ReturnMessages(result, ""); } catch (Exception err) { MessageBox.Show(err.Message + " in RunTool"); ReturnMessages(result, ""); } return(false); }
private void button1_Click(object sender, EventArgs e) { try { IGeoProcessor gp = new GeoProcessor(); ListData listData = new ListData(); IGpEnumList datasets = listData.listDatasetsFGDB(gp); //Check that the enumeration list is not null; if (datasets != null) { string dataset = datasets.Next(); while (dataset != "") { // Put the name of the dataset on the checked list box this.clbDatasets.Items.Add(dataset,false); // Set input raster dataset. dataset = datasets.Next(); } } } catch (COMException COMex) { MessageBox.Show("Error " + COMex.ErrorCode.ToString() + ": " + COMex.Message); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } }
private void buttonXExport_Click(object sender, EventArgs e) { try { IVariantArray parameters = new VarArrayClass(); string layers = ""; for (int i = 0; i < listBox2.Items.Count; i++) { layers = layers + listBox2.Items[i].ToString() + ";"; } layers = layers.TrimEnd(';'); // parameters.Add(@"D:\mydb.gdb\myFeatuerClass1;D:\mydb.gdb\myFeatuerClass2"); //parameters.Add("DWG_R2007"); //parameters.Add(@"C:\temp\ExportCAD.DWG"); parameters.Add(layers); parameters.Add(comboBox1.SelectedItem.ToString()); parameters.Add(textBox1.Text); GeoProcessor gp = new GeoProcessor(); bool response = RunTool("ExportCAD_conversion", parameters, null, false); MessageBox.Show("导出完成"); } catch { } }
/// <summary> /// Provides convenience methods for dealing /// with Geoprocessor issues. (Override: using IGeoProcessor) /// </summary> public static string ReturnGpMessages(GeoProcessor gp, System.Object obj) { string message = ""; if (gp.MessageCount > 0) { for (int i = 0; i <= gp.MessageCount - 1; i++) { message += gp.GetMessage(i) + "\n"; } } return(message); }
private void btnListButton_Click(object sender, EventArgs e) { try { //Connect connect = new Connect("192.168.56.101", "192.168.56.101", "postgres", "postgres", "eauc", "SDE.Default"); Connect connect = new Connect("localhost", "localhost", "sde", "sde", "eauc", "SDE.Default"); /// <param name="server">For example, server = "Kona".</param> /// <param name="instance">Database = "SDE" or "" if Oracle.</param> /// <param name="user">Instance = "5151".</param> /// <param name="password">User = "******".</param> /// <param name="database">Password = "******".</param> /// <param name="version">Version = "SDE.DEFAULT".</param> /// //Get the workspace object IWorkspace iWorkspace = connect.ConnectToTransactionalVersion(); ListData listData = new ListData(iWorkspace); IGeoProcessor gp = new GeoProcessor(); IGpEnumList datasets = listData.listDatasets(gp); //Check that the enumeration list is not null; if (datasets!=null) { string dataset = datasets.Next(); while (dataset != "") { // Put the name of the dataset on the checked list box this.clbDatasets.Items.Add(dataset, false); // Set input raster dataset. dataset = datasets.Next(); } } } catch (COMException COMex) { MessageBox.Show("Error " + COMex.ErrorCode.ToString() + ": " + COMex.Message); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } }
public Task <string> DoGeoprocessingThing(CancellationToken cts, BackgroundWorker worker) { System.Object obj = ""; Geoprocessor gp1 = new Geoprocessor(); GeoProcessor gp = new GeoProcessor(); gp1.OverwriteOutput = true; try { // ################################################ // Working call to an existing ArcGIS Toolbox Tool: CreateFileGDB createFileGdb = new CreateFileGDB(); createFileGdb.out_folder_path = "c:/temp"; createFileGdb.out_name = "tmp.gdb"; gp1.Execute(createFileGdb, null); // ############################################### // ########################################### // This process will fail if you've already started ArcObjects by opening the form UI dialog gp.AddToolbox(@"C:\temp\ArcObjectsIssue\HelloTest.tbx"); //path to your toolbox here!!!!!!!!!!!!!!! IVariantArray parameters = new VarArrayClass(); parameters = new VarArrayClass(); parameters.Add("Hello Geoprocessing Tool with Python Script!"); gp.Execute("helloPython", parameters, null); cts.ThrowIfCancellationRequested(); // ########################################### } catch (Exception e) { Console.WriteLine(e.ToString()); Console.WriteLine(ReturnGpMessages(gp, obj)); //from a support library not shared here. throw new Exception("yeah things went south"); } finally { gp = null; gp1 = null; GC.Collect(); GC.WaitForPendingFinalizers(); } return(null); }
static void Main(string[] args) { RuntimeManager.Bind(ProductCode.Desktop); GeoProcessor gp =new GeoProcessor(); IVariantArray parameters = new VarArrayClass(); //input layer location parameters.Add(@"C:\junk\122.mdb\test"); //output location parameters.Add(@"C:\\Users\\shri7493\\Documents\\ArcGIS\\Default.gdb\\TBL_HYDRANT_Statistics"); //summary field followed by summary method - in this case "MAX" - maximium value parameters.Add("OBJECTID MAX"); IGeoProcessorResult gpResult = gp.Execute("Statistics_analysis", parameters, null); for (int i = 0; i < gpResult.MessageCount; i++) { Console.Write (gpResult.GetMessage(i).ToString()); } gp.ClearMessages(); }
//gp的执行 private void ExecuteGP(IVariantArray parameters, string strToolName) { ITrackCancel pTrackCancel = null; //找到tool ESRI.ArcGIS.Geoprocessing.GeoProcessor _geoPro = new GeoProcessor(); pTrackCancel = new TrackCancelClass(); IVariantArray pVArray = new VarArrayClass(); IGPEnvironmentManager pgpEnv = new GPEnvironmentManager(); IGPMessages pGpMessages; //= _geoPro.Validate(parameters, false, pgpEnv); IGPComHelper pGPCOMHelper = new GpDispatch(); //这里是关键,如果不赋值的话,那么就会报错 IGPEnvironmentManager pEnvMgr = pGPCOMHelper.EnvironmentManager; pgpEnv.PersistAll = true; pGpMessages = new GPMessagesClass(); // Execute the model tool by name. _geoPro.Execute(strToolName, parameters, pTrackCancel); }
static void Main(string[] args) { RuntimeManager.Bind(ProductCode.Desktop); GeoProcessor gp = new GeoProcessor(); IVariantArray parameters = new VarArrayClass(); //input layer location parameters.Add(@"C:\junk\122.mdb\test"); //output location parameters.Add(@"C:\\Users\\shri7493\\Documents\\ArcGIS\\Default.gdb\\TBL_HYDRANT_Statistics"); //summary field followed by summary method - in this case "MAX" - maximium value parameters.Add("OBJECTID MAX"); IGeoProcessorResult gpResult = gp.Execute("Statistics_analysis", parameters, null); for (int i = 0; i < gpResult.MessageCount; i++) { Console.Write(gpResult.GetMessage(i).ToString()); } gp.ClearMessages(); }
private void clbDatasets_ItemCheck(object sender, ItemCheckEventArgs e) { //this.clbDatasets. // Determine if there are any items checked. if (clbDatasets.CheckedItems.Count != 0) { // If so, loop through all checked items and print results. string dataset = ""; for (int x = 0; x <= clbDatasets.CheckedItems.Count - 1; x++) { dataset = clbDatasets.CheckedItems[x].ToString(); rtbDatasetsToLoad.AppendText(dataset + "\r\n\t"); //raise a call to load data from the workspace //loop through to load the database IGeoProcessor gp = new GeoProcessor(); ListData listData = new ListData(); IGpEnumList fcs = listData.listFeatureClassesFGDB(gp, dataset); string fc = fcs.Next(); while (fc != "") { rtbDatasetsToLoad.AppendText(fc + "\r\n\t"); //Console.WriteLine(fc); fc = fcs.Next(); } } //MessageBox.Show(s); } }
//利用quickexport进行数据转换 gdb-->dwg 有扩展属性的转换 private void QuickExportToDWG(string strSource, string strdwgFile, DCtype type, string strTemplate) { ITrackCancel pTrackCancel = null; //找到tool ESRI.ArcGIS.Geoprocessing.GeoProcessor _geoPro = new GeoProcessor(); pTrackCancel = new TrackCancelClass(); IVariantArray pVArray = new VarArrayClass(); IVariantArray parameters = new VarArrayClass(); //模板文件 string strT = ""; if (strTemplate != "") { strT = ",_TMPL," + strTemplate;// D:\南京\data\dddd.dwg } string strtoolName = ""; if (type == DCtype.HasXdata) { parameters.Add(strSource); parameters.Add("ACAD," + strdwgFile); parameters.Add("RUNTIME_MACROS,"); parameters.Add("_ATTRKIND,extended_entity_data,_REL,Release2000" + strT); parameters.Add(",META_MACROS,"); parameters.Add("Dest_ATTRKIND,extended_entity_data,Dest_REL,Release2000" + strT); parameters.Add(",METAFILE,ACAD,COORDSYS,,__FME_DATASET_IS_SOURCE__,false"); strtoolName = "QuickExport_interop"; } else if (type == DCtype.NoXdata) { parameters.Add(strSource); parameters.Add("ACAD," + strdwgFile); parameters.Add("RUNTIME_MACROS,"); parameters.Add("_ATTRKIND,ignore,_REL,Release2000" + strT); parameters.Add(",META_MACROS,"); parameters.Add("Dest_ATTRKIND,ignore,Dest_REL,Release2000" + strT); parameters.Add(",METAFILE,ACAD,COORDSYS,,__FME_DATASET_IS_SOURCE__,false"); strtoolName = "QuickExport_interop"; } else if (type == DCtype.FmeXdata) { string strTblPath = Application.StartupPath + "\\dc.tbx"; if (strTemplate == "") { parameters.Add(strSource); parameters.Add(strdwgFile); _geoPro.AddToolbox(strTblPath); strtoolName = "SpatialETLTool"; } else { parameters.Add(strSource); parameters.Add(strdwgFile); parameters.Add(strTemplate); _geoPro.AddToolbox(strTblPath); strtoolName = "SpatialETLTool"; } } else { return; } IGPEnvironmentManager pgpEnv = new GPEnvironmentManager(); IGPMessages pGpMessages; //= _geoPro.Validate(parameters, false, pgpEnv); IGPComHelper pGPCOMHelper = new GpDispatch(); //这里是关键,如果不赋值的话,那么就会报错 //IGPEnvironmentManager pEnvMgr = pGPCOMHelper.EnvironmentManager; //pgpEnv.PersistAll = true; //pGpMessages = new GPMessagesClass(); // Execute the model tool by name. _geoPro.Execute(strtoolName, parameters, pTrackCancel); }
/// <summary> /// Evento Clic del boton Ejecutar /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnEjecutar_Click_1(object sender, EventArgs e) { //if (!LicenseInitializer.InitializeApplication("arcinfo")) //{ // if (!LicenseInitializer.InitializeApplication("arcview")) // { // MessageBox.Show("No posee licencia de arcview o arcinfo"); // } //} if (chkUtilizarImagenes.Checked) { SIGPIParametros parametros = new SIGPIParametros(); String tempDir = parametros.TempDir; String currentPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase); currentPath = currentPath.Replace("file:\\", ""); //String currentPath = //Path.GetDirectoryName(Application.ExecutablePath); String dateDir = tempDir + "\\" + DateTime.Now.ToString("yyyy-MM-dd"); String MODIS_DIR = "modis"; String SIGPI_PROCESS_BAT = "sigpi_process.bat"; if (System.IO.Directory.Exists(dateDir)) { try { System.IO.Directory.Delete(dateDir); } catch (Exception ex) { Console.WriteLine(ex.Message); } } System.IO.Directory.CreateDirectory(dateDir); String[] files = System.IO.Directory.GetFiles(currentPath + "\\" + MODIS_DIR); foreach (String f in files) { System.IO.File.Copy(f, dateDir + "\\" + f.Substring(f.LastIndexOf("\\") + 1, f.Length - (f.LastIndexOf("\\") + 1)), true); } Process proc = new Process(); proc.StartInfo.FileName = dateDir + "\\" + SIGPI_PROCESS_BAT; proc.StartInfo.Arguments = ""; proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal; proc.StartInfo.ErrorDialog = false; proc.StartInfo.WorkingDirectory = dateDir; proc.Start(); proc.WaitForExit(); if (proc.ExitCode != 0) { Console.WriteLine("Error ejecutando..."); } } IGeoProcessor gp = new GeoProcessor(); // || txtRutaTemperatura.Text.Trim().Length == 0 if (chkUtilizarImagenes.Checked & (txtRutaPrecipitacion.Text.Trim().Length == 0)) { MessageBox.Show("Busque las capa de precipitacion solicitadas"); return; } //string sRasterPrecipitacionSatelite = txtRutaPrecipitacion.Text; //string sFecha = txtRutaPrecipitacion.Text.Substring(txtRutaPrecipitacion.Text.IndexOf('_'), 20).Replace("_satelite_", ""); //String[] sFecha2 = sFecha.Split('_'); //DateTime dFechaPrecipitacionSatelite = new DateTime(Convert.ToInt32(sFecha2[0]), Convert.ToInt32(sFecha2[1]), Convert.ToInt32(sFecha2[2])); String[] sRastersPrecipitacionX10 = new String[10]; //DateTime dTemp; //String sTemp; //for (int i = 0; i < 10; i++) //{ // dTemp = dFechaPrecipitacionSatelite.AddDays(-i); // sTemp = dTemp.ToString("yyyy_MM_dd"); // +"_" + dTemp.ToString("MM") + "_" + dTemp.ToString("dd"); // sRastersPrecipitacionX10[i] = sRasterPrecipitacionSatelite.Replace(sFecha, sTemp); //} GenerarModelo("PRECIPITACION_PROMEDIO", "PRECIPITACION_PROMEDIO.SUM_PREC >= 0", "", "TEMPERATURA_PROMEDIO", "TEMPERATURA_PROMEDIO.TEMP_PROM >= 0", chkUtilizarImagenes.Checked, chkVerResultadorIntermedios.Checked, sRastersPrecipitacionX10); }
private byte[] OperazioneRestDownloadFeatureHandler(NameValueCollection boundVariables, JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = null; #region Istanzio il JSON Result JsonObject result = new JsonObject(); result.AddBoolean("hasError", false); #endregion bool found = operationInput.TryGetArray("listaOID", out object[] paramListaOID); if (!found || paramListaOID == null) { throw new ArgumentNullException("listaOID"); } bool okParam2 = operationInput.TryGetString("URLServiceLayer", out string paramURL); if (!okParam2 || paramURL == String.Empty) { throw new ArgumentNullException("URLServiceLayer"); } IGeoProcessor2 gp = new GeoProcessor() as IGeoProcessor2; gp.OverwriteOutput = true; try { result.AddArray("interno", paramListaOID); // Ricavo Feature Class dietro al Service Layer IFeatureClass featureClass = MapServiceHelper_GiancaGIS.RicavaFCDaURLServiceLayer(this.serverObjectHelper, paramURL); IFeatureLayer fLayer = new FeatureLayerClass { FeatureClass = featureClass, Name = "Mio Layer", SpatialReference = ((IGeoDataset)featureClass).SpatialReference }; IFeatureSelection featureSelection = fLayer as IFeatureSelection; IQueryFilter2 queryFilter = new QueryFilterClass { WhereClause = "OBJECTID IN (" + String.Join(",", paramListaOID) + ")" }; featureSelection.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, false); this.CreaWorkSpaceOutput(out IWorkspaceName WorkspaceNameOUT, out string pathFGDB); IVariantArray parameters = new VarArrayClass(); parameters.Add(fLayer); parameters.Add(System.IO.Path.Combine(pathFGDB, "output")); gp.Execute("CopyFeatures_management", parameters, null); this.ZippaFGDB(System.IO.Path.GetDirectoryName(pathFGDB), out string pathZip); result.AddString("zip", pathZip); } catch (Exception errore) { object severity = null; string errGp = gp.GetMessages(ref severity); if (!string.IsNullOrEmpty(errGp)) { result.AddBoolean("GeoProcessingError", true); result.AddString("erroreGp", errGp); } result.AddString("errorDescription", errore.Message); result.AddBoolean("hasError", true); } return(Encoding.UTF8.GetBytes(result.ToJson())); }