@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 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(); }
@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(); }
@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 protected Object evaluateOGCGeometry(OGCGeometry geometry) throws HyracksDataException { if (geometry instanceof OGCGeometryCollection) { return ((OGCGeometryCollection) geometry).numGeometries(); } else if (!geometry.isEmpty()) { return 1; } else { return null; } }
@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()); } }
if (geom instanceof OGCGeometryCollection) { OGCGeometryCollection geom_coll = (OGCGeometryCollection) geom; for (int i = 0; i < geom_coll.numGeometries(); i++) { OGCGeometry sub_geom = geom_coll.geometryN(i);
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); } }
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(); }
@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(); }
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); } }
@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(); }
@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(); }
@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); }
@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); }