private static Point getPolygonSansHolesCentroid(Polygon polygon) { int pointCount = polygon.getPointCount(); double xSum = 0; double ySum = 0; double signedArea = 0; for (int i = 0; i < pointCount; i++) { Point current = polygon.getPoint(i); Point next = polygon.getPoint((i + 1) % polygon.getPointCount()); double ladder = current.getX() * next.getY() - next.getX() * current.getY(); xSum += (current.getX() + next.getX()) * ladder; ySum += (current.getY() + next.getY()) * ladder; signedArea += ladder / 2; } return new Point(xSum / (signedArea * 6), ySum / (signedArea * 6)); }
@SqlNullable @Description("Returns TRUE if the LineString or Multi-LineString's start and end points are coincident") @ScalarFunction("ST_IsClosed") @SqlType(BOOLEAN) public static Boolean stIsClosed(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); validateType("ST_IsClosed", geometry, EnumSet.of(LINE_STRING, MULTI_LINE_STRING)); MultiPath lines = (MultiPath) geometry.getEsriGeometry(); int pathCount = lines.getPathCount(); for (int i = 0; i < pathCount; i++) { Point start = lines.getPoint(lines.getPathStart(i)); Point end = lines.getPoint(lines.getPathEnd(i) - 1); if (!end.equals(start)) { return false; } } return true; }
private static void writePoint(DynamicSliceOutput output, OGCGeometry geometry) { Geometry esriGeometry = geometry.getEsriGeometry(); verify(esriGeometry instanceof Point, "geometry is expected to be an instance of Point"); Point point = (Point) esriGeometry; verify(!point.hasAttribute(VertexDescription.Semantics.Z) && !point.hasAttribute(VertexDescription.Semantics.M) && !point.hasAttribute(VertexDescription.Semantics.ID), "Only 2D points with no ID nor M attribute are supported"); output.appendByte(GeometrySerializationType.POINT.code()); if (!point.isEmpty()) { output.appendDouble(point.getX()); output.appendDouble(point.getY()); } else { output.appendDouble(NaN); output.appendDouble(NaN); } }
static void exportPointToWkt(int export_flags, Point point, StringBuilder string) { int precision = 17 - (7 & (export_flags >> 13)); boolean b_export_zs = point.hasAttribute(VertexDescription.Semantics.Z) && (export_flags & WktExportFlags.wktExportStripZs) == 0; boolean b_export_ms = point.hasAttribute(VertexDescription.Semantics.M) && (export_flags & WktExportFlags.wktExportStripMs) == 0; double x = NumberUtils.TheNaN; double y = NumberUtils.TheNaN; double z = NumberUtils.TheNaN; double m = NumberUtils.TheNaN; if (!point.isEmpty()) { x = point.getX(); y = point.getY(); if (b_export_zs) z = point.getZ(); if (b_export_ms) m = point.getM(); } if ((export_flags & WktExportFlags.wktExportMultiPoint) != 0) { multiPointTaggedTextFromPoint_(precision, b_export_zs, b_export_ms, x, y, z, m, string); } else { pointTaggedText_(precision, b_export_zs, b_export_ms, x, y, z, m, string); } }
new com.esri.core.geometry.Point(result.x, result.y), sr).asBinary(); } else { com.esri.core.geometry.Geometry esriGeom = geomSrc.getEsriGeometry(); for (int i = 0; i < vertexGeom.getPointCount(); i++) { com.esri.core.geometry.Point point = vertexGeom.getPoint(i); result = transform.transform(new org.osgeo.proj4j.ProjCoordinate(point.getX(), point.getY()), result); point.setXY(result.x, result.y); vertexGeom.setPoint(i, point);
/** * Checks if this envelope contains (covers) the specified point. * * @param p * The Point to be tested for coverage. * @return TRUE if this envelope contains (covers) the specified point. */ public boolean contains(Point p) { if (p.isEmpty()) return false; return m_envelope.contains(p.getX(), p.getY()); }
/** * If the given point is an implementation of this library, returns its coordinate. * Otherwise returns {@code null}. If non-null, the returned array may have a length of 2 or 3. */ @Override final double[] tryGetCoordinate(final Object point) { if (point instanceof Point) { final Point pt = (Point) point; final double z = pt.getZ(); final double[] coord; if (Double.isNaN(z)) { coord = new double[2]; } else { coord = new double[3]; coord[2] = z; } coord[1] = pt.getY(); coord[0] = pt.getX(); return coord; } return null; }
@Override public Point getPoint(int index) { if (index < 0 || index >= m_pointCount) throw new IndexOutOfBoundsException(); _verifyAllStreams(); Point outPoint = new Point(); outPoint.assignVertexDescription(m_description); if (outPoint.isEmpty()) outPoint._setToDefault(); for (int attributeIndex = 0; attributeIndex < m_description .getAttributeCount(); attributeIndex++) { int semantics = m_description.getSemantics(attributeIndex); for (int icomp = 0, ncomp = VertexDescription .getComponentCount(semantics); icomp < ncomp; icomp++) { double v = m_vertexAttributes[attributeIndex].readAsDbl(ncomp * index + icomp); outPoint.setAttribute(semantics, icomp, v); } } return outPoint; }
protected void _initPathStartPoint() { _touch(); if (m_moveToPoint == null) m_moveToPoint = new Point(m_description); else m_moveToPoint.assignVertexDescription(m_description); }
static boolean mergeVertices(Point pt_1, Point pt_2, double w_1, int rank_1, double w_2, int rank_2, Point pt_res, double[] w_res, int[] rank_res) { assert (!pt_1.isEmpty() && !pt_2.isEmpty()); boolean res = pt_1.equals(pt_2); if (rank_1 > rank_2) { pt_res = pt_1; if (w_res != null) { rank_res[0] = rank_1; w_res[0] = w_1; } return res; } else if (rank_2 > rank_1) { pt_res = pt_2; if (w_res != null) { rank_res[0] = rank_1; w_res[0] = w_1; } return res; } pt_res = pt_1; Point2D pt2d = new Point2D(); mergeVertices2D(pt_1.getXY(), pt_2.getXY(), w_1, rank_1, w_2, rank_2, pt2d, w_res, rank_res); pt_res.setXY(pt2d); return res; }
/** Returns the x-value of the first coordinate of {@code geom}. */ public static Double ST_X(Geom geom) { return geom.g() instanceof Point ? ((Point) geom.g()).getX() : null; }
/** Returns the y-value of the first coordinate of {@code geom}. */ public static Double ST_Y(Geom geom) { return geom.g() instanceof Point ? ((Point) geom.g()).getY() : null; }
@Override public void setPoint(int index, Point src) { if (index < 0 || index >= m_pointCount) throw new IndexOutOfBoundsException(); Point point = src; if (src.isEmpty())// can not assign an empty point to a multipoint // vertex throw new IllegalArgumentException(); _verifyAllStreams();// verify all allocated streams are of necessary // size. VertexDescription vdin = point.getDescription(); for (int attributeIndex = 0; attributeIndex < vdin.getAttributeCount(); attributeIndex++) { int semantics = vdin.getSemantics(attributeIndex); int ncomp = VertexDescription.getComponentCount(semantics); for (int icomp = 0; icomp < ncomp; icomp++) { double v = point.getAttributeAsDbl(semantics, icomp); setAttribute(semantics, index, icomp, v); } } }
static Point difference(Point point, Point point2, double tolerance) { if (point.isEmpty()) return (Point) point.createInstance(); if (point2.isEmpty()) return point; if (CrackAndCluster.non_empty_points_need_to_cluster(tolerance, point, point2)) { return (Point) point.createInstance(); } return point; }
@Override public void replaceNaNs(int semantics, double value) { addAttribute(semantics); if (isEmpty()) return; int ncomps = VertexDescription.getComponentCount(semantics); for (int i = 0; i < ncomps; i++) { double v = getAttributeAsDbl(semantics, i); if (Double.isNaN(v)) setAttribute(semantics, i, value); } } }
/** * Constructs an envelope that covers the given point. The coordinates of * the point are used to set the extent of the envelope. * * @param point The point that the envelope covers. */ public Envelope(Point point) { m_description = VertexDescriptionDesignerImpl.getDefaultDescriptor2D(); m_envelope.setEmpty(); if (point.isEmpty()) return; _setFromPoint(point); }
public void startPath(Point point) { if (point.isEmpty()) throw new IllegalArgumentException();// throw new // IllegalArgumentException(); mergeVertexDescription(point.getDescription()); _initPathStartPoint(); point.copyTo(m_moveToPoint); // TODO check MultiPathImpl.cpp comment // "//the description will be merged later" // assignVertexDescription(m_moveToPoint.getDescription()); m_bPathStarted = true; }
public double Z() { return point.getZ(); }