From 0ea0fd7a08cb99dcd242b03f9063f574950e785b Mon Sep 17 00:00:00 2001 From: Brian Osborn Date: Mon, 28 Mar 2016 15:35:50 -0600 Subject: [PATCH 1/3] Creation of JSON utility without functionality --- .../nga/wkb/util/GeometryJSONCompatible.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/mil/nga/wkb/util/GeometryJSONCompatible.java diff --git a/src/main/java/mil/nga/wkb/util/GeometryJSONCompatible.java b/src/main/java/mil/nga/wkb/util/GeometryJSONCompatible.java new file mode 100644 index 0000000..7c7dbfe --- /dev/null +++ b/src/main/java/mil/nga/wkb/util/GeometryJSONCompatible.java @@ -0,0 +1,24 @@ +package mil.nga.wkb.util; + +import mil.nga.wkb.geom.Geometry; + +/** + * JSON compatible object representation of a Geometry + * + * @author osbornb + * @since 1.0.2 + */ +public class GeometryJSONCompatible { + + /** + * Get a Geometry object that is JSON compatible + * + * @param geometry + * geometry + * @return geometry JSON object + */ + public static Object getJSONCompatibleGeometry(Geometry geometry) { + return null; // TODO + } + +} From c3ab31b93623d8813edeb5f974ee15f7dcbd630e Mon Sep 17 00:00:00 2001 From: Brian Osborn Date: Tue, 29 Mar 2016 12:40:17 -0600 Subject: [PATCH 2/3] Geometry JSON compatible object utility implementation --- .../nga/wkb/util/GeometryJSONCompatible.java | 209 +++++++++++++++++- 1 file changed, 208 insertions(+), 1 deletion(-) diff --git a/src/main/java/mil/nga/wkb/util/GeometryJSONCompatible.java b/src/main/java/mil/nga/wkb/util/GeometryJSONCompatible.java index 7c7dbfe..61538f6 100644 --- a/src/main/java/mil/nga/wkb/util/GeometryJSONCompatible.java +++ b/src/main/java/mil/nga/wkb/util/GeometryJSONCompatible.java @@ -1,6 +1,24 @@ package mil.nga.wkb.util; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import mil.nga.wkb.geom.CircularString; +import mil.nga.wkb.geom.CompoundCurve; import mil.nga.wkb.geom.Geometry; +import mil.nga.wkb.geom.GeometryCollection; +import mil.nga.wkb.geom.GeometryType; +import mil.nga.wkb.geom.LineString; +import mil.nga.wkb.geom.MultiLineString; +import mil.nga.wkb.geom.MultiPoint; +import mil.nga.wkb.geom.MultiPolygon; +import mil.nga.wkb.geom.Point; +import mil.nga.wkb.geom.Polygon; +import mil.nga.wkb.geom.PolyhedralSurface; +import mil.nga.wkb.geom.TIN; +import mil.nga.wkb.geom.Triangle; /** * JSON compatible object representation of a Geometry @@ -18,7 +36,196 @@ public class GeometryJSONCompatible { * @return geometry JSON object */ public static Object getJSONCompatibleGeometry(Geometry geometry) { - return null; // TODO + + Map jsonObject = new HashMap<>(); + + Object geometryObject = null; + + GeometryType geometryType = geometry.getGeometryType(); + switch (geometryType) { + case POINT: + geometryObject = getPoint((Point) geometry); + break; + case LINESTRING: + geometryObject = getLineString((LineString) geometry); + break; + case POLYGON: + geometryObject = getPolygon((Polygon) geometry); + break; + case MULTIPOINT: + geometryObject = getMultiPoint((MultiPoint) geometry); + break; + case MULTILINESTRING: + geometryObject = getMultiLineString((MultiLineString) geometry); + break; + case MULTIPOLYGON: + geometryObject = getMultiPolygon((MultiPolygon) geometry); + break; + case CIRCULARSTRING: + geometryObject = getLineString((CircularString) geometry); + break; + case COMPOUNDCURVE: + geometryObject = getCompoundCurve((CompoundCurve) geometry); + break; + case POLYHEDRALSURFACE: + geometryObject = getPolyhedralSurface((PolyhedralSurface) geometry); + break; + case TIN: + geometryObject = getPolyhedralSurface((TIN) geometry); + break; + case TRIANGLE: + geometryObject = getPolygon((Triangle) geometry); + break; + case GEOMETRYCOLLECTION: + List jsonGeoCollectionObject = new ArrayList<>(); + @SuppressWarnings("unchecked") + GeometryCollection geomCollection = (GeometryCollection) geometry; + List geometries = geomCollection.getGeometries(); + for (int i = 0; i < geometries.size(); i++) { + Geometry subGeometry = geometries.get(i); + jsonGeoCollectionObject + .add(getJSONCompatibleGeometry(subGeometry)); + } + geometryObject = jsonGeoCollectionObject; + break; + default: + } + + if (geometryObject != null) { + jsonObject.put(geometryType.getName(), geometryObject); + } + + return jsonObject; + } + + /** + * Get Point object + * + * @param point + * @return point object + */ + private static Object getPoint(Point point) { + Map jsonObject = new HashMap<>(); + jsonObject.put("x", point.getX()); + jsonObject.put("y", point.getY()); + if (point.hasZ()) { + jsonObject.put("z", point.getZ()); + } + if (point.hasM()) { + jsonObject.put("m", point.getM()); + } + return jsonObject; + } + + /** + * Get MultiPoint object + * + * @param multiPoint + * @return multi point object + */ + private static Object getMultiPoint(MultiPoint multiPoint) { + List jsonObject = new ArrayList<>(); + List points = multiPoint.getPoints(); + for (int i = 0; i < points.size(); i++) { + Point point = points.get(i); + jsonObject.add(getPoint(point)); + } + return jsonObject; + } + + /** + * Get LineString object + * + * @param lineString + * @return line string object + */ + private static Object getLineString(LineString lineString) { + List jsonObject = new ArrayList<>(); + for (Point point : lineString.getPoints()) { + jsonObject.add(getPoint(point)); + } + return jsonObject; + } + + /** + * Get MultiLineString object + * + * @param multiLineString + * @return multi line string object + */ + private static Object getMultiLineString(MultiLineString multiLineString) { + List jsonObject = new ArrayList<>(); + List lineStrings = multiLineString.getLineStrings(); + for (int i = 0; i < lineStrings.size(); i++) { + LineString lineString = lineStrings.get(i); + jsonObject.add(getLineString(lineString)); + } + return jsonObject; + } + + /** + * Get Polygon object + * + * @param polygon + * @return polygon object + */ + private static Object getPolygon(Polygon polygon) { + List jsonObject = new ArrayList<>(); + List rings = polygon.getRings(); + for (int i = 0; i < rings.size(); i++) { + LineString ring = rings.get(i); + jsonObject.add(getLineString(ring)); + } + return jsonObject; + } + + /** + * Get MultiPolygon object + * + * @param multiPolygon + * @return multi polygon object + */ + private static Object getMultiPolygon(MultiPolygon multiPolygon) { + List jsonObject = new ArrayList<>(); + List polygons = multiPolygon.getPolygons(); + for (int i = 0; i < polygons.size(); i++) { + Polygon polygon = polygons.get(i); + jsonObject.add(getPolygon(polygon)); + } + return jsonObject; + } + + /** + * Get CompoundCurve object + * + * @param compoundCurve + * @return compound curve object + */ + private static Object getCompoundCurve(CompoundCurve compoundCurve) { + List jsonObject = new ArrayList<>(); + List lineStrings = compoundCurve.getLineStrings(); + for (int i = 0; i < lineStrings.size(); i++) { + LineString lineString = lineStrings.get(i); + jsonObject.add(getLineString(lineString)); + } + return jsonObject; + } + + /** + * Get PolyhedralSurface object + * + * @param polyhedralSurface + * @return polyhedral surface object + */ + private static Object getPolyhedralSurface( + PolyhedralSurface polyhedralSurface) { + List jsonObject = new ArrayList<>(); + List polygons = polyhedralSurface.getPolygons(); + for (int i = 0; i < polygons.size(); i++) { + Polygon polygon = polygons.get(i); + jsonObject.add(getPolygon(polygon)); + } + return jsonObject; } } From a347f758e41616556e6cf6a3f7ff8399c8268d94 Mon Sep 17 00:00:00 2001 From: Brian Osborn Date: Mon, 18 Apr 2016 10:09:04 -0600 Subject: [PATCH 3/3] 1.0.2 readme and changelog --- CHANGELOG.md | 4 ++-- README.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53210ef..2476205 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,9 @@ Adheres to [Semantic Versioning](http://semver.org/). --- -## 1.0.2 (TBD) +## [1.0.2](https://github.com/ngageoint/geopackage-wkb-java/releases/tag/1.0.2) (04-18-2016) -* TBD +* Geometry to JSON Compatible object utility ## [1.0.1](https://github.com/ngageoint/geopackage-wkb-java/releases/tag/1.0.1) (11-20-2015) diff --git a/README.md b/README.md index 8a67e40..813c44b 100644 --- a/README.md +++ b/README.md @@ -38,12 +38,12 @@ View the latest [Javadoc](http://ngageoint.github.io/geopackage-wkb-java/docs/ap ### Installation ### -Pull from the [Maven Central Repository](http://search.maven.org/#artifactdetails|mil.nga|wkb|1.0.1|jar) (JAR, POM, Source, Javadoc) +Pull from the [Maven Central Repository](http://search.maven.org/#artifactdetails|mil.nga|wkb|1.0.2|jar) (JAR, POM, Source, Javadoc) mil.nga wkb - 1.0.1 + 1.0.2 ### Build ###