Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
<version>1.15.0</version>
<version>1.16.1</version>
</dependency>

<dependency>
Expand Down
5 changes: 5 additions & 0 deletions presto-docs/src/main/sphinx/functions/geospatial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ Accessors
Returns an array of geometries in the specified collection. Returns a one-element array
if the input geometry is not a multi-geometry. Returns ``null`` if input geometry is empty.

For example, a MultiLineString will create an array of LineStrings. A GeometryCollection
will produce an un-flattened array of its constituents:
``GEOMETRYCOLLECTION(MULTIPOINT(0 0, 1 1), GEOMETRYCOLLECTION(MULTILINESTRING((2 2, 3 3))))``
would produce ``array[MULTIPOINT(0 0, 1 1), GEOMETRYCOLLECTION(MULTILINESTRING((2 2, 3 3)))]``.

.. function:: ST_NumPoints(Geometry) -> bigint

Returns the number of points in a geometry. This is an extension to the SQL/MM
Expand Down
5 changes: 5 additions & 0 deletions presto-geospatial-toolkit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
<artifactId>presto-array</artifactId>
</dependency>

<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-spi</artifactId>
</dependency>

<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@
import com.esri.core.geometry.ogc.OGCGeometry;
import com.esri.core.geometry.ogc.OGCPoint;
import com.esri.core.geometry.ogc.OGCPolygon;
import com.facebook.presto.spi.PrestoException;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.CoordinateSequence;
import org.locationtech.jts.geom.CoordinateSequenceFactory;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.impl.PackedCoordinateSequenceFactory;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import org.locationtech.jts.io.WKTWriter;

import java.util.HashSet;
import java.util.Set;

import static com.facebook.presto.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT;

