Java Code Examples for com.esri.core.geometry.MultiPath#getPoint()
The following examples show how to use
com.esri.core.geometry.MultiPath#getPoint() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeoFunctions.java From presto with Apache License 2.0 | 6 votes |
@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; }
Example 2
Source File: GeoFunctions.java From presto with Apache License 2.0 | 5 votes |
@SqlNullable @Description("Returns the great-circle length in meters of a linestring or multi-linestring on Earth's surface") @ScalarFunction("ST_Length") @SqlType(DOUBLE) public static Double stSphericalLength(@SqlType(SPHERICAL_GEOGRAPHY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); if (geometry.isEmpty()) { return null; } validateSphericalType("ST_Length", geometry, EnumSet.of(LINE_STRING, MULTI_LINE_STRING)); MultiPath lineString = (MultiPath) geometry.getEsriGeometry(); double sum = 0; // sum up paths on (multi)linestring for (int path = 0; path < lineString.getPathCount(); path++) { if (lineString.getPathSize(path) < 2) { continue; } // sum up distances between adjacent points on this path int pathStart = lineString.getPathStart(path); Point previous = lineString.getPoint(pathStart); for (int i = pathStart + 1; i < lineString.getPathEnd(path); i++) { Point next = lineString.getPoint(i); sum += greatCircleDistance(previous.getY(), previous.getX(), next.getY(), next.getX()); previous = next; } } return sum * 1000; }
Example 3
Source File: ST_IsClosed.java From spatial-framework-for-hadoop with Apache License 2.0 | 5 votes |
public BooleanWritable evaluate(BytesWritable geomref) { if (geomref == null || geomref.getLength() == 0) { LogUtils.Log_ArgumentsNull(LOG); return null; } OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geomref); if (ogcGeometry == null){ LogUtils.Log_ArgumentsNull(LOG); return null; } try { switch(GeometryUtils.getType(geomref)) { case ST_LINESTRING: case ST_MULTILINESTRING: MultiPath lines = (MultiPath)(ogcGeometry.getEsriGeometry()); int nPaths = lines.getPathCount(); boolean rslt = true; for (int ix = 0; rslt && ix < nPaths; ix++) { Point p0 = lines.getPoint(lines.getPathStart(ix)); Point pf = lines.getPoint(lines.getPathEnd(ix)-1); rslt = rslt && pf.equals(p0); // no tolerance - OGC } resultBoolean.set(rslt); return resultBoolean; default: // ST_IsClosed gives ERROR on Point or Polygon, on Postgres/Oracle LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_LINESTRING, GeometryUtils.getType(geomref)); return null; } } catch (Exception e) { LogUtils.Log_InternalError(LOG, "ST_IsClosed" + e); return null; } }
Example 4
Source File: GeoFunctions.java From presto with Apache License 2.0 | 4 votes |
private static List<Point> interpolatePoints(OGCGeometry geometry, double fractionStep, boolean repeated) { validateType("line_interpolate_point", geometry, EnumSet.of(LINE_STRING)); if (fractionStep < 0 || fractionStep > 1) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "fraction must be between 0 and 1"); } MultiPath path = (MultiPath) geometry.getEsriGeometry(); if (fractionStep == 0) { return Collections.singletonList(path.getPoint(0)); } if (fractionStep == 1) { return Collections.singletonList((path.getPoint(path.getPointCount() - 1))); } int pointCount = repeated ? (int) Math.floor(1 / fractionStep) : 1; List<Point> interpolatedPoints = new ArrayList<>(pointCount); double lineStringLength = path.calculateLength2D(); Point previous = path.getPoint(0); double fractionConsumed = 0.0; double fractionIncrement = fractionStep; for (int i = 1; i < path.getPointCount() && interpolatedPoints.size() < pointCount; i++) { Point current = path.getPoint(i); double segmentLengthFraction = GeometryEngine.distance(previous, current, null) / lineStringLength; while (fractionStep < fractionConsumed + segmentLengthFraction && interpolatedPoints.size() < pointCount) { double segmentFraction = (fractionStep - fractionConsumed) / segmentLengthFraction; Point point = new Point(); point.setX(previous.getX() + (current.getX() - previous.getX()) * segmentFraction); point.setY(previous.getY() + (current.getY() - previous.getY()) * segmentFraction); interpolatedPoints.add(point); fractionStep += fractionIncrement; } fractionConsumed += segmentLengthFraction; previous = current; } if (interpolatedPoints.size() < pointCount) { interpolatedPoints.add(path.getPoint(path.getPointCount() - 1)); } return interpolatedPoints; }
Example 5
Source File: ST_GeodesicLengthWGS84.java From spatial-framework-for-hadoop with Apache License 2.0 | 4 votes |
public DoubleWritable evaluate(BytesWritable geomref) { if (geomref == null || geomref.getLength() == 0) { LogUtils.Log_ArgumentsNull(LOG); return null; } int WGS84 = 4326; if (GeometryUtils.getWKID(geomref) != WGS84) { LogUtils.Log_SRIDMismatch(LOG, geomref, WGS84); return null; } OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geomref); if (ogcGeometry == null){ LogUtils.Log_ArgumentsNull(LOG); return null; } Geometry esriGeom = ogcGeometry.getEsriGeometry(); switch(esriGeom.getType()) { case Point: case MultiPoint: resultDouble.set(0.); break; default: MultiPath lines = (MultiPath)(esriGeom); int nPath = lines.getPathCount(); double length = 0.; for (int ix = 0; ix < nPath; ix++) { int curPt = lines.getPathStart(ix); int pastPt = lines.getPathEnd(ix); Point fromPt = lines.getPoint(curPt); Point toPt = null; for (int vx = curPt+1; vx < pastPt; vx++) { toPt = lines.getPoint(vx); length += GeometryEngine.geodesicDistanceOnWGS84(fromPt, toPt); fromPt = toPt; } } resultDouble.set(length); break; } return resultDouble; }