Todavía avances en exportación

ConfiguracionSimplificada
Elena 2022-01-31 23:34:16 +01:00
parent c226ee4cc9
commit 63439152cd
3 changed files with 201 additions and 69 deletions

View File

@ -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 //Devuelve una lista con los campos de una feature class
public static Task<ObservableCollection<string>> GetFields(FeatureClass fc) 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 * 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) if (geomIni == null)
return geomInters; return geomInters;
@ -430,7 +487,11 @@ namespace OliviaAddInPro.Helper
ArcGIS.Core.Geometry.Geometry geomSal = null; ArcGIS.Core.Geometry.Geometry geomSal = null;
try try
{ {
geomSal=GeometryEngine.Instance.Intersection(geomIni, geomInters); if(resultDimension== GeometryDimension.esriGeometryNoDimension)
geomSal =GeometryEngine.Instance.Intersection(geomIni, geomInters);
else
geomSal = GeometryEngine.Instance.Intersection(geomIni, geomInters, resultDimension);
return geomSal; return geomSal;
} }
catch catch
@ -870,64 +931,121 @@ namespace OliviaAddInPro.Helper
return true; 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 * 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 * es menos de un porcentaje, lo quitan del shp
**/ **/
public static bool RemoveRowsGeom(string shp_path, ArcGIS.Core.Geometry.Geometry geom_zon, double porc) public static bool RemoveRowsGeom(string shp_path, ArcGIS.Core.Geometry.Geometry geom_zon, double porc)
{ {
FeatureClass fc = HelperGdb.GetFtClassFromShp(shp_path).Result;
/*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);
if (fc == null) if (fc == null)
return false; return false;
for (j = 0; j < ids.Length; j++) ArcGIS.Core.Geometry.Geometry geom = null;
{ ArcGIS.Core.Geometry.Polyline line = null;
f = fc.GetFeature(ids[j]); Feature f = null;
geom_aux = f.Shape; double longi_zon = 0, longi_tot = 0;
poli = (IPolyline)geom_aux; List<long> quita = new List<long>();
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)
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) if ((longi_zon / longi_tot) < porc)
{ {
//quita esa línea //quita esa línea
quita.Add(ids[j]); quita.Add(ids[j]);
} }
FunGDB.libera(f); j++;
Free(f);
} }
Free(f);
Free(fc);
FunGDB.libera(fc); Free(cursor);
FunGDB.libera(f);
if (quita.Count > 0) if (quita.Count > 0)
{ {
//borra las líneas que se han indicado //borra las líneas que se han indicado
if (!FunGDB.quita_filas(shp_path, quita)) if (!RemoveRowsFromShp(shp_path, quita))
return false; return false;
} }
return true; return true;
} }
catch (Exception) catch (Exception)
{ {
@ -935,10 +1053,10 @@ namespace OliviaAddInPro.Helper
} }
finally finally
{ {
FunGDB.libera(fc); HelperGdb.Free(fc);
FunGDB.libera(f); HelperGdb.Free(f);
}*/ }
return true;
} }
} }

View File

@ -65,37 +65,62 @@ namespace OliviaAddInPro.Services
{ {
//mira spatialreference de los datos de entrada //mira spatialreference de los datos de entrada
spatRef = geom_export.SpatialReference; spatRef = geom_export.SpatialReference;
filtroEspacial = CreaFiltro(com.ConsultaAmbs, geom_export); filtroEspacial = (SpatialQueryFilter) HelperGdb.CreateFiler(com.ConsultaAmbs, geom_export);
fue_mal = filtroEspacial == null; fue_mal = filtroEspacial == null;
if (fue_mal) if (fue_mal)
ErrStr = "error al crear el filtro de exportacion"; ErrStr = "Error al crear el filtro de exportacion";
cps.Value = 80;
if (!fue_mal) 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) if (!fue_mal)
{ {
//Guarda el nombre
OliviaGlob.Paths.PathData = OliviaGlob.Paths.DirData + com.NombreShpExport; 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 //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 && if (geom_export != null &&
(OliviaGlob.IsReco() || (OliviaGlob.IsLimp() && (com.TipoTto < (int)LimpiezaDef.TiposTto.TtoPapeVaci)))) (OliviaGlob.IsReco() || (OliviaGlob.IsLimp() && (com.TipoTto < (int)LimpiezaDef.TiposTto.TtoPapeVaci))))
{ {
//FALTA RELLENAR
if (!HelperGdb.RemoveRowsGeom(OliviaGlob.Paths.PathData, geom_export, 0.4)) 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; return false;
} }
} }
} }
//comprueba que no se haya quedado sin ámbitos //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 //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...) //exporta la red navegable (buffer, le quita las restr...)
@ -146,7 +171,7 @@ namespace OliviaAddInPro.Services
cps.Value = 30; cps.Value = 30;
//prepara el filtro con consulta y espacial //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 //Ahora hace la geometría de los ámbitos que cumplen la consulta
geomAmbits = HelperGdb.GetGeomConvexHull(fc, filtro, cps).Result; geomAmbits = HelperGdb.GetGeomConvexHull(fc, filtro, cps).Result;
@ -172,17 +197,6 @@ namespace OliviaAddInPro.Services
return geomAux; 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) * Devuelve el string a concatenar en el nombre del path dependiendo de los polígonos seleccionados (zonas, turnos... etc)
*/ */

View File

@ -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) //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"); fechaHora = DateTime.Now.ToString("yyyyMMdd_Hmmss");
//Pone nombre al shape en función de los ámbitos, el tratamiento, y los polígonos + timestamp //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 = ""; string msg = "";
//comienza ejecucion //comienza ejecucion