@Override public boolean hasNext() { if (geometriesDeque.isEmpty()) { return false; } while (geometriesDeque.peek() instanceof OGCConcreteGeometryCollection) { OGCGeometryCollection collection = (OGCGeometryCollection) geometriesDeque.pop(); for (int i = 0; i < collection.numGeometries(); i++) { geometriesDeque.push(collection.geometryN(i)); } } return !geometriesDeque.isEmpty(); }
@Description("Returns the cardinality of the geometry collection") @ScalarFunction("ST_NumGeometries") @SqlType(INTEGER) public static long stNumGeometries(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); if (geometry.isEmpty()) { return 0; } GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType()); if (!type.isMultitype()) { return 1; } return ((OGCGeometryCollection) geometry).numGeometries(); }
@Override protected OGCGeometry evaluateOGCGeometry(OGCGeometry geometry, int n) throws HyracksDataException { if (geometry instanceof OGCGeometryCollection) { return ((OGCGeometryCollection) geometry).geometryN(n); } else { throw new UnsupportedOperationException( "The operation " + getIdentifier() + " is not supported for the type " + geometry.geometryType()); } } }
static protected OGCGeometry union(Tuple input) throws ExecException { DataBag values = (DataBag)input.get(0); if (values.size() == 0) return null; ArrayList<OGCGeometry> all_geoms = new ArrayList<OGCGeometry>(); for (Tuple one_geom : values) { OGCGeometry parsedGeom = geometryParser.parseGeom(one_geom.get(0)); all_geoms.add(parsedGeom); } // Do a union of all_geometries in the recommended way (using buffer(0)) OGCGeometryCollection geom_collection = new OGCConcreteGeometryCollection( all_geoms, all_geoms.get(0).getEsriSpatialReference()); return geom_collection.union(all_geoms.get(0)); }
static protected OGCGeometry extent(Tuple input) throws ExecException { DataBag values = (DataBag)input.get(0); if (values.size() == 0) return null; ArrayList<OGCGeometry> all_geoms = new ArrayList<OGCGeometry>(); for (Tuple one_geom : values) { OGCGeometry parsedGeom = geometryParser.parseGeom(one_geom.get(0)); all_geoms.add(parsedGeom); } // Do a union of all_geometries in the recommended way (using buffer(0)) OGCGeometryCollection geom_collection = new OGCConcreteGeometryCollection( all_geoms, all_geoms.get(0).getEsriSpatialReference()); return geom_collection.envelope(); }
static protected OGCGeometry convexHull(Tuple input) throws ExecException { DataBag values = (DataBag)input.get(0); if (values.size() == 0) return null; ArrayList<OGCGeometry> all_geoms = new ArrayList<OGCGeometry>(); for (Tuple one_geom : values) { OGCGeometry parsedGeom = geometryParser.parseGeom(one_geom.get(0)); all_geoms.add(parsedGeom); } // Do a convex null of all_geometries OGCGeometryCollection geom_collection = new OGCConcreteGeometryCollection( all_geoms, all_geoms.get(0).getEsriSpatialReference()); return geom_collection.convexHull(); }
} else if (createdShapes.size() > 1) { OGCGeometryCollection collection = new OGCConcreteGeometryCollection(createdShapes, createdShapes.get(0).getEsriSpatialReference()); return new DataByteArray(collection.asBinary().array()); } else { throw new GeoException("No shapes to connect");
@Override protected Object evaluateOGCGeometry(OGCGeometry geometry) throws HyracksDataException { if (geometry instanceof OGCGeometryCollection) { return ((OGCGeometryCollection) geometry).numGeometries(); } else if (!geometry.isEmpty()) { return 1; } else { return null; } }
OGCGeometryCollection geom_collection = new OGCConcreteGeometryCollection(category.getValue(), category.getValue().firstElement().esriSR); OGCGeometry union = geom_collection.union(category.getValue().firstElement()); final_result.put(category.getKey(), union);
@Override public boolean isIntersected(Shape s) { Rectangle s_mbr = s.getMBR(); Rectangle this_mbr = this.getMBR(); if (s_mbr == null || this_mbr == null) return false; // Filter step if (!s_mbr.isIntersected(this_mbr)) return false; try { if (s instanceof OGCESRIShape) return geom.intersects(((OGCESRIShape)s).geom); } catch (NullPointerException e) { // TODO Auto-generated catch block e.printStackTrace(); } ArrayList<OGCGeometry> points = new ArrayList<OGCGeometry>(); points.add(new OGCPoint(new com.esri.core.geometry.Point(s_mbr.x1, s_mbr.y1), geom.getEsriSpatialReference())); points.add(new OGCPoint(new com.esri.core.geometry.Point(s_mbr.x2, s_mbr.y2), geom.getEsriSpatialReference())); OGCGeometryCollection all_points = new OGCConcreteGeometryCollection(points, geom.getEsriSpatialReference()); return geom.intersects(all_points.envelope()); }
private static void writeGeometryCollection(DynamicSliceOutput output, OGCGeometryCollection collection) { output.appendByte(GeometrySerializationType.GEOMETRY_COLLECTION.code()); for (int geometryIndex = 0; geometryIndex < collection.numGeometries(); geometryIndex++) { OGCGeometry geometry = collection.geometryN(geometryIndex); int startPosition = output.size(); // leave 4 bytes for the shape length output.appendInt(0); writeGeometry(output, geometry); int endPosition = output.size(); int length = endPosition - startPosition - Integer.BYTES; output.getUnderlyingSlice().setInt(startPosition, length); } }
@Description("Returns the cardinality of the geometry collection") @ScalarFunction("ST_NumGeometries") @SqlType(INTEGER) public static long stNumGeometries(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); if (geometry.isEmpty()) { return 0; } GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType()); if (!type.isMultitype()) { return 1; } return ((OGCGeometryCollection) geometry).numGeometries(); }
@Override public void reduce(IntWritable category, Iterator<Text> shape_lines, OutputCollector<IntWritable, Text> output, Reporter reporter) throws IOException { OGCESRIShape shape = new OGCESRIShape(); Vector<OGCGeometry> shapes = new Vector<OGCGeometry>(); while (shape_lines.hasNext()) { shape.fromText(shape_lines.next()); shapes.add(shape.geom); } OGCGeometryCollection geo_collection = new OGCConcreteGeometryCollection(shapes, shapes.firstElement().getEsriSpatialReference()); OGCGeometry union = geo_collection.union(shapes.firstElement()); geo_collection = null; shapes = null; temp_out.clear(); output.collect(category, new OGCESRIShape(union).toText(temp_out)); } }
@SqlNullable @Description("Returns an array of geometries in the specified collection") @ScalarFunction("ST_Geometries") @SqlType("array(" + GEOMETRY_TYPE_NAME + ")") public static Block stGeometries(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); if (geometry.isEmpty()) { return null; } GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType()); if (!type.isMultitype()) { BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, 1); GEOMETRY.writeSlice(blockBuilder, serialize(geometry)); return blockBuilder.build(); } OGCGeometryCollection collection = (OGCGeometryCollection) geometry; BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, collection.numGeometries()); for (int i = 0; i < collection.numGeometries(); i++) { GEOMETRY.writeSlice(blockBuilder, serialize(collection.geometryN(i))); } return blockBuilder.build(); }
@Description("Returns the cardinality of the geometry collection") @ScalarFunction("ST_NumGeometries") @SqlType(INTEGER) public static long stNumGeometries(@SqlType(GEOMETRY_TYPE_NAME) Slice input) { OGCGeometry geometry = deserialize(input); if (geometry.isEmpty()) { return 0; } GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType()); if (!type.isMultitype()) { return 1; } return ((OGCGeometryCollection) geometry).numGeometries(); }
@SqlNullable @Description("Returns the geometry element at the specified index (indices started with 1)") @ScalarFunction("ST_GeometryN") @SqlType(GEOMETRY_TYPE_NAME) public static Slice stGeometryN(@SqlType(GEOMETRY_TYPE_NAME) Slice input, @SqlType(INTEGER) long index) { OGCGeometry geometry = deserialize(input); if (geometry.isEmpty()) { return null; } GeometryType type = GeometryType.getForEsriGeometryType(geometry.geometryType()); if (!type.isMultitype()) { if (index == 1) { return input; } return null; } OGCGeometryCollection geometryCollection = ((OGCGeometryCollection) geometry); if (index < 1 || index > geometryCollection.numGeometries()) { return null; } OGCGeometry ogcGeometry = geometryCollection.geometryN((int) index - 1); return serialize(ogcGeometry); }
@Override public boolean hasNext() { if (geometriesDeque.isEmpty()) { return false; } while (geometriesDeque.peek() instanceof OGCConcreteGeometryCollection) { OGCGeometryCollection collection = (OGCGeometryCollection) geometriesDeque.pop(); for (int i = 0; i < collection.numGeometries(); i++) { geometriesDeque.push(collection.geometryN(i)); } } return !geometriesDeque.isEmpty(); }
@Override public boolean hasNext() { if (geometriesDeque.isEmpty()) { return false; } while (geometriesDeque.peek() instanceof OGCConcreteGeometryCollection) { OGCGeometryCollection collection = (OGCGeometryCollection) geometriesDeque.pop(); for (int i = 0; i < collection.numGeometries(); i++) { geometriesDeque.push(collection.geometryN(i)); } } return !geometriesDeque.isEmpty(); }
private boolean isClosed(OGCGeometry geometry) { if (geometry instanceof OGCCurve) { return ((OGCCurve) geometry).isClosed(); } else if (geometry instanceof OGCMultiCurve) { return ((OGCMultiCurve) geometry).isClosed(); } else if (geometry instanceof OGCMultiPoint || geometry instanceof OGCMultiPolygon || geometry instanceof OGCPolygon || geometry instanceof OGCPoint) { return true; } else if (geometry instanceof OGCGeometryCollection) { OGCGeometryCollection geometryCollection = (OGCGeometryCollection) geometry; int num = geometryCollection.numGeometries(); for (int i = 0; i < num; ++i) { if (!isClosed(geometryCollection.geometryN(i))) { return false; } } return true; } else { throw new UnsupportedOperationException( "The operation " + getIdentifier() + " is not supported for the type " + geometry.geometryType()); } }
private static void writeGeometryCollection(DynamicSliceOutput output, OGCGeometryCollection collection) { output.appendByte(GeometrySerializationType.GEOMETRY_COLLECTION.code()); for (int geometryIndex = 0; geometryIndex < collection.numGeometries(); geometryIndex++) { OGCGeometry geometry = collection.geometryN(geometryIndex); int startPosition = output.size(); // leave 4 bytes for the shape length output.appendInt(0); writeGeometry(output, geometry); int endPosition = output.size(); int length = endPosition - startPosition - Integer.BYTES; output.getUnderlyingSlice().setInt(startPosition, length); } }