Todavía avances en exportación
parent
c226ee4cc9
commit
63439152cd
|
|
@ -310,6 +310,62 @@ namespace OliviaAddInPro.Helper
|
|||
|
||||
}
|
||||
|
||||
//Crea un filtro espacial a partir de una consulta y en todo caso, una geometría
|
||||
public static ArcGIS.Core.Data.QueryFilter CreateFiler(string consulta, ArcGIS.Core.Geometry.Geometry geom, SpatialRelationship rel= SpatialRelationship.Intersects)
|
||||
{
|
||||
ArcGIS.Core.Data.QueryFilter filt=null;
|
||||
if (geom != null)
|
||||
{
|
||||
SpatialQueryFilter filtSpat = new SpatialQueryFilter
|
||||
{
|
||||
WhereClause = consulta,
|
||||
FilterGeometry = geom,
|
||||
SpatialRelationship = rel,
|
||||
};
|
||||
filt = (ArcGIS.Core.Data.QueryFilter)filtSpat;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
filt = new ArcGIS.Core.Data.QueryFilter();
|
||||
filt.WhereClause = consulta;
|
||||
}
|
||||
return filt;
|
||||
}
|
||||
|
||||
//Devuelve la lista de IDs de la clase que cumplen la consulta
|
||||
public static Task<List<long>> GetIds(FeatureClass fc, ArcGIS.Core.Data.QueryFilter filt)
|
||||
{
|
||||
ReiniciaOutStr();
|
||||
List<long> ids = new List<long>();
|
||||
Selection sel=null;
|
||||
return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func<List<long>>)(() =>
|
||||
{
|
||||
if (fc == null)
|
||||
return null;
|
||||
try
|
||||
{
|
||||
if (filt == null)
|
||||
filt = new ArcGIS.Core.Data.QueryFilter();
|
||||
sel = fc.Select(filt, SelectionType.ObjectID, SelectionOption.Normal);
|
||||
int nsel = sel.GetCount();
|
||||
IReadOnlyList<long> ids_= sel.GetObjectIDs();
|
||||
ids = ids_.ToList();
|
||||
return ids;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
HelperGdb.OutStr = "Error al conseguir IDs " + fc.GetName() + ": " + ex.Message;
|
||||
return ids;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Free(sel);
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
//Devuelve una lista con los campos de una feature class
|
||||
public static Task<ObservableCollection<string>> GetFields(FeatureClass fc)
|
||||
{
|
||||
|
|
@ -421,7 +477,8 @@ namespace OliviaAddInPro.Helper
|
|||
/**
|
||||
* Devuelve una geometría que es la suma de la inicial y la que se añade Add
|
||||
*/
|
||||
public static ArcGIS.Core.Geometry.Geometry IntersectGeom(ArcGIS.Core.Geometry.Geometry geomIni, ArcGIS.Core.Geometry.Geometry geomInters)
|
||||
public static ArcGIS.Core.Geometry.Geometry IntersectGeom(ArcGIS.Core.Geometry.Geometry geomIni, ArcGIS.Core.Geometry.Geometry geomInters,
|
||||
GeometryDimension resultDimension= GeometryDimension.esriGeometryNoDimension)
|
||||
{
|
||||
if (geomIni == null)
|
||||
return geomInters;
|
||||
|
|
@ -430,7 +487,11 @@ namespace OliviaAddInPro.Helper
|
|||
ArcGIS.Core.Geometry.Geometry geomSal = null;
|
||||
try
|
||||
{
|
||||
if(resultDimension== GeometryDimension.esriGeometryNoDimension)
|
||||
geomSal =GeometryEngine.Instance.Intersection(geomIni, geomInters);
|
||||
else
|
||||
geomSal = GeometryEngine.Instance.Intersection(geomIni, geomInters, resultDimension);
|
||||
|
||||
return geomSal;
|
||||
}
|
||||
catch
|
||||
|
|
@ -870,64 +931,121 @@ namespace OliviaAddInPro.Helper
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Elimina las filas indicadas del shp
|
||||
**/
|
||||
public static bool RemoveRowsFromShp(string shp_path, List<long> quita)
|
||||
{
|
||||
FeatureClass fc = HelperGdb.GetFtClassFromShp(shp_path).Result;
|
||||
if (fc == null)
|
||||
return false;
|
||||
|
||||
string message = String.Empty;
|
||||
bool deletionResult = false;
|
||||
|
||||
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => {
|
||||
string shpname = System.IO.Path.GetFileNameWithoutExtension(shp_path);
|
||||
var shapeFileConnPath = new FileSystemConnectionPath(new Uri(shp_path), FileSystemDatastoreType.Shapefile);
|
||||
var shapefile = new FileSystemDatastore(shapeFileConnPath);
|
||||
using (Table table = shapefile.OpenDataset<Table>(shp_path))
|
||||
{
|
||||
EditOperation editOperation = new EditOperation();
|
||||
editOperation.Callback(context =>
|
||||
{
|
||||
ArcGIS.Core.Data.QueryFilter openCutFilter = new ArcGIS.Core.Data.QueryFilter { WhereClause = "ACTION = 'Open Cut'" };
|
||||
|
||||
using (RowCursor rowCursor = table.Search(openCutFilter, false))
|
||||
{
|
||||
while (rowCursor.MoveNext())
|
||||
{
|
||||
using (Row row = rowCursor.Current)
|
||||
{
|
||||
// In order to update the Map and/or the attribute table. Has to be called before the delete.
|
||||
context.Invalidate(row);
|
||||
|
||||
row.Delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, table);
|
||||
|
||||
try
|
||||
{
|
||||
deletionResult = editOperation.Execute();
|
||||
if (!deletionResult)
|
||||
{
|
||||
message = editOperation.ErrorMessage;
|
||||
}
|
||||
}
|
||||
catch (GeodatabaseException exObj)
|
||||
{
|
||||
message = exObj.Message;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!string.IsNullOrEmpty(message))
|
||||
{
|
||||
OutStr = message;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recorre los ámbitos lineales del shp viendo qué longitud tienen dentro de la geometría, y si
|
||||
* es menos de un porcentaje, lo quitan del shp
|
||||
**/
|
||||
public static bool RemoveRowsGeom(string shp_path, ArcGIS.Core.Geometry.Geometry geom_zon, double porc)
|
||||
{
|
||||
|
||||
/*int[] ids = null;
|
||||
IFeature f = null;
|
||||
IFeatureClass fc = null;
|
||||
IGeometry geom_aux = null;
|
||||
ITopologicalOperator union = null;
|
||||
IPolyline poli = null;
|
||||
double longi_zon = 0, longi_tot = 0;
|
||||
List<int> quita = new List<int>();
|
||||
int j;
|
||||
|
||||
try
|
||||
{
|
||||
ids = FunGDB.dame_ids_consulta(shp_path, ""); //consulta todos
|
||||
if (ids == null)
|
||||
return false;
|
||||
fc = FunGDB.abre_ftclass(shp_path);
|
||||
FeatureClass fc = HelperGdb.GetFtClassFromShp(shp_path).Result;
|
||||
if (fc == null)
|
||||
return false;
|
||||
for (j = 0; j < ids.Length; j++)
|
||||
{
|
||||
f = fc.GetFeature(ids[j]);
|
||||
geom_aux = f.Shape;
|
||||
poli = (IPolyline)geom_aux;
|
||||
longi_tot = poli.Length;
|
||||
union = (ITopologicalOperator)geom_zon;
|
||||
if (geom_aux == null)
|
||||
return false;
|
||||
geom_aux = union.Intersect(geom_aux, esriGeometryDimension.esriGeometry1Dimension);//se realiza la interseccion entre ámbito (linea) y nivel (poligono)
|
||||
poli = (IPolyline)geom_aux;
|
||||
longi_zon = poli.Length;//se consigue la longitud de ámbito (linea) que interseca con el nivel)
|
||||
ArcGIS.Core.Geometry.Geometry geom = null;
|
||||
ArcGIS.Core.Geometry.Polyline line = null;
|
||||
Feature f = null;
|
||||
double longi_zon = 0, longi_tot = 0;
|
||||
List<long> quita = new List<long>();
|
||||
|
||||
int j=0;
|
||||
List<long> ids;
|
||||
try
|
||||
{
|
||||
//Obtiene los IDs
|
||||
ids = GetIds(fc, null).Result;
|
||||
//Recorre las features de la capa
|
||||
RowCursor cursor = fc.Search();
|
||||
while(cursor.MoveNext())
|
||||
{
|
||||
f = (Feature)cursor.Current;
|
||||
geom = f.GetShape();
|
||||
line = (ArcGIS.Core.Geometry.Polyline)geom;
|
||||
longi_tot = line.Length;
|
||||
geom= IntersectGeom(geom_zon, line,GeometryDimension.esriGeometry1Dimension);
|
||||
line =(ArcGIS.Core.Geometry.Polyline)geom;
|
||||
longi_zon = line.Length;//se consigue la longitud de ámbito (linea) que interseca con el nivel)
|
||||
if ((longi_zon / longi_tot) < porc)
|
||||
{
|
||||
//quita esa línea
|
||||
quita.Add(ids[j]);
|
||||
}
|
||||
FunGDB.libera(f);
|
||||
j++;
|
||||
Free(f);
|
||||
}
|
||||
|
||||
|
||||
FunGDB.libera(fc);
|
||||
FunGDB.libera(f);
|
||||
Free(f);
|
||||
Free(fc);
|
||||
Free(cursor);
|
||||
|
||||
if (quita.Count > 0)
|
||||
{
|
||||
//borra las líneas que se han indicado
|
||||
if (!FunGDB.quita_filas(shp_path, quita))
|
||||
if (!RemoveRowsFromShp(shp_path, quita))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
|
@ -935,10 +1053,10 @@ namespace OliviaAddInPro.Helper
|
|||
}
|
||||
finally
|
||||
{
|
||||
FunGDB.libera(fc);
|
||||
FunGDB.libera(f);
|
||||
}*/
|
||||
return true;
|
||||
HelperGdb.Free(fc);
|
||||
HelperGdb.Free(f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,37 +65,62 @@ namespace OliviaAddInPro.Services
|
|||
{
|
||||
//mira spatialreference de los datos de entrada
|
||||
spatRef = geom_export.SpatialReference;
|
||||
filtroEspacial = CreaFiltro(com.ConsultaAmbs, geom_export);
|
||||
filtroEspacial = (SpatialQueryFilter) HelperGdb.CreateFiler(com.ConsultaAmbs, geom_export);
|
||||
fue_mal = filtroEspacial == null;
|
||||
if (fue_mal)
|
||||
ErrStr = "error al crear el filtro de exportacion";
|
||||
|
||||
cps.Value = 80;
|
||||
ErrStr = "Error al crear el filtro de exportacion";
|
||||
|
||||
if (!fue_mal)
|
||||
fue_mal = Exporta(modo, cps, out ErrStr); //Falta pasar el filtro espacial
|
||||
|
||||
}
|
||||
fue_mal = Exporta(modo, cps, out ErrStr);
|
||||
if (!fue_mal)
|
||||
{
|
||||
//Guarda el nombre
|
||||
OliviaGlob.Paths.PathData = OliviaGlob.Paths.DirData + com.NombreShpExport;
|
||||
}
|
||||
}
|
||||
cps.Value = 80;
|
||||
if (!fue_mal)
|
||||
{
|
||||
//hace intersecciones espaciales en caso de ámbitos lineales para quitar los que tienen más parte fuera de la zona que dentro
|
||||
if (geom_export != null &&
|
||||
(OliviaGlob.IsReco() || (OliviaGlob.IsLimp() && (com.TipoTto < (int)LimpiezaDef.TiposTto.TtoPapeVaci))))
|
||||
{
|
||||
//FALTA RELLENAR
|
||||
if (!HelperGdb.RemoveRowsGeom(OliviaGlob.Paths.PathData, geom_export, 0.4))
|
||||
{
|
||||
ErrStr = "Error al quitar los ámbitos que sobresalen";
|
||||
ErrStr = "Error al quitar los ámbitos que sobresalen: "+HelperGdb.OutStr;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
//comprueba que no se haya quedado sin ámbitos
|
||||
using (FeatureClass fc = HelperGdb.GetFtClassFromShp(OliviaGlob.Paths.PathData).Result)
|
||||
{
|
||||
if (fc.GetCount() <= 0)
|
||||
{
|
||||
ErrStr = "No quedan ámbitos que cumplan la geometría seleccionada.";
|
||||
return false;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//amplia la geom para englobar las instalaciones
|
||||
geom_export = HelperGdb.GetGeomConvexHull(fc, null, cps).Result;
|
||||
/*if (limp.coords_instala[0] != 0 && limp.coords_instala[1] != 0)
|
||||
{
|
||||
//hay instalación
|
||||
if (!FunGDB.is_pto_in_geom(limp.coords_instala[0], limp.coords_instala[1], geom_ambits))
|
||||
geom_ambits = FunGDB.amplia_geom_convexhull(geom_ambits, limp.coords_instala[0], limp.coords_instala[1]);
|
||||
|
||||
//comprueba, si hay restricciones de circulación, que la instalación no está en ellas
|
||||
if (limp.geom_rest_acces != null)
|
||||
{
|
||||
if (FunGDB.is_pto_in_geom(limp.coords_instala[0], limp.coords_instala[1], limp.geom_rest_acces))
|
||||
{
|
||||
err_st = "Error, la instalación sal/lleg está en la zona restringida a la circulación";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
//exporta la red navegable (buffer, le quita las restr...)
|
||||
|
||||
|
|
@ -146,7 +171,7 @@ namespace OliviaAddInPro.Services
|
|||
cps.Value = 30;
|
||||
|
||||
//prepara el filtro con consulta y espacial
|
||||
SpatialQueryFilter filtro = CreaFiltro(com.ConsultaAmbs, geomAux);
|
||||
SpatialQueryFilter filtro = (SpatialQueryFilter)HelperGdb.CreateFiler(com.ConsultaAmbs, geomAux);
|
||||
|
||||
//Ahora hace la geometría de los ámbitos que cumplen la consulta
|
||||
geomAmbits = HelperGdb.GetGeomConvexHull(fc, filtro, cps).Result;
|
||||
|
|
@ -172,17 +197,6 @@ namespace OliviaAddInPro.Services
|
|||
return geomAux;
|
||||
}
|
||||
|
||||
public SpatialQueryFilter CreaFiltro(string consulta, Geometry geom)
|
||||
{
|
||||
SpatialQueryFilter filtSpac = new SpatialQueryFilter
|
||||
{
|
||||
WhereClause = consulta,
|
||||
FilterGeometry = geom,
|
||||
SpatialRelationship = SpatialRelationship.Contains,
|
||||
};
|
||||
return filtSpac;
|
||||
}
|
||||
|
||||
/**
|
||||
* Devuelve el string a concatenar en el nombre del path dependiendo de los polígonos seleccionados (zonas, turnos... etc)
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ namespace OliviaAddInPro.Services
|
|||
//se consigue el tiempo en este instante para añadirlo a los nombres de los archivos de salida (shapefiles)
|
||||
fechaHora = DateTime.Now.ToString("yyyyMMdd_Hmmss");
|
||||
//Pone nombre al shape en función de los ámbitos, el tratamiento, y los polígonos + timestamp
|
||||
//reco.NombreShpExport = prefNameExport + "T" + reco.TipoTto.ToString("00") + nombFileAmbs + DameStrPoligs() + "_" + fechaHora + extShp;
|
||||
reco.NombreShpExport = prefNameExport + "T" + reco.TipoTto.ToString("00") + nombFileAmbs + DameStrPoligs() + "_" + fechaHora + extShp;
|
||||
|
||||
string msg = "";
|
||||
//comienza ejecucion
|
||||
|
|
|
|||
Loading…
Reference in New Issue