X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.app.geo%2Fsrc%2Forg%2Fargeo%2Fapp%2Fgeo%2Facr%2FGeoEntityUtils.java;h=62b432e7f42e59155d3f0a5f383b9057b087ef7d;hb=6e13b9416a5fd1f5477eb7233f86d3eacbb88c55;hp=f10d89e60ee38486af58cf64e4f9b0125c59b4a6;hpb=b384a9cbe93b83b3aa94fe46cf2ff0a929f0332c;p=gpl%2Fargeo-suite.git diff --git a/org.argeo.app.geo/src/org/argeo/app/geo/acr/GeoEntityUtils.java b/org.argeo.app.geo/src/org/argeo/app/geo/acr/GeoEntityUtils.java index f10d89e..62b432e 100644 --- a/org.argeo.app.geo/src/org/argeo/app/geo/acr/GeoEntityUtils.java +++ b/org.argeo.app.geo/src/org/argeo/app/geo/acr/GeoEntityUtils.java @@ -35,7 +35,6 @@ import jakarta.json.stream.JsonGenerator; /** Utilities around entity types related to geography. */ public class GeoEntityUtils { - public static final String PLACE_GEOM_JSON = "place.geom.json"; public static final String _GEOM_JSON = ".geom.json"; public static void putGeometry(Content c, QNamed name, Geometry geometry) { @@ -43,7 +42,7 @@ public class GeoEntityUtils { } public static void putGeometry(Content c, QName name, Geometry geometry) { - QName jsonFileName = new ContentName(name.getNamespaceURI(), name.getLocalPart() + _GEOM_JSON); + QName jsonFileName = getJsonFileName(name); Content geom = c.soleChild(jsonFileName).orElseGet( () -> c.add(jsonFileName, Collections.singletonMap(DName.getcontenttype.qName(), "application/json"))); try (OutputStream out = geom.open(OutputStream.class)) { @@ -55,7 +54,16 @@ public class GeoEntityUtils { } catch (IOException e) { throw new UncheckedIOException("Cannot add geometry " + name + " to " + c, e); } - // updateBoundingBox(c); + updateBoundingBox(c); + } + + public static boolean hasGeometry(Content c, QNamed name) { + return hasGeometry(c, name.qName()); + } + + public static boolean hasGeometry(Content c, QName name) { + QName jsonFileName = getJsonFileName(name); + return c.hasChild(jsonFileName); } public static T getGeometry(Content c, QNamed name, Class clss) { @@ -63,7 +71,7 @@ public class GeoEntityUtils { } public static T getGeometry(Content c, QName name, Class clss) { - QName jsonFileName = new ContentName(name.getNamespaceURI(), name.getLocalPart() + _GEOM_JSON); + QName jsonFileName = getJsonFileName(name); Content geom = c.soleChild(jsonFileName).orElse(null); if (geom == null) return null; @@ -77,6 +85,11 @@ public class GeoEntityUtils { } } + private static QName getJsonFileName(QName name) { + QName jsonFileName = new ContentName(name.getNamespaceURI(), name.getLocalPart() + _GEOM_JSON); + return jsonFileName; + } + public static Point toPoint(Content c) { if (c.hasContentClass(EntityType.geopoint)) { Double lat = c.get(WGS84PosName.lat, Double.class).orElseThrow();