Search in sources :

Example 6 with GeometryCollection

use of com.vividsolutions.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(com.vividsolutions.jts.geom.MultiPoint) MultiLineString(com.vividsolutions.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(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) LineStringType(net.opengis.gml.v_3_2_1.LineStringType) MultiPointType(net.opengis.gml.v_3_2_1.MultiPointType) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) MultiSurfaceType(net.opengis.gml.v_3_2_1.MultiSurfaceType) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) PointType(net.opengis.gml.v_3_2_1.PointType) MultiPointType(net.opengis.gml.v_3_2_1.MultiPointType) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon) GeometryPropertyType(net.opengis.gml.v_3_2_1.GeometryPropertyType)

Example 7 with GeometryCollection

use of com.vividsolutions.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(com.vividsolutions.jts.geom.Geometry) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) Serializable(java.io.Serializable) GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Attribute(ddf.catalog.data.Attribute) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Envelope(com.vividsolutions.jts.geom.Envelope) LinkedList(java.util.LinkedList)

Example 8 with GeometryCollection

use of com.vividsolutions.jts.geom.GeometryCollection in project ddf by codice.

the class WfsFilterDelegate method createGeometryOperand.

private JAXBElement<? extends AbstractGeometryType> createGeometryOperand(String wkt) {
    String convertedWkt = wkt;
    Geometry wktGeometry = null;
    try {
        wktGeometry = getGeometryFromWkt(convertedWkt);
    } catch (ParseException e) {
        throw new IllegalArgumentException("Unable to parse WKT Geometry [" + convertedWkt + "]", e);
    }
    if (wktGeometry instanceof Polygon) {
        if (isGeometryOperandSupported(Wfs10Constants.POLYGON)) {
            return createPolygon(convertedWkt);
        } else {
            throw new IllegalArgumentException("The Polygon operand is not supported.");
        }
    } else if (wktGeometry instanceof Point) {
        if (isGeometryOperandSupported(Wfs10Constants.POINT)) {
            return createPoint(convertedWkt);
        } else {
            throw new IllegalArgumentException("The Point operand is not supported.");
        }
    } else if (wktGeometry instanceof LineString) {
        if (isGeometryOperandSupported(Wfs10Constants.LINESTRING)) {
            return createLineString(wktGeometry);
        } else {
            throw new IllegalArgumentException("The LineString operand is not supported.");
        }
    } else if (wktGeometry instanceof MultiPoint) {
        if (isGeometryOperandSupported(Wfs10Constants.MULTI_POINT)) {
            return createMultiPoint(wktGeometry);
        } else {
            throw new IllegalArgumentException("The MultiPoint operand is not supported.");
        }
    } else if (wktGeometry instanceof MultiLineString) {
        if (isGeometryOperandSupported(Wfs10Constants.MULTI_LINESTRING)) {
            return createMultiLineString(wktGeometry);
        } else {
            throw new IllegalArgumentException("The MultiLineString operand is not supported.");
        }
    } else if (wktGeometry instanceof MultiPolygon) {
        if (isGeometryOperandSupported(Wfs10Constants.MULTI_POLYGON)) {
            return createMultiPolygon(wktGeometry);
        } else {
            throw new IllegalArgumentException("The MultiPolygon operand is not supported.");
        }
    } else if (wktGeometry instanceof GeometryCollection) {
        if (isGeometryOperandSupported(Wfs10Constants.GEOMETRY_COLLECTION)) {
            return createGeometryCollection(wktGeometry);
        } else {
            throw new IllegalArgumentException("The GeometryCollection operand is not supported.");
        }
    }
    throw new IllegalArgumentException("Unable to create Geometry from WKT String");
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) LineString(com.vividsolutions.jts.geom.LineString) MultiLineString(com.vividsolutions.jts.geom.MultiLineString) ParseException(com.vividsolutions.jts.io.ParseException) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 9 with GeometryCollection

use of com.vividsolutions.jts.geom.GeometryCollection in project series-rest-api by 52North.

the class GeoJSONTest method testCrs.

private void testCrs(int parent, int child) {
    final GeometryCollection col = geometryFactory.createGeometryCollection(new Geometry[] { randomPoint(child) });
    col.setSRID(parent);
    readWriteTest(col);
}
Also used : GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection)

Example 10 with GeometryCollection

use of com.vividsolutions.jts.geom.GeometryCollection in project ddf by codice.

the class DynamicSchemaResolver method createCenterPoint.

private String createCenterPoint(List<Serializable> values) {
    WKTReader reader = new WKTReader(GEOMETRY_FACTORY);
    List<Geometry> geometries = new ArrayList<>();
    for (Serializable serializable : values) {
        String wkt = serializable.toString();
        try {
            geometries.add(reader.read(wkt));
        } catch (ParseException e) {
            LOGGER.debug("Failed to read WKT, skipping: {}", wkt, e);
        }
    }
    if (geometries.isEmpty()) {
        return null;
    }
    Point centerPoint;
    if (geometries.size() > 1) {
        GeometryCollection geoCollection = GEOMETRY_FACTORY.createGeometryCollection(geometries.toArray(new Geometry[geometries.size()]));
        centerPoint = geoCollection.getCentroid();
    } else {
        centerPoint = geometries.get(0).getCentroid();
    }
    return centerPoint.getY() + "," + centerPoint.getX();
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) GeometryCollection(com.vividsolutions.jts.geom.GeometryCollection) Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) ParseException(com.vividsolutions.jts.io.ParseException) Point(com.vividsolutions.jts.geom.Point) WKTReader(com.vividsolutions.jts.io.WKTReader)

Aggregations

GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)12 Geometry (com.vividsolutions.jts.geom.Geometry)6 LineString (com.vividsolutions.jts.geom.LineString)4 Point (com.vividsolutions.jts.geom.Point)4 Polygon (com.vividsolutions.jts.geom.Polygon)4 ArrayList (java.util.ArrayList)4 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)3 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)3 Serializable (java.io.Serializable)3 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)2 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)2 ParseException (com.vividsolutions.jts.io.ParseException)2 WKTReader (com.vividsolutions.jts.io.WKTReader)2 Test (org.junit.Test)2 Envelope (com.vividsolutions.jts.geom.Envelope)1 Attribute (ddf.catalog.data.Attribute)1 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)1 Metacard (ddf.catalog.data.Metacard)1 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)1 Coordinate (de.micromata.opengis.kml.v_2_2_0.Coordinate)1