@SqlNullable @Description("Returns the vertex of a linestring at the specified index (indices started with 1) ") @ScalarFunction("ST_PointN") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stPointN(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(INTEGER) long index) { OGCGeometry geometry = deserialize(input); validateType("ST_PointN", geometry, EnumSet.of(LINE_STRING)); OGCLineString linestring = (OGCLineString) geometry; if (index < 1 || index > linestring.numPoints()) { return null; } return serialize(linestring.pointN(toIntExact(index) - 1)); }
@Override public OGCPoint startPoint() { return pointN(0); }
@Override public OGCPoint startPoint() { return pointN(0); }
@Override public OGCPoint endPoint() { return pointN(numPoints() - 1); }
@Override public OGCPoint endPoint() { return pointN(numPoints() - 1); }
@Override protected OGCGeometry evaluateOGCGeometry(OGCGeometry geometry, int n) throws HyracksDataException { if (geometry instanceof OGCLineString) { return ((OGCLineString) geometry).pointN(n); } else { throw new UnsupportedOperationException( "The operation " + getIdentifier() + " is not supported for the type " + geometry.geometryType()); } } }
public void drawESRIGeom(Graphics g, OGCGeometry geom, double xscale, double yscale) { if (geom instanceof OGCLineString) { OGCLineString linestring = (OGCLineString) geom; int[] xs = new int[linestring.numPoints()]; int[] ys = new int[linestring.numPoints()]; int n = 0; for (int i = 0; i < n; i++) { OGCPoint point = linestring.pointN(i); xs[n] = (int) Math.floor(point.X() * xscale); ys[n] = (int) Math.floor(point.Y() * yscale); // Increment number of point if this point is different than previous ones if (n == 0 || xs[n] != xs[n-1] || ys[n] != ys[n-1]) n++; } g.drawPolyline(xs, ys, n); } else { throw new RuntimeException("Cannot draw a shape of type "+geom.getClass()); } } }
linestring.numPoints() - 1 : linestring.numPoints(); for (int i_point = 0; i_point < last_i; i_point++) { points[n++] = (Point) linestring.pointN( isReverse? linestring.numPoints() - 1 - i_point : i_point ).getEsriGeometry();
@SqlNullable @Description("Returns the vertex of a linestring at the specified index (indices started with 1) ") @ScalarFunction("ST_PointN") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stPointN(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(INTEGER) long index) { OGCGeometry geometry = deserialize(input); validateType("ST_PointN", geometry, EnumSet.of(LINE_STRING)); OGCLineString linestring = (OGCLineString) geometry; if (index < 1 || index > linestring.numPoints()) { return null; } return serialize(linestring.pointN(toIntExact(index) - 1)); }
@SqlNullable @Description("Returns the vertex of a linestring at the specified index (indices started with 1) ") @ScalarFunction("ST_PointN") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stPointN(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(INTEGER) long index) { OGCGeometry geometry = deserialize(input); validateType("ST_PointN", geometry, EnumSet.of(LINE_STRING)); OGCLineString linestring = (OGCLineString) geometry; if (index < 1 || index > linestring.numPoints()) { return null; } return serialize(linestring.pointN(toIntExact(index) - 1)); }