Search in sources :

Example 6 with GeometryCollection

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

the class GeoJSONTest method testGeometryCollectionWithZCoordinate.

@Test
public void testGeometryCollectionWithZCoordinate() throws GeoJSONException, IOException {
    GeometryCollection geometry = geometryFactory.createGeometryCollection(new Geometry[] { randomGeometryCollection(CRSUtils.EPSG_WGS84), randomGeometryCollection(2000) });
    geometry.apply(new RandomZCoordinateFilter());
    geometry.geometryChanged();
    readWriteTest(geometry);
}
Also used : GeometryCollection(org.locationtech.jts.geom.GeometryCollection) Test(org.junit.jupiter.api.Test)

Example 7 with GeometryCollection

use of org.locationtech.jts.geom.GeometryCollection in project ddf by codice.

the class Wfs20JTStoGML321Converter method createGeometryPropertyType.

private static GeometryPropertyType createGeometryPropertyType(Geometry geometry, String srsName) {
    final GeometryPropertyType geometryPropertyType = GML320_OBJECT_FACTORY.createGeometryPropertyType();
    if (geometry instanceof Point) {
        PointType pointType = convertToPointType((Point) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertPointTypeToJAXB(pointType));
    } else if (geometry instanceof LineString) {
        LineStringType lineStringType = convertToLineStringType((LineString) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertLineStringTypeToJAXB(lineStringType));
    } else if (geometry instanceof Polygon) {
        PolygonType polygonType = convertToPolygonType((Polygon) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertPolygonTypeToJAXB(polygonType));
    } else if (geometry instanceof MultiPoint) {
        MultiPointType multiPointType = convertToMultiPointType((MultiPoint) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertMultiPointTypeToJAXB(multiPointType));
    } else if (geometry instanceof MultiLineString) {
        MultiCurveType multiCurveType = convertToMultiLineStringType((MultiLineString) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertMultiCurveTypeToJAXB(multiCurveType));
    } else if (geometry instanceof MultiPolygon) {
        MultiSurfaceType multiSurfaceType = convertToMultiSurfaceType((MultiPolygon) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertMultiSurfaceTypeToJAXB(multiSurfaceType));
    } else if (geometry instanceof GeometryCollection) {
        MultiGeometryType multiGeometryType = convertToMultiGeometryType((GeometryCollection) geometry, srsName);
        geometryPropertyType.setAbstractGeometry(convertMultiGeometryTypeToJAXB(multiGeometryType));
    } else {
        throw new IllegalArgumentException();
    }
    return geometryPropertyType;
}
Also used : MultiPoint(org.locationtech.jts.geom.MultiPoint) MultiLineString(org.locationtech.jts.geom.MultiLineString) MultiCurveType(net.opengis.gml.v_3_2_1.MultiCurveType) MultiGeometryType(net.opengis.gml.v_3_2_1.MultiGeometryType) PolygonType(net.opengis.gml.v_3_2_1.PolygonType) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) LineStringType(net.opengis.gml.v_3_2_1.LineStringType) MultiPointType(net.opengis.gml.v_3_2_1.MultiPointType) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) MultiSurfaceType(net.opengis.gml.v_3_2_1.MultiSurfaceType) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) PointType(net.opengis.gml.v_3_2_1.PointType) MultiPointType(net.opengis.gml.v_3_2_1.MultiPointType) Polygon(org.locationtech.jts.geom.Polygon) MultiPolygon(org.locationtech.jts.geom.MultiPolygon) GeometryPropertyType(net.opengis.gml.v_3_2_1.GeometryPropertyType)

Example 8 with GeometryCollection

use of org.locationtech.jts.geom.GeometryCollection in project ddf by codice.

the class CswMarshallHelper method writeBoundingBox.

