use of org.n52.svalbard.coding.json.GeoJSONDecodingException in project arctic-sea by 52North.
the class GeoJSONDecoder method decodeCRS.
protected GeometryFactory decodeCRS(JsonNode node, GeometryFactory factory) throws GeoJSONDecodingException {
if (!node.path(JSONConstants.CRS).hasNonNull(JSONConstants.TYPE)) {
throw new GeoJSONDecodingException("Missing CRS type");
}
String type = node.path(JSONConstants.CRS).path(JSONConstants.TYPE).textValue();
JsonNode properties = node.path(JSONConstants.CRS).path(JSONConstants.PROPERTIES);
switch(type) {
case JSONConstants.NAME:
return decodeNamedCRS(properties, factory);
case JSONConstants.LINK:
return decodeLinkedCRS(properties, factory);
default:
throw new GeoJSONDecodingException("Unknown CRS type: " + type);
}
}
use of org.n52.svalbard.coding.json.GeoJSONDecodingException in project arctic-sea by 52North.
the class GeoJSONDecoder method decodeCoordinate.
protected Coordinate decodeCoordinate(JsonNode node) throws GeoJSONDecodingException {
if (!node.isArray()) {
throw new GeoJSONDecodingException(EXPECTED_ARRAY);
}
final int dim = node.size();
if (dim < DIM_2D) {
throw new GeoJSONDecodingException("coordinates may have at least 2 dimensions");
}
if (dim > DIM_3D) {
throw new GeoJSONDecodingException("coordinates may have at most 3 dimensions");
}
final Coordinate coordinate = new Coordinate();
for (int i = 0; i < dim; ++i) {
if (node.get(i).isNumber()) {
coordinate.setOrdinate(i, node.get(i).doubleValue());
} else {
throw new GeoJSONDecodingException("coordinate index " + i + " has to be a number");
}
}
return coordinate;
}
use of org.n52.svalbard.coding.json.GeoJSONDecodingException in project arctic-sea by 52North.
the class GeoJSONDecoder method decodePolygonCoordinates.
protected Polygon decodePolygonCoordinates(JsonNode coordinates, GeometryFactory fac) throws GeoJSONDecodingException {
if (!coordinates.isArray()) {
throw new GeoJSONDecodingException(EXPECTED_ARRAY);
}
if (coordinates.size() < 1) {
throw new GeoJSONDecodingException("missing polygon shell");
}
LinearRing shell = fac.createLinearRing(decodeCoordinates(coordinates.get(0)));
LinearRing[] holes = new LinearRing[coordinates.size() - 1];
for (int i = 1; i < coordinates.size(); ++i) {
holes[i - 1] = fac.createLinearRing(decodeCoordinates(coordinates.get(i)));
}
return fac.createPolygon(shell, holes);
}
use of org.n52.svalbard.coding.json.GeoJSONDecodingException in project arctic-sea by 52North.
the class GeoJSONDecoder method decodeGeometry.
protected Geometry decodeGeometry(Object o, GeometryFactory parentFactory) throws GeoJSONDecodingException {
if (!(o instanceof JsonNode)) {
throw new GeoJSONDecodingException("Cannot decode " + o);
}
final JsonNode node = (JsonNode) o;
final String type = getType(node);
final GeometryFactory factory = getGeometryFactory(node, parentFactory);
switch(type) {
case JSONConstants.POINT:
return decodePoint(node, factory);
case JSONConstants.MULTI_POINT:
return decodeMultiPoint(node, factory);
case JSONConstants.LINE_STRING:
return decodeLineString(node, factory);
case JSONConstants.MULTI_LINE_STRING:
return decodeMultiLineString(node, factory);
case JSONConstants.POLYGON:
return decodePolygon(node, factory);
case JSONConstants.MULTI_POLYGON:
return decodeMultiPolygon(node, factory);
case JSONConstants.GEOMETRY_COLLECTION:
return decodeGeometryCollection(node, factory);
default:
throw new GeoJSONDecodingException("Unkown geometry type: " + type);
}
}
use of org.n52.svalbard.coding.json.GeoJSONDecodingException in project arctic-sea by 52North.
the class GeoJSONDecoder method decodeGeometryCollection.
protected GeometryCollection decodeGeometryCollection(JsonNode node, GeometryFactory fac) throws GeoJSONDecodingException {
final JsonNode geometries = node.path(JSONConstants.GEOMETRIES);
if (!geometries.isArray()) {
throw new GeoJSONDecodingException("expected 'geometries' array");
}
Geometry[] geoms = new Geometry[geometries.size()];
for (int i = 0; i < geometries.size(); ++i) {
geoms[i] = decodeGeometry(geometries.get(i), fac);
}
return fac.createGeometryCollection(geoms);
}
Aggregations