@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)); }
if (!multiType && ((MultiPoint) geometry).getPointCount() <= 1) { if (geometry.isEmpty()) { return new OGCPoint(new Point(), null);
public int numGeometries() { return multiPoint.getPointCount(); }
public int numGeometries() { return multiPoint.getPointCount(); }
void appendMultiPoint_(int dstGeom, MultiPoint multi_point) { // m_vertices->reserve_rounded(m_vertices->get_point_count() + // multi_point.get_point_count());//ensure reallocation happens by // blocks so that already allocated vertices do not get reallocated. m_vertices_mp.add(multi_point, 0, multi_point.getPointCount()); m_xy_stream = (AttributeStreamOfDbl) m_vertices .getAttributeStreamRef(VertexDescription.Semantics.POSITION); int path = insertPath(dstGeom, -1); for (int ivertex = 0, iend = multi_point.getPointCount(); ivertex < iend; ivertex++) { insertVertex_(path, -1, null); } }
void appendMultiPoint_(int dstGeom, MultiPoint multi_point) { // m_vertices->reserve_rounded(m_vertices->get_point_count() + // multi_point.get_point_count());//ensure reallocation happens by // blocks so that already allocated vertices do not get reallocated. m_vertices_mp.add(multi_point, 0, multi_point.getPointCount()); m_xy_stream = (AttributeStreamOfDbl) m_vertices .getAttributeStreamRef(VertexDescription.Semantics.POSITION); int path = insertPath(dstGeom, -1); for (int ivertex = 0, iend = multi_point.getPointCount(); ivertex < iend; ivertex++) { insertVertex_(path, -1, null); } }
private static int quickTest2DMultiPointPoint(MultiPoint geomA, Point2D ptB, double tolerance) { // TODO: Add Geometry accelerator. (RasterizedGeometry + kd-tree or // alike) for (int i = 0, n = geomA.getPointCount(); i < n; i++) { Point2D ptA; ptA = geomA.getXY(i); int res = quickTest2DPointPoint(ptA, ptB, tolerance); if (res != (int) Relation.Disjoint) { if ((res & (int) Relation.Within) != 0 && n != 1) { // _ASSERT(res & (int)Relation.Contains); return (int) Relation.Contains; } return res; } } return (int) Relation.Disjoint; }
private static int quickTest2DMultiPointPoint(MultiPoint geomA, Point2D ptB, double tolerance) { // TODO: Add Geometry accelerator. (RasterizedGeometry + kd-tree or // alike) for (int i = 0, n = geomA.getPointCount(); i < n; i++) { Point2D ptA; ptA = geomA.getXY(i); int res = quickTest2DPointPoint(ptA, ptB, tolerance); if (res != (int) Relation.Disjoint) { if ((res & (int) Relation.Within) != 0 && n != 1) { // _ASSERT(res & (int)Relation.Contains); return (int) Relation.Contains; } return res; } } return (int) Relation.Disjoint; }
static boolean multiPointDisjointPointImpl_(MultiPoint multipoint_a, Point2D pt_b, double tolerance, ProgressTracker progressTracker) { Point2D pt_a = new Point2D(); double tolerance_sq = tolerance * tolerance; for (int i = 0; i < multipoint_a.getPointCount(); i++) { multipoint_a.getXY(i, pt_a); if (Point2D.sqrDistance(pt_a, pt_b) <= tolerance_sq) return false; } return true; }
static boolean multiPointDisjointPointImpl_(MultiPoint multipoint_a, Point2D pt_b, double tolerance, ProgressTracker progressTracker) { Point2D pt_a = new Point2D(); double tolerance_sq = tolerance * tolerance; for (int i = 0; i < multipoint_a.getPointCount(); i++) { multipoint_a.getXY(i, pt_a); if (Point2D.sqrDistance(pt_a, pt_b) <= tolerance_sq) return false; } return true; }
private static Point2D computePointsCentroid(MultiPoint multiPoint) { double xSum = 0; double ySum = 0; int pointCount = multiPoint.getPointCount(); Point2D point2D = new Point2D(); for (int i = 0; i < pointCount; i++) { multiPoint.getXY(i, point2D); xSum += point2D.x; ySum += point2D.y; } return new Point2D(xSum / pointCount, ySum / pointCount); }
private static Point2D computePointsCentroid(MultiPoint multiPoint) { double xSum = 0; double ySum = 0; int pointCount = multiPoint.getPointCount(); Point2D point2D = new Point2D(); for (int i = 0; i < pointCount; i++) { multiPoint.getXY(i, point2D); xSum += point2D.x; ySum += point2D.y; } return new Point2D(xSum / pointCount, ySum / pointCount); }
private static boolean multiPointContainsMultiPointBrute_( MultiPoint multipoint_a, MultiPoint multipoint_b, double tolerance) { double tolerance_sq = tolerance * tolerance; Point2D pt_a = new Point2D(); Point2D pt_b = new Point2D(); for (int i = 0; i < multipoint_b.getPointCount(); i++) { multipoint_b.getXY(i, pt_b); boolean b_contained = false; for (int j = 0; j < multipoint_a.getPointCount(); j++) { multipoint_a.getXY(j, pt_a); if (Point2D.sqrDistance(pt_a, pt_b) <= tolerance_sq) { b_contained = true; break; } } if (!b_contained) return false; } return true; }
static Geometry pointMinusMultiPoint_(Point point, MultiPoint multi_point, double tolerance, ProgressTracker progress_tracker) { MultiPointImpl multipointImpl = (MultiPointImpl) (multi_point ._getImpl()); AttributeStreamOfDbl position = (AttributeStreamOfDbl) multipointImpl .getAttributeStreamRef(VertexDescription.Semantics.POSITION); int point_count = multi_point.getPointCount(); Point2D point2D = point.getXY(); Point2D pt = new Point2D(); double tolerance_cluster = tolerance * Math.sqrt(2.0) * 1.00001; double tolerance_cluster_sq = tolerance_cluster * tolerance_cluster; for (int i = 0; i < point_count; i++) { position.read(2 * i, pt); double sqr_dist = Point2D.sqrDistance(pt, point2D); if (sqr_dist <= tolerance_cluster_sq) return point.createInstance();// return an empty point. } return point;// return the input point }
static Geometry pointMinusMultiPoint_(Point point, MultiPoint multi_point, double tolerance, ProgressTracker progress_tracker) { MultiPointImpl multipointImpl = (MultiPointImpl) (multi_point ._getImpl()); AttributeStreamOfDbl position = (AttributeStreamOfDbl) multipointImpl .getAttributeStreamRef(VertexDescription.Semantics.POSITION); int point_count = multi_point.getPointCount(); Point2D point2D = point.getXY(); Point2D pt = new Point2D(); double tolerance_cluster = tolerance * Math.sqrt(2.0) * 1.00001; double tolerance_cluster_sq = tolerance_cluster * tolerance_cluster; for (int i = 0; i < point_count; i++) { position.read(2 * i, pt); double sqr_dist = Point2D.sqrDistance(pt, point2D); if (sqr_dist <= tolerance_cluster_sq) return point.createInstance();// return an empty point. } return point;// return the input point }
static Geometry _denormalizeGeometry(Geometry geom, Geometry geomA, Geometry geomB) { Geometry.Type gtA = geomA.getType(); Geometry.Type gtB = geomB.getType(); Geometry.Type gt = geom.getType(); if (gt == Geometry.Type.MultiPoint) { if (gtA == Geometry.Type.Point || gtB == Geometry.Type.Point) { MultiPoint mp = (MultiPoint) geom; if (mp.getPointCount() <= 1) { Point pt = new Point(geom.getDescription()); if (!mp.isEmpty()) mp.getPointByVal(0, pt); return (Geometry) pt; } } } return geom; }
static Geometry _denormalizeGeometry(Geometry geom, Geometry geomA, Geometry geomB) { Geometry.Type gtA = geomA.getType(); Geometry.Type gtB = geomB.getType(); Geometry.Type gt = geom.getType(); if (gt == Geometry.Type.MultiPoint) { if (gtA == Geometry.Type.Point || gtB == Geometry.Type.Point) { MultiPoint mp = (MultiPoint) geom; if (mp.getPointCount() <= 1) { Point pt = new Point(geom.getDescription()); if (!mp.isEmpty()) mp.getPointByVal(0, pt); return (Geometry) pt; } } } return geom; }
private static boolean multiPointDisjointEnvelope_(MultiPoint multipoint_a, Envelope envelope_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); multipoint_a.queryEnvelope2D(env_a); envelope_b.queryEnvelope2D(env_b); if (envelopeInfContainsEnvelope_(env_b, env_a, tolerance)) return false; Envelope2D env_b_inflated = new Envelope2D(); env_b_inflated.setCoords(env_b); env_b_inflated.inflate(tolerance, tolerance); Point2D pt_a = new Point2D(); for (int i = 0; i < multipoint_a.getPointCount(); i++) { multipoint_a.getXY(i, pt_a); if (!env_b_inflated.contains(pt_a)) continue; return false; } return true; }
private static boolean multiPointDisjointEnvelope_(MultiPoint multipoint_a, Envelope envelope_b, double tolerance, ProgressTracker progress_tracker) { Envelope2D env_a = new Envelope2D(), env_b = new Envelope2D(); multipoint_a.queryEnvelope2D(env_a); envelope_b.queryEnvelope2D(env_b); if (envelopeInfContainsEnvelope_(env_b, env_a, tolerance)) return false; Envelope2D env_b_inflated = new Envelope2D(); env_b_inflated.setCoords(env_b); env_b_inflated.inflate(tolerance, tolerance); Point2D pt_a = new Point2D(); for (int i = 0; i < multipoint_a.getPointCount(); i++) { multipoint_a.getXY(i, pt_a); if (!env_b_inflated.contains(pt_a)) continue; return false; } return true; }
private static boolean polylineTouchesPolyline_(Polyline polyline_a, Polyline polyline_b, double tolerance, ProgressTracker progress_tracker) { // Quick rasterize test to see whether the the geometries are disjoint. if (tryRasterizedContainsOrDisjoint_(polyline_a, polyline_b, tolerance, false) == Relation.disjoint) return false; AttributeStreamOfDbl intersections = new AttributeStreamOfDbl(0); int dim = linearPathIntersectsLinearPathMaxDim_(polyline_a, polyline_b, tolerance, intersections); if (dim != 0) return false; MultiPoint intersection = new MultiPoint(); for (int i = 0; i < intersections.size(); i += 2) { double x = intersections.read(i); double y = intersections.read(i + 1); intersection.add(x, y); } MultiPoint boundary_a_b = (MultiPoint) (polyline_a.getBoundary()); MultiPoint boundary_b = (MultiPoint) (polyline_b.getBoundary()); boundary_a_b.add(boundary_b, 0, boundary_b.getPointCount()); return multiPointContainsMultiPointBrute_(boundary_a_b, intersection, tolerance); }