This is an automated email from the ASF dual-hosted git repository. amanin pushed a commit to branch refactor/sql-store in repository https://gitbox.apache.org/repos/asf/sis.git
commit a97b70fe3888966e192e22e63740839a9dfab437 Author: Alexis Manin <[email protected]> AuthorDate: Wed Nov 6 16:44:00 2019 +0100 feat(Feature): add minor functionality to convert arbitrary geometry to polygon --- .../src/main/java/org/apache/sis/internal/feature/ESRI.java | 9 ++++++++- .../java/org/apache/sis/internal/feature/Geometries.java | 10 +++++++++- .../src/main/java/org/apache/sis/internal/feature/JTS.java | 12 +++++++++++- .../main/java/org/apache/sis/internal/feature/Java2D.java | 7 ++++++- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/ESRI.java b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/ESRI.java index 9659549..c01dd00 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/ESRI.java +++ b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/ESRI.java @@ -16,6 +16,7 @@ */ package org.apache.sis.internal.feature; +import java.nio.ByteBuffer; import java.util.Iterator; import org.apache.sis.geometry.GeneralEnvelope; @@ -227,10 +228,16 @@ add: for (;;) { * Parses the given WKT. */ @Override - public Object parseWKT(final String wkt) { + public Geometry parseWKT(final String wkt) { return OperatorImportFromWkt.local().execute(WktImportFlags.wktImportDefaults, Geometry.Type.Unknown, wkt, null); } + @Override + public Geometry parseWKB(byte[] source) { + final OperatorImportFromWkb op = OperatorImportFromWkb.local(); + return op.execute(WkbImportFlags.wkbImportDefaults, Geometry.Type.Unknown, ByteBuffer.wrap(source), null); + } + /** * If the given object is an ESRI geometry, returns its WKT representation. */ diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java index 3f78d61..9a17aed 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java +++ b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Geometries.java @@ -281,7 +281,15 @@ public abstract class Geometries<G> { * @return the geometry object for the given WKT. * @throws Exception if the WKT can not be parsed. The exception sub-class depends on the implementation. */ - public abstract Object parseWKT(String wkt) throws Exception; + public abstract G parseWKT(String wkt) throws Exception; + + /** + * Try to read given bytes as a WKB encoded geometry. + * @param source Contains the WKB data. Must not be null. + * @return Decoded Geometry, never null. + * @throws RuntimeException If given byte array is not a consistent WKB, or denote some unsupported geometry type. + */ + public abstract G parseWKB(byte[] source); /** * Creates a two-dimensional point from the given coordinate. If the CRS is geographic, then the diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java index 34c5ba0..28e0fbe 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java +++ b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/JTS.java @@ -41,6 +41,7 @@ import org.locationtech.jts.geom.MultiPolygon; import org.locationtech.jts.geom.Point; import org.locationtech.jts.geom.Polygon; import org.locationtech.jts.io.ParseException; +import org.locationtech.jts.io.WKBReader; import org.locationtech.jts.io.WKTReader; @@ -77,10 +78,19 @@ final class JTS extends Geometries<Geometry> { * @throws ParseException if the WKT can not be parsed. */ @Override - public Object parseWKT(final String wkt) throws ParseException { + public Geometry parseWKT(final String wkt) throws ParseException { return new WKTReader(factory).read(wkt); } + @Override + public Geometry parseWKB(byte[] source) { + try { + return new WKBReader(factory).read(source); + } catch (ParseException e) { + throw new BackingStoreException("Cannot decode given bytes as a WKB geometry", e); + } + } + /** * If the given object is a JTS geometry, returns its WKT representation. */ diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Java2D.java b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Java2D.java index 35f9a04..7f03643 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Java2D.java +++ b/core/sis-feature/src/main/java/org/apache/sis/internal/feature/Java2D.java @@ -287,7 +287,12 @@ add: for (;;) { * Parses the given WKT. */ @Override - public Object parseWKT(final String wkt) { + public Shape parseWKT(final String wkt) { + throw unsupported(2); + } + + @Override + public Shape parseWKB(byte[] source) { throw unsupported(2); }
