case Polygon: { if (!multiType && ((Polygon) geometry).getExteriorRingCount() <= 1) { return new OGCPolygon((Polygon) geometry, null); Polygon polygon = new Polygon(); polygon.addEnvelope((Envelope) geometry, false); return new OGCPolygon(polygon, null);
@SqlNullable @Description("Returns the interior ring element at the specified index (indices start at 1)") @ScalarFunction("ST_InteriorRingN") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stInteriorRingN(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(INTEGER) long index) { OGCGeometry geometry = deserialize(input); validateType("ST_InteriorRingN", geometry, EnumSet.of(POLYGON)); OGCPolygon polygon = (OGCPolygon) geometry; if (index < 1 || index > polygon.numInteriorRing()) { return null; } OGCGeometry interiorRing = polygon.interiorRingN(toIntExact(index) - 1); return serialize(interiorRing); }
@SqlNullable @Description("Returns a line string representing the exterior ring of the POLYGON") @ScalarFunction("ST_ExteriorRing") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stExteriorRing(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); validateType("ST_ExteriorRing", geometry, EnumSet.of(POLYGON)); if (geometry.isEmpty()) { return null; } return serialize(((OGCPolygon) geometry).exteriorRing()); }
@SqlNullable @Description("Returns the cardinality of the collection of interior rings of a polygon") @ScalarFunction("ST_NumInteriorRing") @SqlType(BIGINT) public static Long stNumInteriorRings(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); validateType("ST_NumInteriorRing", geometry, EnumSet.of(POLYGON)); if (geometry.isEmpty()) { return null; } return Long.valueOf(((OGCPolygon) geometry).numInteriorRing()); }
@Override public DataByteArray exec(Tuple b) throws IOException { DataBag points = (DataBag) b.get(0); Point[] coordinates = new Point[(int) points.size()]; int i = 0; for (Tuple t : points) { coordinates[i++] = (Point) (geometryParser.parseGeom(t.get(0))).getEsriGeometry(); } Polygon multi_path = new Polygon(); for (i = 1; i <coordinates.length; i++) { Segment segment = new Line(); segment.setStart(coordinates[i-1]); segment.setEnd(coordinates[i]); multi_path.addSegment(segment, false); } OGCPolygon linestring = new OGCPolygon(multi_path, 0, SpatialReference.create(4326)); return new DataByteArray(linestring.asBinary().array()); }
@Override protected OGCGeometry evaluateOGCGeometry(OGCGeometry geometry, int n) throws HyracksDataException { if (geometry instanceof OGCPolygon) { return ((OGCPolygon) geometry).interiorRingN(n); } else { throw new UnsupportedOperationException( "The operation " + getIdentifier() + " is not supported for the type " + geometry.geometryType()); } } }
@Override public String asText() { return GeometryEngine.geometryToWkt(getEsriGeometry(), WktExportFlags.wktExportPolygon); }
@Override protected Object evaluateOGCGeometry(OGCGeometry geometry) throws HyracksDataException { if (geometry instanceof OGCPolygon) { return ((OGCPolygon) geometry).numInteriorRing(); } else { throw new UnsupportedOperationException( "The operation " + getIdentifier() + " is not supported for the type " + geometry.geometryType()); } }
public BytesWritable evaluate(BytesWritable geomref, IntWritable index) { if (geomref == null || geomref.getLength() == 0 || index == null) { LogUtils.Log_ArgumentsNull(LOG); return null; } OGCGeometry ogcGeometry = GeometryUtils.geometryFromEsriShape(geomref); if (ogcGeometry == null){ LogUtils.Log_ArgumentsNull(LOG); return null; } int idx = index.get() - 1; // 1-based UI, 0-based engine if (GeometryUtils.getType(geomref) == GeometryUtils.OGCType.ST_POLYGON) { try { OGCLineString hole = ((OGCPolygon)(ogcGeometry)).interiorRingN(idx); return GeometryUtils.geometryToEsriShapeBytesWritable(hole); } catch (Exception e) { LogUtils.Log_InternalError(LOG, "ST_InteriorRingN: " + e); return null; } } else { LogUtils.Log_InvalidType(LOG, GeometryUtils.OGCType.ST_POLYGON, GeometryUtils.getType(geomref)); return null; } }
@Override public String asText() { return GeometryEngine.geometryToWkt(getEsriGeometry(), WktExportFlags.wktExportPolygon); }
@SqlNullable @Description("Returns an array of interior rings of a polygon") @ScalarFunction("ST_InteriorRings") @SqlType("array(" + GEOMETRY_TYPE_NAME + ")") public static Block stInteriorRings(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); validateType("ST_InteriorRings", geometry, EnumSet.of(POLYGON)); if (geometry.isEmpty()) { return null; } OGCPolygon polygon = (OGCPolygon) geometry; BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, polygon.numInteriorRing()); for (int i = 0; i < polygon.numInteriorRing(); i++) { GEOMETRY.writeSlice(blockBuilder, serialize(polygon.interiorRingN(i))); } return blockBuilder.build(); }
@Override public OGCGeometry geometryN(int n) { int exterior = 0; for (int i = 0; i < polygon.getPathCount(); i++) { if (polygon.isExteriorRing(i)) exterior++; if (exterior == n + 1) { return new OGCPolygon(polygon, i, esriSR); } } throw new IllegalArgumentException("geometryN: n out of range"); }
@Override protected Object evaluateOGCGeometry(OGCGeometry geometry) throws HyracksDataException { if (geometry instanceof OGCPolygon) { return ((OGCPolygon) geometry).numInteriorRing() + 1; } else if (geometry instanceof OGCMultiPolygon) { OGCMultiPolygon polygon = (OGCMultiPolygon) geometry; int numGeometries = polygon.numGeometries(); int count = 0; for (int i = 1; i < numGeometries + 1; i++) { if (polygon.geometryN(i) instanceof OGCPolygon) { count += ((OGCPolygon) polygon.geometryN(i)).numInteriorRing() + 1; } } return count; } else { throw new UnsupportedOperationException( "The operation " + getIdentifier() + " is not supported for the type " + geometry.geometryType()); } }
@Override protected Object evaluateOGCGeometry(OGCGeometry geometry) throws HyracksDataException { if (geometry instanceof OGCPolygon) { return ((OGCPolygon) geometry).exteriorRing(); } else { throw new UnsupportedOperationException( "The operation " + getIdentifier() + " is not supported for the type " + geometry.geometryType()); } }
@Override public ByteBuffer asBinary() { OperatorExportToWkb op = (OperatorExportToWkb) OperatorFactoryLocal .getInstance().getOperator(Operator.Type.ExportToWkb); return op.execute(WkbExportFlags.wkbExportPolygon, getEsriGeometry(), null); }
@SqlNullable @Description("Returns the interior ring element at the specified index (indices start at 1)") @ScalarFunction("ST_InteriorRingN") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stInteriorRingN(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(INTEGER) long index) { OGCGeometry geometry = deserialize(input); validateType("ST_InteriorRingN", geometry, EnumSet.of(POLYGON)); OGCPolygon polygon = (OGCPolygon) geometry; if (index < 1 || index > polygon.numInteriorRing()) { return null; } OGCGeometry interiorRing = polygon.interiorRingN(toIntExact(index) - 1); return serialize(interiorRing); }
@Override public OGCGeometry geometryN(int n) { int exterior = 0; for (int i = 0; i < polygon.getPathCount(); i++) { if (polygon.isExteriorRing(i)) exterior++; if (exterior == n + 1) { return new OGCPolygon(polygon, i, esriSR); } } throw new IllegalArgumentException("geometryN: n out of range"); }
@SqlNullable @Description("Returns the cardinality of the collection of interior rings of a polygon") @ScalarFunction("ST_NumInteriorRing") @SqlType(BIGINT) public static Long stNumInteriorRings(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); validateType("ST_NumInteriorRing", geometry, EnumSet.of(POLYGON)); if (geometry.isEmpty()) { return null; } return Long.valueOf(((OGCPolygon) geometry).numInteriorRing()); }
@SqlNullable @Description("Returns a line string representing the exterior ring of the POLYGON") @ScalarFunction("ST_ExteriorRing") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stExteriorRing(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); validateType("ST_ExteriorRing", geometry, EnumSet.of(POLYGON)); if (geometry.isEmpty()) { return null; } return serialize(((OGCPolygon) geometry).exteriorRing()); }
@Override public ByteBuffer asBinary() { OperatorExportToWkb op = (OperatorExportToWkb) OperatorFactoryLocal .getInstance().getOperator(Operator.Type.ExportToWkb); return op.execute(WkbExportFlags.wkbExportPolygon, getEsriGeometry(), null); }