/** * Verify with the remaining bytes that there are enough remaining to read * the provided amount * * @param bytesToRead * number of bytes to read */ private void verifyRemainingBytes(int bytesToRead) { if (nextByte + bytesToRead > bytes.length) { throw new SFException( "No more remaining bytes to read. Total Bytes: " + bytes.length + ", Bytes already read: " + nextByte + ", Attempted to read: " + bytesToRead); } }
/** * Convert the JSON tree to a typed GeoJSON object * * @param type * GeoJSON object type * @param tree * tree node * @return typed GeoJSON object */ private static <T extends GeoJsonObject> T toTypedGeoJsonObject( Class<T> type, JsonNode tree) { T geoJsonObject; try { geoJsonObject = mapper.treeToValue(tree, type); } catch (JsonProcessingException e) { throw new SFException( "Failed to convert node tree to GeoJSON object: " + tree, e); } return geoJsonObject; }
/** * Convert the GeoJSON object to a string value * * @param object * GeoJSON object * @return string value */ public static String toStringValue(GeoJsonObject object) { String stringValue = null; try { stringValue = mapper.writeValueAsString(object); } catch (JsonProcessingException e) { throw new SFException( "Failed to write GeoJSON object as a String: " + object.getType(), e); } return stringValue; }
/** * Convert the string content to a typed GeoJSON object * * @param type * GeoJSON object type * @param content * string content * @return typed GeoJSON object */ private static <T extends GeoJsonObject> T toTypedGeoJsonObject( Class<T> type, String content) { JsonNode tree; try { tree = mapper.readTree(content); } catch (Exception e) { throw new SFException("Failed to convert content to a node tree: " + content, e); } T typedGeoJsonObject = toTypedGeoJsonObject(type, tree); return typedGeoJsonObject; }
/** * Update the extended geometry type based upon the contained geometries */ public void updateGeometryType() { GeometryType geometryType = getCollectionType(); switch (geometryType) { case GEOMETRYCOLLECTION: case MULTICURVE: case MULTISURFACE: break; case MULTIPOINT: geometryType = GeometryType.GEOMETRYCOLLECTION; break; case MULTILINESTRING: geometryType = GeometryType.MULTICURVE; break; case MULTIPOLYGON: geometryType = GeometryType.MULTISURFACE; break; default: throw new SFException( "Unsupported extended geometry collection geometry type: " + geometryType); } this.geometryType = geometryType; }
/** * {@inheritDoc} */ @Override public void setPoints(List<Point> points) { super.setPoints(points); if (numPoints() != 2) { throw new SFException("A line must have exactly 2 points."); } }
throw new SFException("Unsupported Geometry Type: " + geometryType);
/** * {@inheritDoc} */ @Override public void setPoints(List<Point> points) { super.setPoints(points); if (!isEmpty()) { if (!isClosed()) { addPoint(points.get(0)); } if (numPoints() < 4) { throw new SFException( "A closed linear ring must have at least four points."); } } }
break; default: throw new SFException("Unexpected Curve Type: " + curveGeometryType); break; default: throw new SFException("Unexpected Curve Type: " + curveHoleGeometryType);
throw new SFException("Unsupported " + this.getClass().getSimpleName() + " Geometry Type: " + geometryType);
geometry = new GeometryCollection(simpleGeometryCollection); } else { throw new SFException("Unsupported Geometry type: " + simpleGeometry.getClass().getSimpleName());
throw new SFException("Unsupported " + this.getClass().getSimpleName() + " Geometry Type: " + geometryType);
throw new SFException("Unsupported " + this.getClass().getSimpleName() + " Geometry Type: " + geometryType);
throw new SFException("Unexpected Geometry Collection Type: " + geometryType);