mil.nga.wkb.util.GeometryJSONCompatible Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wkb Show documentation
Show all versions of wkb Show documentation
Library for writing and reading Well-Known Binary Geometries to and from bytes
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.Curve;
import mil.nga.wkb.geom.CurvePolygon;
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
*
* @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) {
Map jsonObject = new HashMap<>();
Object geometryObject = getJSONCompatibleGeometryObject(geometry);
if (geometryObject != null) {
jsonObject
.put(geometry.getGeometryType().getName(), geometryObject);
}
return jsonObject;
}
/**
* Get a Geometry object that is JSON compatible
*
* @param geometry
* geometry
* @return geometry JSON object
*/
private static Object getJSONCompatibleGeometryObject(Geometry geometry) {
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 CURVEPOLYGON:
@SuppressWarnings("unchecked")
CurvePolygon curvePolygon = (CurvePolygon) geometry;
geometryObject = getCurvePolygon(curvePolygon);
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