178 lines
6.6 KiB
C#
178 lines
6.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Policy;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using ArcGIS.Desktop.Catalog;
|
|
using ArcGIS.Desktop.Core;
|
|
using ArcGIS.Desktop.Framework;
|
|
using System.Collections.ObjectModel;
|
|
using ArcGIS.Core.Geometry;
|
|
using ArcGIS.Core.Data;
|
|
using ArcGIS.Desktop.Mapping;
|
|
|
|
namespace OliviaAddInPro.Helper
|
|
{
|
|
public static class HelperGdb
|
|
{
|
|
[Flags]
|
|
public enum TiposOpenFileDlg
|
|
{
|
|
OpenFtrClassLine=1,
|
|
OpenFtrClassPoint=2,
|
|
OpenFtrClassPolygon=4,
|
|
OpenGdb=8,
|
|
}
|
|
|
|
public static FeatureClass OpenFtClassDialog(TiposOpenFileDlg tipo, string initialLoc = "")
|
|
{
|
|
Item it = OpenFileDialog( tipo, initialLoc);
|
|
FeatureClass fc = it as FeatureClass;
|
|
return fc;
|
|
}
|
|
|
|
public static async Task<Geodatabase> OpenGdb(string path)
|
|
{
|
|
try
|
|
{
|
|
await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => {
|
|
// Opens a file geodatabase. This will open the geodatabase if the folder exists and contains a valid geodatabase.
|
|
using (
|
|
Geodatabase geodatabase =
|
|
new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(path))))
|
|
{
|
|
return geodatabase;
|
|
}
|
|
});
|
|
}
|
|
catch (GeodatabaseNotFoundOrOpenedException exception)
|
|
{
|
|
// Handle Exception.
|
|
}
|
|
return null;
|
|
|
|
}
|
|
|
|
//Devuelve el Path del archivo seleccionado o un string vacío si se ha cancelado
|
|
public static Item OpenFileDialog(TiposOpenFileDlg tipo, string initialLoc="")
|
|
{
|
|
string titulo;
|
|
titulo = "Abrir Archivo";
|
|
//Create a browse filter that uses Pro's "esri_browseDialogFilters_geodatabases" filter.
|
|
//The browse filter is used in an OpenItemDialog.
|
|
//fuentes filtros
|
|
//https://github.com/Esri/arcgis-pro-sdk-community-samples/blob/master/Map-Exploration/IdentifyWindow/Daml.cs
|
|
BrowseProjectFilter filtro = new BrowseProjectFilter();
|
|
if ((tipo & TiposOpenFileDlg.OpenFtrClassLine)== TiposOpenFileDlg.OpenFtrClassLine)
|
|
{
|
|
filtro.AddFilter(BrowseProjectFilter.GetFilter("esri_browseDialogFilters_featureClasses_line"));
|
|
titulo = "Abrir Feature Class";
|
|
}
|
|
if ((tipo & TiposOpenFileDlg.OpenFtrClassPoint) == TiposOpenFileDlg.OpenFtrClassPoint)
|
|
{
|
|
filtro.AddFilter(BrowseProjectFilter.GetFilter("esri_browseDialogFilters_featureClasses_point"));
|
|
titulo = "Abrir Feature Class";
|
|
}
|
|
if ((tipo & TiposOpenFileDlg.OpenFtrClassPolygon) == TiposOpenFileDlg.OpenFtrClassPolygon)
|
|
{
|
|
filtro.AddFilter(BrowseProjectFilter.GetFilter("esri_browseDialogFilters_featureClasses_polygon"));
|
|
titulo = "Abrir Feature Class";
|
|
}
|
|
if ((tipo & TiposOpenFileDlg.OpenGdb) == TiposOpenFileDlg.OpenGdb)
|
|
{
|
|
filtro.AddFilter(BrowseProjectFilter.GetFilter("esri_browseDialogFilters_geodatabases"));
|
|
titulo = "Abrir Geodatabase";
|
|
}
|
|
if(tipo==0)
|
|
{
|
|
filtro.AddFilter(BrowseProjectFilter.GetFilter(""));
|
|
}
|
|
//Display the filter in an Open Item dialog
|
|
OpenItemDialog aNewFilter = new OpenItemDialog
|
|
{
|
|
Title = titulo,
|
|
InitialLocation = initialLoc,
|
|
MultiSelect = false,
|
|
//Set the BrowseFilter property to Pro's Geodatabase filter.
|
|
BrowseFilter = filtro
|
|
};
|
|
bool? ok = aNewFilter.ShowDialog();
|
|
if ((ok ?? true) && aNewFilter.Items.Count() > 0)
|
|
return aNewFilter.Items.First();
|
|
else
|
|
return null;
|
|
}
|
|
|
|
/*public static bool SelecPolig(string title, int wnd_handle, out string text_sal, out IGeometry geom_sal)
|
|
{
|
|
|
|
}
|
|
public static bool SelecInstal(string title, int wnd_handle, out string text_sal, out double x, out double y)
|
|
{
|
|
|
|
}*/
|
|
|
|
public static Table GetTable(string pathLyr)
|
|
{
|
|
Table tb=null;
|
|
Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(pathLyr)));
|
|
// FeatureLayer lyr = new FeatureLayer();
|
|
|
|
return tb;
|
|
}
|
|
|
|
public static ObservableCollection<string> GetFields(FeatureClass fc)
|
|
{
|
|
ObservableCollection<string> fields = new ObservableCollection<string>();
|
|
|
|
|
|
return fields;
|
|
}
|
|
|
|
public static ObservableCollection<string> GetAttributes(FeatureClass fc, string fieldName)
|
|
{
|
|
ObservableCollection<string> attribs = new ObservableCollection<string>();
|
|
|
|
return attribs;
|
|
}
|
|
|
|
public static Geometry GetGeomSel(string pathLyr, string selField, ObservableCollection<string> selAttributes, out string textoSal)
|
|
{
|
|
string _textosal = "";
|
|
Geometry geomsal = null;
|
|
|
|
/*is_str = FunGDB.is_str_field(clase_path, selField);
|
|
nval = list.selec_valores_campo(selField, out val_ids, out val_st);//valores únicos
|
|
if (nval > 0)
|
|
{
|
|
//se embucla para unir las geoms
|
|
for (int i = 0; i < nval; i++)
|
|
{
|
|
if (is_str)
|
|
consulta = selField + " = '" + val_st[i] + "'";
|
|
else
|
|
consulta = selField + " = " + val_st[i];
|
|
ids = FunGDB.dame_ids_consulta(clase_path, consulta);
|
|
fc = FunGDB.abre_ftclass(clase_path);
|
|
if ((ids != null) && (fc != null))
|
|
{
|
|
for (j = 0; j < ids.Length; j++)
|
|
{
|
|
f = fc.GetFeature(ids[j]);
|
|
geom = f.Shape;
|
|
geom_sal = FunGDB.une_geoms(geom_sal, geom);
|
|
FunGDB.libera(f);
|
|
}
|
|
}
|
|
FunGDB.libera(fc);
|
|
//Actualiza el texto de salida
|
|
_textosal = _textosal + HelperGlobal.RevisaText(val_st[i]);
|
|
}
|
|
}*/
|
|
textoSal = _textosal;
|
|
return geomsal;
|
|
}
|
|
}
|
|
}
|