@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; }
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; }
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; }
@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; }
@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; }
Point p0 = lines.getPoint(lines.getPathStart(ix)); Point pf = lines.getPoint(lines.getPathEnd(ix)-1); rslt = rslt && pf.equals(p0); // no tolerance - OGC