@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); return new OGCPoint(((MultiPoint) geometry).getPoint(0), null);
public OGCMultiPoint(Point startPoint, SpatialReference sr) { multiPoint = new MultiPoint(); multiPoint.add((Point) startPoint); esriSR = sr; }
static Geometry multiPointSymDiffPoint_(MultiPoint multi_point, Point 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(); MultiPoint new_multipoint = (MultiPoint) (multi_point.createInstance()); double tolerance_cluster = tolerance * Math.sqrt(2.0) * 1.00001; multi_point.queryEnvelope2D(env); env.inflate(tolerance_cluster, tolerance_cluster); new_multipoint.add(multi_point, 0, point_count); new_multipoint.add(point); } else { for (int i = 0; i < point_count; i++) { if (!covered[i]) new_multipoint.add(multi_point, i, i + 1); new_multipoint.add(multi_point, 0, point_count); new_multipoint.add(point);
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 Geometry multiPointMinusEnvelope_(MultiPoint multi_point, Envelope envelope, double tolerance, ProgressTracker progress_tracker) { Envelope2D env = new Envelope2D(); envelope.queryEnvelope2D(env); env.inflate(tolerance, tolerance); int point_count = multi_point.getPointCount(); boolean b_found_covered = false; boolean[] covered = new boolean[point_count]; for (int i = 0; i < point_count; i++) covered[i] = false; Point2D pt = new Point2D(); for (int i = 0; i < point_count; i++) { multi_point.getXY(i, pt); if (!env.contains(pt)) continue; b_found_covered = true; covered[i] = true; } if (!b_found_covered) return multi_point; MultiPoint new_multipoint = (MultiPoint) multi_point.createInstance(); for (int i = 0; i < point_count; i++) { if (!covered[i]) new_multipoint.add(multi_point, i, i + 1); } return new_multipoint; }
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 void exportMultiPointToJson(MultiPoint mpt, SpatialReference spatialReference, JsonWriter jsonWriter, Map<String, Object> exportProperties) { boolean bExportZs = mpt.hasAttribute(Semantics.Z); boolean bExportMs = mpt.hasAttribute(Semantics.M); if (!mpt.isEmpty()) { MultiPointImpl mpImpl = (MultiPointImpl) mpt._getImpl();// get impl int n = mpt.getPointCount(); for (int i = 0; i < n; i++) { mpt.getXY(i, pt);
private Geometry createMultiPointFromStreams_() { assert (m_position != null); assert (m_paths == null); assert (m_path_flags == null); MultiPoint multi_point = new MultiPoint(); MultiPointImpl multi_point_impl = (MultiPointImpl) multi_point ._getImpl(); multi_point_impl.setAttributeStreamRef(Semantics.POSITION, m_position); if (m_b_has_zs) { assert (m_zs != null); multi_point_impl.setAttributeStreamRef(Semantics.Z, m_zs); } if (m_b_has_ms) { assert (m_ms != null); multi_point_impl.setAttributeStreamRef(Semantics.M, m_ms); } multi_point_impl.resize(m_position.size() / 2); multi_point_impl.notifyModified(MultiVertexGeometryImpl.DirtyFlags.DirtyAll); return multi_point; }
MultiPoint multipoint_b; if (_multipointA.getPointCount() > _multipointB.getPointCount()) { multipoint_a = _multipointB; multipoint_b = _multipointA; Envelope2D env_b = new Envelope2D(); Envelope2D envInter = new Envelope2D(); multipoint_a.queryEnvelope2D(env_a); multipoint_b.queryEnvelope2D(env_b); env_a.inflate(tolerance, tolerance); env_b.inflate(tolerance, tolerance); (MultiPointImpl) (multipoint_b._getImpl()), envInter); QuadTreeImpl.QuadTreeIteratorImpl qtIterB = quadTreeB.getIterator(); for (int vertex_a = 0; vertex_a < multipoint_a.getPointCount(); vertex_a++) { multipoint_a.getXY(vertex_a, ptA); .next()) { int vertex_b = quadTreeB.getElement(elementHandleB); multipoint_b.getXY(vertex_b, ptB);
@Override public Geometry createInstance() { return new MultiPoint(m_description); }
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; }
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 }
int createGeometry(Geometry.Type geometry_type, VertexDescription description) { int newgeom = newGeometry_(geometry_type.value()); if (m_vertices == null) { m_vertices_mp = new MultiPoint(description); m_vertices = (MultiPointImpl) m_vertices_mp._getImpl(); } else m_vertices_mp.mergeVertexDescription(description); m_vertex_description = m_vertices_mp.getDescription();// this // description // will be a // merge of // existing // description // and the // description // of the // multi_path m_b_has_attributes = m_vertex_description.getAttributeCount() > 1; if (m_first_geometry == -1) { m_first_geometry = newgeom; m_last_geometry = newgeom; } else { setPrevGeometry_(newgeom, m_last_geometry); setNextGeometry_(m_last_geometry, newgeom); m_last_geometry = newgeom; } return newgeom; }
public int numGeometries() { return multiPoint.getPointCount(); }
@Override public Geometry createInstance() { return new MultiPoint(getDescription()); }
public OGCGeometry geometryN(int n) { return OGCGeometry.createFromEsriGeometry(multiPoint.getPoint(n), esriSR); }
m_vertices_mp.add(multi_path, multi_path.getPathStart(ipath), mp_impl.getPathEnd(ipath)); m_xy_stream = (AttributeStreamOfDbl) m_vertices