Trying to fix the Centroid Object registered in the Project #25056

This commit is contained in:
Francesco Mangiacrapa 2023-05-04 11:54:44 +02:00
parent 5e98b60a20
commit fe0869975a
2 changed files with 92 additions and 4 deletions

View File

@ -2,6 +2,7 @@
## [v1.1.1-SNAPSHOT]
- Improved some logs
- Fixed: Centroid Object registered in the Project [#25056]
## [v1.1.0]
- Integrated the field 'geov_link' (Geoportal GisViewer link) in the centroid layer [#24859]

View File

@ -141,7 +141,7 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
centroidDoc.put(DBConstants.Defaults.PROJECT_ID, project.getId());
centroidDoc.put(DBConstants.Defaults.DISPLAYED, true);
// Added by Francesco. Creating Gis Viewer Link as public or private
//*********** Added by Francesco. Creating Gis Viewer Link as public or private
Boolean isInternalIndex = null;
try {
isInternalIndex = requestArguments.getBoolean(IndexConstants.INDEX_PARAMETER_FLAGINTERNALINDEX);
@ -173,10 +173,90 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
log.error("Error on creating the Geoportal GisViewer link for project id {}", project.getId(), e);
}
}
// ********************** EVALAUTE POSITION
// ********************** Updated by Francesco, see #25056, EVALAUTE POSITION
log.debug("indexing UseCaseDescriptor {} : Evaluating Centroid... ", useCaseDescriptor.getId());
SpatialReference reference = null;
List<IdentificationReference> refs = project
.getIdentificationReferenceByType(SpatialReference.SPATIAL_REFERENCE_TYPE);
GCubeSDILayer.BBOX bbox = null;
if (!refs.isEmpty()) {
// Use existing Reference
try {
reference = Serialization.convert(refs.get(0), SpatialReference.class);
log.debug("Using already defined spatial reference " + reference);
GeoJsonObject object = Serialization.convert(reference.getGeoJson(), GeoJsonObject.class);
bbox = GCubeSDILayer.BBOX.fromGeoJSON(object.getBbox());
log.info("Found declared BBOX {} ", bbox);
Double pointX = (bbox.getMaxX() + bbox.getMinX()) / 2;
Double pointY = (bbox.getMaxY() + bbox.getMinY()) / 2;
String wkt = String.format("POINT (%1$f %2$f) ", pointX, pointY);
centroidDoc.put("geom", wkt);
}catch (Exception e) {
log.info("Is defined spatial reference wrong or empty? " + reference);
}
}
if(bbox==null) {
log.info("No bbox defined in the current spatial reference going to calculate it...");
// unable to use current Spatial reference, try evaluating it
log.debug("UseCaseDescriptor {} : Getting evaluation paths from useCaseDescriptor.. ",
useCaseDescriptor.getId());
// for each configuration option try until found
GCubeSDILayer.BBOX toSet = null;
for (BBOXEvaluator evaluator : BBOX_EVALUATORS) {
log.trace("UCD {}, Project {}. Evaluating BBOX with {}", useCaseDescriptor.getId(), project.getId(),
evaluator);
try {
if (evaluator.isConfigured(profileConfiguration)) {
toSet = evaluator.evaluate(profileConfiguration, useCaseDescriptor, documentNavigator);
if (toSet != null) {
log.info("UCD {}, Project {}. Evaluated BBOX {} with method {}",
useCaseDescriptor.getId(), project.getId(), toSet, evaluator);
break;
}
}
} catch (Throwable t) {
log.warn("UCD {}, Project {}. Exception with {}", useCaseDescriptor.getId(), project.getId(),
evaluator, t);
}
}
if (toSet == null)
throw new IndexingException("No BBOX has been evaluated from project");
Double pointX = (toSet.getMaxX() + toSet.getMinX()) / 2;
Double pointY = (toSet.getMaxY() + toSet.getMinY()) / 2;
log.info("Evaluated BBOX {} ", toSet);
String wkt = String.format("POINT (%1$f %2$f) ", pointX, pointY);
// TODO support altitude
Double pointZ = 0d;
centroidDoc.put("geom", wkt);
Point point = new Point();
point.setCoordinates(new LngLatAlt(pointX, pointY, pointZ));
point.setBbox(toSet.asGeoJSONArray());
// TODO Manage CRS
point.setCrs(new Crs());
reference = new SpatialReference(Serialization.asDocument(point));
log.info("UCD {} project {}, Setting Spatial Reference {} ", useCaseDescriptor.getId(), project.getId(),
Serialization.write(reference));
report.addIdentificationReference(reference);
}
// ********************** EVALAUTE POSITION
/*log.debug("indexing UseCaseDescriptor {} : Evaluating Centroid... ", useCaseDescriptor.getId());
SpatialReference reference = null;
List<IdentificationReference> refs = project
.getIdentificationReferenceByType(SpatialReference.SPATIAL_REFERENCE_TYPE);
if (!refs.isEmpty()) {
@ -244,7 +324,7 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
log.info("UCD {} project {}, Setting Spatial Reference {} ", useCaseDescriptor.getId(), project.getId(),
Serialization.write(reference));
report.addIdentificationReference(reference);
}
}*/
// *********** Additional Values from useCaseDescriptor
@ -328,6 +408,13 @@ public class SDIIndexerPlugin extends SDIAbstractPlugin implements IndexerPlugin
try {
PostgisIndexer indexer = getIndexer(request.getUseCaseDescriptor(), request.getCallParameters());
indexer.removeByFieldValue(PostgisIndexer.StandardFields.PROJECT_ID, request.getDocument().getId());
//***** Added by Francesco, see #25056
//Replacing the "old" centroid if any. Creating an empty SpatialReference
SpatialReference reference = new SpatialReference(new Document());
log.info("UCD {} project {}, Setting Spatial Reference empty {} ", request.getDocument().getId(), Serialization.write(reference));
report.addIdentificationReference(reference);
} catch (SDIInteractionException e) {
log.error("Unable to index " + request, e);
report.setStatus(Report.Status.ERROR);