X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.app.geo%2Fsrc%2Forg%2Fargeo%2Fapp%2Fgeo%2Facr%2FGeoEntityUtils.java;h=48c3c1b438113f263f36296fff809f5fe8cb8d1e;hb=e0b05d6328f810c4009a636e52e20e6ece5c6c0a;hp=dca696285c25a4dc75c5e5c448329daf476afbfe;hpb=2e08c3d9f69332161101e1bdda35054ae953748f;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 dca6962..48c3c1b 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,15 +54,31 @@ public class GeoEntityUtils { } catch (IOException e) { throw new UncheckedIOException("Cannot add geometry " + name + " to " + c, e); } + +// try (BufferedReader in = new BufferedReader( +// new InputStreamReader(geom.open(InputStream.class), StandardCharsets.UTF_8))) { +// System.out.println(in.readLine()); +// } catch (IOException e) { +// throw new UncheckedIOException("Cannot parse " + c, e); +// } 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) { return getGeometry(c, name.qName(), clss); } 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,8 +92,13 @@ 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)) { + if (c.containsKey(WGS84PosName.lon) && c.containsKey(WGS84PosName.lat)) { Double lat = c.get(WGS84PosName.lat, Double.class).orElseThrow(); Double lon = c.get(WGS84PosName.lon, Double.class).orElseThrow(); return JTS.GEOMETRY_FACTORY_WGS84.createPoint(new Coordinate(lat, lon));