static void writeBoundingBox(HierarchicalStreamWriter writer, MarshallingContext context, Metacard metacard) {
    Set<AttributeDescriptor> attrDescs = metacard.getMetacardType().getAttributeDescriptors();
    List<Geometry> geometries = new LinkedList<>();
    for (AttributeDescriptor ad : attrDescs) {
        if (ad.getType() != null && AttributeType.AttributeFormat.GEOMETRY.equals(ad.getType().getAttributeFormat())) {
            Attribute attr = metacard.getAttribute(ad.getName());
            if (attr != null) {
                if (ad.isMultiValued()) {
                    for (Serializable value : attr.getValues()) {
                        geometries.add(XmlNode.readGeometry((String) value));
                    }
                } else {
                    geometries.add(XmlNode.readGeometry((String) attr.getValue()));
                }
            }
        }
    }
    Geometry allGeometry = new GeometryCollection(geometries.toArray(new Geometry[geometries.size()]), new GeometryFactory());
    Envelope bounds = allGeometry.getEnvelopeInternal();
    if (!bounds.isNull()) {
        String bbox = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_BOUNDING_BOX;
        String lower = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_LOWER_CORNER;
        String upper = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_UPPER_CORNER;
        writer.startNode(bbox);
        writer.addAttribute(CswConstants.CRS, CswConstants.SRS_URL);
        writer.startNode(lower);
        writer.setValue(bounds.getMinX() + " " + bounds.getMinY());
        writer.endNode();
        writer.startNode(upper);
        writer.setValue(bounds.getMaxX() + " " + bounds.getMaxY());
        writer.endNode();
        writer.endNode();
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) Serializable(java.io.Serializable) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Attribute(ddf.catalog.data.Attribute) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Envelope(org.locationtech.jts.geom.Envelope) LinkedList(java.util.LinkedList)

Example 9 with GeometryCollection

use of org.locationtech.jts.geom.GeometryCollection in project ddf by codice.

the class KmlToJtsMultiGeometryConverterTest method testConvertMultiGeometry.

@Test
public void testConvertMultiGeometry() {
    GeometryCollection geometryCollection = KmlToJtsMultiGeometryConverter.from(testKmlMultiGeometry);
    assertJtsGeometryCollection(geometryCollection);
}
Also used : GeometryCollection(org.locationtech.jts.geom.GeometryCollection) Test(org.junit.Test)

Example 10 with GeometryCollection

use of org.locationtech.jts.geom.GeometryCollection in project hale by halestudio.

the class GenericGeometryHandler method createGeometry.

/**
 * Create a geometry value from a given instance.
 *
 * @param instance the instance
 * @param childGeometries the child geometries found in the instance
 * @param defaultCrs the definition of the default CRS for this instance
 * @param reader the IO provider
 * @return the geometry value derived from the instance, the return type
 *         should match the {@link Binding} created in
 *         {@link #getTypeConstraints(TypeDefinition)}.
 * @throws GeometryNotSupportedException if the type definition doesn't
 *             represent a geometry type supported by the handler
 */
@SuppressWarnings("unused")
protected Collection<GeometryProperty<?>> createGeometry(Instance instance, List<GeometryProperty<?>> childGeometries, CRSDefinition defaultCrs, IOProvider reader) throws GeometryNotSupportedException {
    List<Geometry> geomList = new ArrayList<Geometry>();
    Class<? extends Geometry> commonGeomType = null;
    CRSWrapper commonCrs = null;
    boolean allowCombine = true;
    // TODO partition based on CRS?
    for (GeometryProperty<?> geomProp : childGeometries) {
        if (geomProp.getGeometry() instanceof GeometryCollection) {
            GeometryCollection geomCollection = (GeometryCollection) geomProp.getGeometry();
            for (int i = 0; i < geomCollection.getNumGeometries(); i++) {
                // find the common geometry class
                Class<? extends Geometry> geometryType = geomCollection.getGeometryN(i).getClass();
                if (commonGeomType == null) {
                    commonGeomType = geometryType;
                } else if (!commonGeomType.equals(geometryType)) {
                    // TODO determine common type in inheritance?
                    commonGeomType = Geometry.class;
                }
                geomList.add(geomCollection.getGeometryN(i));
            }
        } else {
            // find the common geometry class
            Class<? extends Geometry> geometryType = geomProp.getGeometry().getClass();
            if (commonGeomType == null) {
                commonGeomType = geometryType;
            } else if (!commonGeomType.equals(geometryType)) {
                // find common super class
                commonGeomType = findClosestCommonSuperclass(commonGeomType, geometryType);
            }
            geomList.add(geomProp.getGeometry());
        }
        // check common CRS
        CRSWrapper crs = new CRSWrapper(geomProp.getCRSDefinition());
        if (commonCrs == null) {
            commonCrs = crs;
        } else if (!commonCrs.equals(crs)) {
            allowCombine = false;
        }
    }
    if (allowCombine && commonGeomType != null) {
        if (!(commonGeomType.equals(Polygon.class) || commonGeomType.equals(Point.class) || commonGeomType.equals(LineString.class))) {
            // check if it is a subclass of a supported type
            if (LineString.class.isAssignableFrom(commonGeomType)) {
                // for instance for InterpolatedLineString
                commonGeomType = LineString.class;
            }
            if (Point.class.isAssignableFrom(commonGeomType)) {
                commonGeomType = Point.class;
            }
            if (Polygon.class.isAssignableFrom(commonGeomType)) {
                commonGeomType = Polygon.class;
            }
        }
        Geometry geom = null;
        if (commonGeomType.equals(Polygon.class)) {
            // create a MultiPolygon
            Polygon[] polygons = new Polygon[geomList.size()];
            for (int i = 0; i < geomList.size(); i++) {
                polygons[i] = (Polygon) geomList.get(i);
            }
            geom = combine(polygons, reader);
        } else if (commonGeomType.equals(LineString.class)) {
            // create a MultiLineString
            LineString[] lines = new LineString[geomList.size()];
            for (int i = 0; i < geomList.size(); i++) {
                lines[i] = (LineString) geomList.get(i);
            }
            geom = combine(lines, reader);
        } else if (commonGeomType.equals(Point.class)) {
            // create a MultiPoint
            Point[] points = new Point[geomList.size()];
            for (int i = 0; i < geomList.size(); i++) {
                points[i] = (Point) geomList.get(i);
            }
            geom = combine(points, reader);
        }
        if (geom != null) {
            // returned combined property
            CRSDefinition crs = (commonCrs != null && commonCrs.getCrsDef() != null) ? (commonCrs.getCrsDef()) : (defaultCrs);
            return Collections.<GeometryProperty<?>>singleton(new DefaultGeometryProperty<Geometry>(crs, geom));
        }
    }
    // fall-back: return a collection of geometry properties
    if (childGeometries.isEmpty()) {
        return null;
    }
    return childGeometries;
}
Also used : DefaultGeometryProperty(eu.esdihumboldt.hale.common.instance.geometry.DefaultGeometryProperty) GeometryProperty(eu.esdihumboldt.hale.common.schema.geometry.GeometryProperty) CRSDefinition(eu.esdihumboldt.hale.common.schema.geometry.CRSDefinition) ArrayList(java.util.ArrayList) Point(org.locationtech.jts.geom.Point) TypeConstraint(eu.esdihumboldt.hale.common.schema.model.TypeConstraint) Point(org.locationtech.jts.geom.Point) Geometry(org.locationtech.jts.geom.Geometry) GeometryCollection(org.locationtech.jts.geom.GeometryCollection) LineString(org.locationtech.jts.geom.LineString) Polygon(org.locationtech.jts.geom.Polygon)

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