Search in sources :

Example 1 with GeometryCollection

use of org.locationtech.jts.geom.GeometryCollection in project arctic-sea by 52North.

the class GeoJSONTest method randomGeometryCollection.

private GeometryCollection randomGeometryCollection(int srid) {
    GeometryCollection geometry = geometryFactory.createGeometryCollection(new Geometry[] { randomPoint(srid), randomMultiPoint(srid), randomLineString(srid), randomMultiLineString(srid), randomPolygon(srid), randomMultiPolygon(srid) });
    geometry.setSRID(srid);
    return geometry;
}
Also used : GeometryCollection(org.locationtech.jts.geom.GeometryCollection)

Example 2 with GeometryCollection

use of org.locationtech.jts.geom.GeometryCollection in project presto by prestodb.

the class GeoFunctions method stGeometries.

@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) {
    Geometry geometry = deserialize(input);
    if (geometry.isEmpty()) {
        return null;
    }
    GeometryType type = GeometryType.getForJtsGeometryType(geometry.getGeometryType());
    if (!type.isMultitype()) {
        BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, 1);
        GEOMETRY.writeSlice(blockBuilder, serialize(geometry));
        return blockBuilder.build();
    }
    GeometryCollection collection = (GeometryCollection) geometry;
    BlockBuilder blockBuilder = GEOMETRY.createBlockBuilder(null, collection.getNumGeometries());
    for (int i = 0; i < collection.getNumGeometries(); i++) {
        GEOMETRY.writeSlice(blockBuilder, serialize(collection.getGeometryN(i)));
    }
    return blockBuilder.build();
}
Also used : GeometryUtils.wktFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometry.createFromEsriGeometry(com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryUtils.jsonFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) OGCConcreteGeometryCollection(com.esri.core.geometry.ogc.OGCConcreteGeometryCollection) GeometryType(com.facebook.presto.geospatial.GeometryType) GeometryUtils.createJtsMultiPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsMultiPoint) Point(com.esri.core.geometry.Point) GeometryUtils.createJtsEmptyPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsEmptyPoint) GeometryUtils.createJtsPoint(com.facebook.presto.geospatial.GeometryUtils.createJtsPoint) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 3 with GeometryCollection

use of org.locationtech.jts.geom.GeometryCollection in project presto by prestodb.

the class GeoFunctions method stGeometryN.

@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) {
    Geometry geometry = deserialize(input);
    if (geometry.isEmpty()) {
        return null;
    }
    GeometryType type = GeometryType.getForJtsGeometryType(geometry.getGeometryType());
    if (!type.isMultitype()) {
        if (index == 1) {
            return input;
        }
        return null;
    }
    GeometryCollection geometryCollection = ((GeometryCollection) geometry);
    if (index < 1 || index > geometryCollection.getNumGeometries()) {
        return null;
    }
    return serialize(geometryCollection.getGeometryN((int) index - 1));
}
Also used : GeometryUtils.wktFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry) OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) OGCGeometry.createFromEsriGeometry(com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryUtils.jsonFromJtsGeometry(com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) OGCConcreteGeometryCollection(com.esri.core.geometry.ogc.OGCConcreteGeometryCollection) GeometryType(com.facebook.presto.geospatial.GeometryType) SqlNullable(com.facebook.presto.spi.function.SqlNullable) ScalarFunction(com.facebook.presto.spi.function.ScalarFunction) Description(com.facebook.presto.spi.function.Description) SqlType(com.facebook.presto.spi.function.SqlType)

Example 4 with GeometryCollection

use of org.locationtech.jts.geom.GeometryCollection in project jena by apache.

the class WKTWriter method expand.

private static String expand(final Geometry geometry, final CoordinateSequenceDimensions dimensions) {
    String wktString = "";
    String dimensionString = CoordinateSequenceDimensions.convertDimensions(dimensions);
    switch(geometry.getGeometryType()) {
        case "Point":
            Point point = (Point) geometry;
            wktString = buildWKT("POINT", point.getCoordinateSequence(), dimensionString);
            break;
        case "LineString":
        case "LinearRing":
            LineString lineString = (LineString) geometry;
            wktString = buildWKT("LINESTRING", lineString.getCoordinateSequence(), dimensionString);
            break;
        case "Polygon":
            Polygon polygon = (Polygon) geometry;
            wktString = buildPolygon(polygon, true, dimensionString);
            break;
        case "MultiPoint":
            MultiPoint multiPoint = (MultiPoint) geometry;
            wktString = buildMultiPoint(multiPoint, dimensionString);
            break;
        case "MultiLineString":
            MultiLineString multiLineString = (MultiLineString) geometry;
            wktString = buildMultiLineString(multiLineString, dimensionString);
            break;
        case "MultiPolygon":
            MultiPolygon multiPolygon = (MultiPolygon) geometry;
            wktString = buildMultiPolygon(multiPolygon, dimensionString);
            break;
        case "GeometryCollection":
            GeometryCollection geometryCollection = (GeometryCollection) geometry;
            wktString = buildGeometryCollection(geometryCollection, dimensions);
            break;
    }
    return wktString;
}
Also used : MultiPoint(org.locationtech.jts.geom.MultiPoint) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) MultiLineString(org.locationtech.jts.geom.MultiLineString) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon)

Example 5 with GeometryCollection

use of org.locationtech.jts.geom.GeometryCollection in project series-rest-api by 52North.

the class GeoJSONTest method randomGeometryCollection.

private GeometryCollection randomGeometryCollection(int srid) {
    GeometryCollection geometry = geometryFactory.createGeometryCollection(new Geometry[] { randomPoint(srid), randomMultiPoint(srid), randomLineString(srid), randomMultiLineString(srid), randomPolygon(srid), randomMultiPolygon(srid) });
    geometry.setSRID(srid);
    return geometry;
}
Also used : GeometryCollection(org.locationtech.jts.geom.GeometryCollection)

Aggregations

GeometryCollection (org.locationtech.jts.geom.GeometryCollection)23 Geometry (org.locationtech.jts.geom.Geometry)13 Point (org.locationtech.jts.geom.Point)7 LineString (org.locationtech.jts.geom.LineString)6 Polygon (org.locationtech.jts.geom.Polygon)6 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)3 MultiLineString (org.locationtech.jts.geom.MultiLineString)3 MultiPoint (org.locationtech.jts.geom.MultiPoint)3 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)3 OGCConcreteGeometryCollection (com.esri.core.geometry.ogc.OGCConcreteGeometryCollection)2 OGCGeometry (com.esri.core.geometry.ogc.OGCGeometry)2 OGCGeometry.createFromEsriGeometry (com.esri.core.geometry.ogc.OGCGeometry.createFromEsriGeometry)2 GeometryType (com.facebook.presto.geospatial.GeometryType)2 GeometryUtils.jsonFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.jsonFromJtsGeometry)2 GeometryUtils.wktFromJtsGeometry (com.facebook.presto.geospatial.GeometryUtils.wktFromJtsGeometry)2 Description (com.facebook.presto.spi.function.Description)2 ScalarFunction (com.facebook.presto.spi.function.ScalarFunction)2 SqlNullable (com.facebook.presto.spi.function.SqlNullable)2 SqlType (com.facebook.presto.spi.function.SqlType)2