134 lines
6.1 KiB
C#
134 lines
6.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
|
|
|
|
using ArcGIS.Core.Geometry;
|
|
using ArcGIS.Desktop.Core.Geoprocessing;
|
|
using ArcGIS.Desktop.Mapping;
|
|
using ArcGIS.Desktop.Framework.Threading.Tasks;
|
|
using ArcGIS.Core.Data;
|
|
using ArcGIS.Desktop.Core;
|
|
using ArcGIS.Desktop.Editing;
|
|
using ArcGIS.Desktop.Internal.Layouts.Utilities;
|
|
|
|
namespace PruebaAddIn
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ProWindow1.xaml
|
|
/// </summary>
|
|
public partial class ProWindow1 : ArcGIS.Desktop.Framework.Controls.ProWindow
|
|
{
|
|
public ProWindow1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
string layerpath, outpath;
|
|
layerpath = "D:\\Proyectos\\Olivia\\Datos\\gdbs\\Soria.gdb\\prueba";
|
|
outpath = "D:\\Proyectos\\Olivia\\Pruebas";
|
|
//layerpath = @"Z:\Europe.gdb\Streets";
|
|
//layerpath = @"C:\Users\narvaling_epareja\Documents\ArcGIS\Projects\MyProject\MyProject.gdb\SanLorenzo";
|
|
//outpath = @"C:\Users\narvaling_epareja\Documents\PruebasOlivia";
|
|
ConvertShp(layerpath, outpath);
|
|
}
|
|
|
|
protected async Task<string> ConvertShp(string layerpath, string outpath)
|
|
{
|
|
if (!System.IO.Directory.Exists(outpath))
|
|
System.IO.Directory.CreateDirectory(outpath);
|
|
/*var valueArray = await QueuedTask.Run(() =>
|
|
{
|
|
//input layers list should contain the path of each layer name, i.e. if the root node is "Mapping" and the layer name is "gs_points", path is "Mapping\\gs_points".
|
|
List<string> inlayers = new List<string>();
|
|
inlayers.Add(layerpath);
|
|
//outpath is just the folder to save the shapefiles in
|
|
return Geoprocessing.MakeValueArray(inlayers, outpath);
|
|
});*/
|
|
|
|
EditOperation op = new EditOperation();
|
|
|
|
using (Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri("D:\\Proyectos\\Olivia\\Datos\\gdbs\\Soria.gdb"))))
|
|
{
|
|
//management.CreateFeatureClass
|
|
FeatureClass featureClass_out= fileGeodatabase.
|
|
using (FeatureClass featureClass = fileGeodatabase.OpenDataset<FeatureClass>("prueba"))
|
|
{
|
|
FeatureClassDefinition facilitySiteDefinition = featureClass.GetDefinition();
|
|
featureClass_out.CopyFrom<FeatureClass, FeatureClass>(featureClass);
|
|
featureClass_out.DeleteRows(null);
|
|
//int facilityIdIndex = facilitySiteDefinition.FindField("TIPO_ENT");
|
|
string whereClause = "NOM_TIPO_ENTIDAD = 'Aceras'";
|
|
//Selection sel = featureClass.Select(new QueryFilter { WhereClause = whereClause }, SelectionType.ObjectID, SelectionOption.Normal);
|
|
//FeatureClass featSel = sel as FeatureClass;
|
|
//IReadOnlyList<long> selectedOIDs = sel.GetObjectIDs();
|
|
Row row;
|
|
Feature feat;
|
|
using (RowCursor rowCursor = featureClass.Search(new QueryFilter { WhereClause = whereClause }))
|
|
{
|
|
while (rowCursor.MoveNext())
|
|
{
|
|
using (row = rowCursor.Current)
|
|
{
|
|
feat = row as Feature;
|
|
featureClass_out
|
|
}
|
|
}
|
|
}
|
|
|
|
var progDlg = new ProgressDialog("Running Geoprocessing Tool", "Cancel", 100, true);
|
|
progDlg.Show();
|
|
|
|
var progSrc = new CancelableProgressorSource(progDlg);
|
|
|
|
// prepare input parameter values to CopyFeatures tool
|
|
string input_data = layerpath;
|
|
//string out_workspace = ArcGIS.Desktop.Core.Project.Current.DefaultGeodatabasePath;
|
|
string out_data = outpath;
|
|
|
|
// make a value array of strings to be passed to ExecuteToolAsync
|
|
var parameters = Geoprocessing.MakeValueArray(input_data, out_data);
|
|
|
|
// execute the tool
|
|
IGPResult gpResult = await Geoprocessing.ExecuteToolAsync("FeatureClassToShapefile_conversion", parameters,
|
|
null, new CancelableProgressorSource(progDlg).Progressor, GPExecuteToolFlags.Default);
|
|
|
|
// dialog hides itself once the execution is complete
|
|
//progDlg.Hide();
|
|
|
|
|
|
/*//input layers list should contain the path of each layer name, i.e. if the root node is "Mapping" and the layer name is "gs_points", path is "Mapping\\gs_points".
|
|
List<string> inlayers = new List<string>();
|
|
inlayers.Add(layerpath);
|
|
//outpath is just the folder to save the shapefiles in
|
|
var valueArray = Geoprocessing.MakeValueArray(inlayers, outpath);
|
|
|
|
// to let the GP tool run asynchronously without blocking the main thread
|
|
// use the GPThread option of GPExecuteToolFlasgs
|
|
//
|
|
GPExecuteToolFlags flags = GPExecuteToolFlags.GPThread; // instruct the tool run non-blocking GPThread
|
|
IGPResult gpResult = await Geoprocessing.ExecuteToolAsync("FeatureClassToShapefile_conversion", valueArray, null, null, null, flags);*/
|
|
string res = string.IsNullOrEmpty(gpResult.ReturnValue)
|
|
? $@"Error in gp tool: {gpResult.ErrorMessages}"
|
|
: $@"Ok: {gpResult.ReturnValue}";
|
|
|
|
|
|
return res;
|
|
}
|
|
}
|
|
}
|
|
}
|