private void testEnvelopeSerialization(Envelope envelope) { assertEquals(deserialize(serialize(envelope)), createFromEsriGeometry(envelope, null)); assertEquals(deserializeEnvelope(serialize(envelope)), envelope); assertEquals(JtsGeometrySerde.serialize(JtsGeometrySerde.deserialize(serialize(envelope))), serialize(createFromEsriGeometry(envelope, null))); }
@Override public void output() { if (nonNullCount.value > 0) { out.isSet = 1; java.util.List<com.esri.core.geometry.Geometry> tmp = (java.util.ArrayList<com.esri.core.geometry.Geometry>) value.obj; com.esri.core.geometry.SpatialReference spatialRef = null; if (srid.value != 0){ spatialRef = com.esri.core.geometry.SpatialReference.create(4326); } com.esri.core.geometry.Geometry[] geomArr = (com.esri.core.geometry.Geometry[]) tmp.toArray(new com.esri.core.geometry.Geometry[0]); com.esri.core.geometry.Geometry geom = com.esri.core.geometry.GeometryEngine.union(geomArr, spatialRef); com.esri.core.geometry.ogc.OGCGeometry unionGeom = com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry(geom, spatialRef); java.nio.ByteBuffer unionGeomBytes = unionGeom.asBinary(); int outputSize = unionGeomBytes.remaining(); buf = out.buffer = buf.reallocIfNeeded(outputSize); out.start = 0; out.end = outputSize; buf.setBytes(0, unionGeomBytes); } else { out.isSet = 0; } }
@Description("Returns a Geometry type Point object with the given coordinate values") @ScalarFunction("ST_Point") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stPoint(@SqlType(DOUBLE) double x, @SqlType(DOUBLE) double y) { OGCGeometry geometry = createFromEsriGeometry(new Point(x, y), null); return serialize(geometry); }
OGCGeometry unionedGeometry = createFromEsriGeometry(operator.next(), null); if (unionedGeometry != null) { outputs.add(unionedGeometry);
@SqlNullable @Description("Returns the first point of a LINESTRING geometry as a Point") @ScalarFunction("ST_StartPoint") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stStartPoint(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); validateType("ST_StartPoint", geometry, EnumSet.of(LINE_STRING)); if (geometry.isEmpty()) { return null; } MultiPath lines = (MultiPath) geometry.getEsriGeometry(); SpatialReference reference = geometry.getEsriSpatialReference(); return serialize(createFromEsriGeometry(lines.getPoint(0), reference)); }
@SqlNullable @Description("Returns the last point of a LINESTRING geometry as a Point") @ScalarFunction("ST_EndPoint") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stEndPoint(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); validateType("ST_EndPoint", geometry, EnumSet.of(LINE_STRING)); if (geometry.isEmpty()) { return null; } MultiPath lines = (MultiPath) geometry.getEsriGeometry(); SpatialReference reference = geometry.getEsriSpatialReference(); return serialize(createFromEsriGeometry(lines.getPoint(lines.getPointCount() - 1), reference)); }
@SqlNullable @Description("Returns the lower left and upper right corners of bounding rectangular polygon of a Geometry") @ScalarFunction("ST_EnvelopeAsPts") @SqlType("array(" + GEOMETRY_TYPE_NAME + ")") public static Block stEnvelopeAsPts(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { Envelope envelope = deserializeEnvelope(input); if (envelope == null) { return null; } BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, 2); Point lowerLeftCorner = new Point(envelope.getXMin(), envelope.getYMin()); Point upperRightCorner = new Point(envelope.getXMax(), envelope.getYMax()); GEOMETRY.writeSlice(blockBuilder, serialize(createFromEsriGeometry(lowerLeftCorner, null, false))); GEOMETRY.writeSlice(blockBuilder, serialize(createFromEsriGeometry(upperRightCorner, null, false))); return blockBuilder.build(); }
@SqlNullable @Description("Returns a multi-point geometry formed from input points") @ScalarFunction("ST_MultiPoint") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stMultiPoint(@SqlType("array(" + GEOMETRY_TYPE_NAME + ")") Block input) { MultiPoint multipoint = new MultiPoint(); for (int i = 0; i < input.getPositionCount(); i++) { if (input.isNull(i)) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: null at index %s", i + 1)); } Slice slice = GEOMETRY.getSlice(input, i); OGCGeometry geometry = deserialize(slice); if (!(geometry instanceof OGCPoint)) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: geometry is not a point: %s at index %s", geometry.geometryType(), i + 1)); } OGCPoint point = (OGCPoint) geometry; if (point.isEmpty()) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Invalid input to ST_MultiPoint: empty point at index %s", i + 1)); } multipoint.add(point.X(), point.Y()); } if (multipoint.getPointCount() == 0) { return null; } return serialize(createFromEsriGeometry(multipoint, null, true)); }
return serialize(createFromEsriGeometry(new Point(), geometry.getEsriSpatialReference())); throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Unexpected geometry type: " + geometryType); return serialize(createFromEsriGeometry(centroid, geometry.getEsriSpatialReference()));
@Description("Returns the Geometry value that represents the point set intersection of two Geometries") @ScalarFunction("ST_Intersection") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stIntersection(@SqlType(GEOMETRY_TYPE_NAME) Slice left, @SqlType(GEOMETRY_TYPE_NAME) Slice right) { if (deserializeType(left) == GeometrySerializationType.ENVELOPE && deserializeType(right) == GeometrySerializationType.ENVELOPE) { Envelope leftEnvelope = deserializeEnvelope(left); Envelope rightEnvelope = deserializeEnvelope(right); // Envelope#intersect updates leftEnvelope to the intersection of the two envelopes if (!leftEnvelope.intersect(rightEnvelope)) { return EMPTY_POLYGON; } Envelope intersection = leftEnvelope; if (intersection.getXMin() == intersection.getXMax()) { if (intersection.getYMin() == intersection.getYMax()) { return serialize(createFromEsriGeometry(new Point(intersection.getXMin(), intersection.getXMax()), null)); } return serialize(createFromEsriGeometry(new Polyline(new Point(intersection.getXMin(), intersection.getYMin()), new Point(intersection.getXMin(), intersection.getYMax())), null)); } if (intersection.getYMin() == intersection.getYMax()) { return serialize(createFromEsriGeometry(new Polyline(new Point(intersection.getXMin(), intersection.getYMin()), new Point(intersection.getXMax(), intersection.getYMin())), null)); } return serialize(intersection); } OGCGeometry leftGeometry = deserialize(left); OGCGeometry rightGeometry = deserialize(right); verifySameSpatialReference(leftGeometry, rightGeometry); return serialize(leftGeometry.intersection(rightGeometry)); }
com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry(esriGeom, sr); geomBytes = tGeom.asBinary();
@Override public OGCGeometry boundary() { Polyline polyline = new Polyline(); polyline.add(polygon, true); // adds reversed path return (OGCMultiCurve) OGCGeometry.createFromEsriGeometry(polyline, esriSR, true); }
@Override public OGCMultiCurve boundary() { Polyline polyline = new Polyline(); polyline.add(polygon, true); // adds reversed path return (OGCMultiCurve) OGCGeometry.createFromEsriGeometry(polyline, esriSR, true); }
public OGCGeometry centroid() { OperatorCentroid2D op = (OperatorCentroid2D) OperatorFactoryLocal.getInstance() .getOperator(Operator.Type.Centroid2D); Point2D centroid = op.execute(getEsriGeometry(), null); if (centroid == null) { return OGCGeometry.createFromEsriGeometry(new Point(), esriSR); } return OGCGeometry.createFromEsriGeometry(new Point(centroid), esriSR); }
@Override public OGCGeometry boundary() { OperatorBoundary op = (OperatorBoundary) OperatorFactoryLocal .getInstance().getOperator(Operator.Type.Boundary); Geometry g = op.execute(polyline, null); return OGCGeometry.createFromEsriGeometry(g, esriSR, true); }
public OGCGeometry symDifference(OGCGeometry another) { if (another.geometryType() == OGCConcreteGeometryCollection.TYPE) { // TODO throw new UnsupportedOperationException(); } com.esri.core.geometry.Geometry geom1 = getEsriGeometry(); com.esri.core.geometry.Geometry geom2 = another.getEsriGeometry(); return createFromEsriGeometry( com.esri.core.geometry.GeometryEngine.symmetricDifference( geom1, geom2, getEsriSpatialReference()), esriSR); }
@Override public OGCPoint pointN(int n) { int nn; if (n == multiPath.getPathSize(0)) { nn = multiPath.getPathStart(0); } else nn = multiPath.getPathStart(0) + n; return (OGCPoint) OGCGeometry.createFromEsriGeometry( multiPath.getPoint(nn), esriSR); } }
public static OGCGeometry fromEsriShape(ByteBuffer buffer) { OperatorImportFromESRIShape op = (OperatorImportFromESRIShape) OperatorFactoryLocal .getInstance().getOperator(Operator.Type.ImportFromESRIShape); Geometry g = op.execute(0, Geometry.Type.Unknown, buffer); return OGCGeometry.createFromEsriGeometry(g, SpatialReference.create(4326)); }
public static OGCGeometry fromJson(String string) { MapGeometry mapGeom = GeometryEngine.jsonToGeometry(JsonParserReader.createFromString(string)); return OGCGeometry.createFromEsriGeometry(mapGeom.getGeometry(), mapGeom.getSpatialReference()); }
public OGCGeometry difference(OGCGeometry another) { if (another.geometryType() == OGCConcreteGeometryCollection.TYPE) { return (new OGCConcreteGeometryCollection(this, esriSR)).difference(another); } com.esri.core.geometry.Geometry geom1 = getEsriGeometry(); com.esri.core.geometry.Geometry geom2 = another.getEsriGeometry(); return createFromEsriGeometry( com.esri.core.geometry.GeometryEngine.difference(geom1, geom2, getEsriSpatialReference()), esriSR); }