public final class GeometryUtils
{
private static final CoordinateSequenceFactory COORDINATE_SEQUENCE_FACTORY = new PackedCoordinateSequenceFactory();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, i see, you are making them private in the next commit. Could you please move it to the commit before?

Expand Down Expand Up @@ -220,13 +227,53 @@ public static boolean isPointOrRectangle(OGCGeometry ogcGeometry, Envelope envel
return true;
}

public static org.locationtech.jts.geom.Point makeJtsEmptyPoint()
public static org.locationtech.jts.geom.Geometry jtsGeometryFromWkt(String wkt)
{
try {
return new WKTReader(GEOMETRY_FACTORY).read(wkt);
}
catch (ParseException | IllegalArgumentException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKT: " + e.getMessage(), e);
}
}

public static String wktFromJtsGeometry(org.locationtech.jts.geom.Geometry geometry)
{
return new WKTWriter().write(geometry);
}

public static org.locationtech.jts.geom.Point createJtsEmptyPoint()
{
return GEOMETRY_FACTORY.createPoint();
}

public static org.locationtech.jts.geom.Point makeJtsPoint(Coordinate coordinate)
public static org.locationtech.jts.geom.Point createJtsPoint(Coordinate coordinate)
{
return GEOMETRY_FACTORY.createPoint(coordinate);
}

public static org.locationtech.jts.geom.Point createJtsPoint(double x, double y)
{
return createJtsPoint(new Coordinate(x, y));
}

public static org.locationtech.jts.geom.MultiPoint createJtsMultiPoint(CoordinateSequence coordinates)
{
return GEOMETRY_FACTORY.createMultiPoint(coordinates);
}

public static org.locationtech.jts.geom.Geometry createJtsEmptyLineString()
{
return GEOMETRY_FACTORY.createLineString();
}

public static org.locationtech.jts.geom.Geometry createJtsLineString(CoordinateSequence coordinates)
{
return GEOMETRY_FACTORY.createLineString(coordinates);
}

public static org.locationtech.jts.geom.Geometry createJtsEmptyPolygon()
{
return GEOMETRY_FACTORY.createPolygon();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
import static java.lang.Math.toIntExact;
import static java.util.Objects.requireNonNull;

public class GeometrySerde
public class EsriGeometrySerde
{
private GeometrySerde() {}
private EsriGeometrySerde() {}

public static Slice serialize(OGCGeometry input)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ private static void writeGeometry(Geometry geometry, DynamicSliceOutput output)
writeMultiPoint((MultiPoint) geometry, output);
break;
case "LineString":
case "LinearRing":
// LinearRings are a subclass of LineString
writePolyline(geometry, output, false);
break;
case "MultiLineString":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
import static com.facebook.presto.geospatial.serde.BenchmarkGeometrySerializationData.POINT;
import static com.facebook.presto.geospatial.serde.BenchmarkGeometrySerializationData.POLYGON;
import static com.facebook.presto.geospatial.serde.BenchmarkGeometrySerializationData.readResource;
import static com.facebook.presto.geospatial.serde.GeometrySerde.deserialize;
import static com.facebook.presto.geospatial.serde.GeometrySerde.deserializeEnvelope;
import static com.facebook.presto.geospatial.serde.GeometrySerde.serialize;
import static com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserialize;
import static com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope;
import static com.facebook.presto.geospatial.serde.EsriGeometrySerde.serialize;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.openjdk.jmh.annotations.Mode.Throughput;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import org.locationtech.jts.io.WKTReader;
import org.testng.annotations.Test;

import static com.facebook.presto.geospatial.serde.GeometrySerde.createFromEsriGeometry;
import static com.facebook.presto.geospatial.serde.GeometrySerde.deserialize;
import static com.facebook.presto.geospatial.serde.GeometrySerde.deserializeEnvelope;
import static com.facebook.presto.geospatial.serde.GeometrySerde.deserializeType;
import static com.facebook.presto.geospatial.serde.GeometrySerde.serialize;
import static com.facebook.presto.geospatial.serde.EsriGeometrySerde.createFromEsriGeometry;
import static com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserialize;
import static com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeEnvelope;
import static com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserializeType;
import static com.facebook.presto.geospatial.serde.EsriGeometrySerde.serialize;
import static com.facebook.presto.geospatial.serde.GeometrySerializationType.ENVELOPE;
import static com.facebook.presto.geospatial.serde.GeometrySerializationType.GEOMETRY_COLLECTION;
import static com.facebook.presto.geospatial.serde.GeometrySerializationType.LINE_STRING;
Expand Down Expand Up @@ -208,9 +208,9 @@ private static void testCrossSerialization(String wkt)
OGCGeometry esriGeometry = OGCGeometry.fromText(wkt);

Slice jtsSerialized = JtsGeometrySerde.serialize(jtsGeometry);
Slice esriSerialized = GeometrySerde.serialize(esriGeometry);
Slice esriSerialized = EsriGeometrySerde.serialize(esriGeometry);

OGCGeometry esriFromJts = GeometrySerde.deserialize(jtsSerialized);
OGCGeometry esriFromJts = EsriGeometrySerde.deserialize(jtsSerialized);
Geometry jtsFromEsri = JtsGeometrySerde.deserialize(esriSerialized);
assertGeometryEquals(esriFromJts, esriGeometry);
assertGeometryEquals(jtsFromEsri, jtsGeometry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import static com.facebook.presto.geospatial.GeometryUtils.getEnvelope;
import static com.facebook.presto.geospatial.GeometryUtils.getPointCount;
import static com.facebook.presto.geospatial.GeometryUtils.isPointOrRectangle;
import static com.facebook.presto.geospatial.serde.GeometrySerde.deserialize;
import static com.facebook.presto.geospatial.serde.GeometrySerde.serialize;
import static com.facebook.presto.geospatial.serde.EsriGeometrySerde.deserialize;
import static com.facebook.presto.geospatial.serde.EsriGeometrySerde.serialize;
import static com.facebook.presto.plugin.geospatial.BingTile.MAX_ZOOM_LEVEL;
import static com.facebook.presto.plugin.geospatial.GeometryType.GEOMETRY_TYPE_NAME;
import static com.facebook.presto.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT;
Expand Down
Loading