Search in sources :

Example 31 with Geometry

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

the class AbstractGmlDecoderv321 method parseNamedValueValue.

protected NamedValue<?> parseNamedValueValue(XmlObject xml) throws DecodingException {
    XmlObject xmlObject = xml;
    if (xmlObject.schemaType() == XmlAnyTypeImpl.type) {
        try {
            xmlObject = XmlObject.Factory.parse(xml.xmlText().trim());
        } catch (XmlException e) {
            LOGGER.error("Error while parsing NamedValueValue", e);
        }
    }
    Object value;
    if (XmlBoolean.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
        value = ((XmlBoolean) xmlObject).getBooleanValue();
    } else if (XmlString.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
        value = ((XmlString) xmlObject).getStringValue();
    } else if (XmlInt.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
        value = ((XmlInt) xmlObject).getIntValue();
    } else if (XmlInteger.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
        value = ((XmlInteger) xmlObject).getBigIntegerValue().intValue();
    } else if (XmlDouble.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
        value = ((XmlDouble) xmlObject).getDoubleValue();
    } else {
        value = decodeXmlObject(xmlObject);
    }
    if (value instanceof BooleanValue) {
        NamedValue<Boolean> namedValue = new NamedValue<>();
        namedValue.setValue((BooleanValue) value);
        return namedValue;
    } else if (value instanceof SweBoolean) {
        NamedValue<Boolean> namedValue = new NamedValue<>();
        namedValue.setValue(new BooleanValue(((SweBoolean) value).getValue()));
        return namedValue;
    } else if (value instanceof Boolean) {
        NamedValue<Boolean> namedValue = new NamedValue<>();
        namedValue.setValue(new BooleanValue((Boolean) value));
        return namedValue;
    } else if (value instanceof CategoryValue) {
        NamedValue<String> namedValue = new NamedValue<>();
        namedValue.setValue((CategoryValue) value);
        return namedValue;
    } else if (value instanceof SweCategory) {
        NamedValue<String> namedValue = new NamedValue<>();
        namedValue.setValue(new CategoryValue(((SweCategory) value).getValue(), ((SweCategory) value).getCodeSpace()));
        return namedValue;
    } else if (value instanceof CountValue) {
        NamedValue<Integer> namedValue = new NamedValue<>();
        namedValue.setValue((CountValue) value);
        return namedValue;
    } else if (value instanceof SweCount) {
        NamedValue<Integer> namedValue = new NamedValue<>();
        namedValue.setValue(new CountValue(((SweCount) value).getValue()));
        return namedValue;
    } else if (value instanceof Integer) {
        NamedValue<Integer> namedValue = new NamedValue<>();
        namedValue.setValue(new CountValue((Integer) value));
        return namedValue;
    } else if (value instanceof GeometryValue) {
        NamedValue<Geometry> namedValue = new NamedValue<>();
        namedValue.setValue((GeometryValue) value);
        return namedValue;
    } else if (value instanceof QuantityValue) {
        NamedValue<BigDecimal> namedValue = new NamedValue<>();
        namedValue.setValue((QuantityValue) value);
        return namedValue;
    } else if (value instanceof GmlMeasureType) {
        NamedValue<BigDecimal> namedValue = new NamedValue<>();
        namedValue.setValue(new QuantityValue(((GmlMeasureType) value).getValue(), ((GmlMeasureType) value).getUnit()));
        return namedValue;
    } else if (value instanceof SweQuantity) {
        NamedValue<BigDecimal> namedValue = new NamedValue<>();
        namedValue.setValue(new QuantityValue(((SweQuantity) value).getValue(), ((SweQuantity) value).getUom()));
        return namedValue;
    } else if (value instanceof Double) {
        NamedValue<BigDecimal> namedValue = new NamedValue<>();
        namedValue.setValue(new QuantityValue((Double) value));
        return namedValue;
    } else if (value instanceof TextValue) {
        NamedValue<String> namedValue = new NamedValue<>();
        namedValue.setValue((TextValue) value);
        return namedValue;
    } else if (value instanceof SweText) {
        NamedValue<String> namedValue = new NamedValue<>();
        namedValue.setValue(new TextValue(((SweText) value).getValue()));
        return namedValue;
    } else if (value instanceof String) {
        NamedValue<String> namedValue = new NamedValue<>();
        namedValue.setValue(new TextValue((String) value));
        return namedValue;
    } else if (value instanceof AbstractGeometry) {
        NamedValue<Geometry> namedValue = new NamedValue<>();
        namedValue.setValue(new GeometryValue((AbstractGeometry) value));
        return namedValue;
    } else if (value instanceof org.n52.shetland.ogc.gml.ReferenceType) {
        NamedValue<org.n52.shetland.ogc.gml.ReferenceType> namedValue = new NamedValue<>();
        namedValue.setValue(new ReferenceValue((org.n52.shetland.ogc.gml.ReferenceType) value));
        return namedValue;
    } else if (value instanceof W3CHrefAttribute) {
        NamedValue<W3CHrefAttribute> namedValue = new NamedValue<>();
        namedValue.setValue(new HrefAttributeValue((W3CHrefAttribute) value));
        return namedValue;
    } else {
        throw new UnsupportedDecoderInputException(this, xmlObject);
    }
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) ReferenceValue(org.n52.shetland.ogc.om.values.ReferenceValue) NamedValue(org.n52.shetland.ogc.om.NamedValue) XmlString(org.apache.xmlbeans.XmlString) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) CountValue(org.n52.shetland.ogc.om.values.CountValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) XmlBoolean(org.apache.xmlbeans.XmlBoolean) HrefAttributeValue(org.n52.shetland.ogc.om.values.HrefAttributeValue) XmlString(org.apache.xmlbeans.XmlString) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) W3CHrefAttribute(org.n52.shetland.w3c.xlink.W3CHrefAttribute) XmlDouble(org.apache.xmlbeans.XmlDouble) UnsupportedDecoderInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderInputException) BigDecimal(java.math.BigDecimal) XmlInteger(org.apache.xmlbeans.XmlInteger) Geometry(org.locationtech.jts.geom.Geometry) AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) XmlException(org.apache.xmlbeans.XmlException) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) TextValue(org.n52.shetland.ogc.om.values.TextValue) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue) XmlObject(org.apache.xmlbeans.XmlObject) XmlObject(org.apache.xmlbeans.XmlObject) GmlMeasureType(org.n52.shetland.ogc.gml.GmlMeasureType)

Example 32 with Geometry

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

the class OgcDecoderv100 method parseBBOXFilterType.

/**
 * Parses the spatial filter of a request.
 *
 * @param xbBBOX XmlBean representing the feature of interest parameter of the request
 *
 * @return Returns SpatialFilter created from the passed foi request parameter
 *
 * @throws DecodingException * if creation of the SpatialFilter failed
 */
private SpatialFilter parseBBOXFilterType(BBOXTypeImpl xbBBOX) throws DecodingException {
    SpatialFilter spatialFilter = new SpatialFilter();
    // FIXME local workaround for SOSHelper check value reference
    String valueRef = "om:featureOfInterest/sams:SF_SpatialSamplingFeature/sams:shape";
    try {
        spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
        XmlCursor geometryCursor = xbBBOX.newCursor();
        if (geometryCursor.toChild(GmlConstants.QN_ENVELOPE)) {
            Object sosGeometry = decodeXmlElement(XmlObject.Factory.parse(geometryCursor.getDomNode()));
            // }
            if (sosGeometry instanceof Geometry) {
                spatialFilter.setGeometry((Geometry) sosGeometry);
                spatialFilter.setValueReference(valueRef);
            }
        } else {
            throw unsupportedSpatialFilterOperand();
        }
        geometryCursor.dispose();
    } catch (XmlException xmle) {
        throw errorParsingSpatialFilter(xmle);
    }
    return spatialFilter;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) XmlException(org.apache.xmlbeans.XmlException) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) XmlObject(org.apache.xmlbeans.XmlObject) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 33 with Geometry

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

the class GmlDecoderv321 method parseCompositeSurfaceType.

private Geometry parseCompositeSurfaceType(CompositeSurfaceType xbCompositeSurface) throws DecodingException {
    SurfacePropertyType[] xbCurfaceProperties = xbCompositeSurface.getSurfaceMemberArray();
    int srid = -1;
    ArrayList<Polygon> polygons = new ArrayList<>(xbCurfaceProperties.length);
    if (xbCompositeSurface.getSrsName() != null) {
        srid = CRSHelper.parseSrsName(xbCompositeSurface.getSrsName());
    }
    for (SurfacePropertyType xbSurfaceProperty : xbCurfaceProperties) {
        AbstractSurfaceType xbAbstractSurface = xbSurfaceProperty.getAbstractSurface();
        if (srid == -1 && xbAbstractSurface.getSrsName() != null) {
            srid = CRSHelper.parseSrsName(xbAbstractSurface.getSrsName());
        }
        if (xbAbstractSurface instanceof PolygonType) {
            polygons.add((Polygon) parsePolygonType((PolygonType) xbAbstractSurface));
        } else {
            throw new DecodingException("The FeatureType %s is not supportted! Only PolygonType", xbAbstractSurface);
        }
    }
    if (polygons.isEmpty()) {
        throw new DecodingException("The FeatureType: %s does not contain any member!", xbCompositeSurface);
    }
    srid = setDefaultForUnsetSrid(srid);
    GeometryFactory factory = new GeometryFactory();
    Geometry geom = factory.createMultiPolygon(polygons.toArray(new Polygon[polygons.size()]));
    geom.setSRID(srid);
    return geom;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) AbstractSurfaceType(net.opengis.gml.x32.AbstractSurfaceType) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) SurfacePropertyType(net.opengis.gml.x32.SurfacePropertyType) ArrayList(java.util.ArrayList) PolygonType(net.opengis.gml.x32.PolygonType) DecodingException(org.n52.svalbard.decode.exception.DecodingException) Polygon(org.locationtech.jts.geom.Polygon)

Example 34 with Geometry

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

the class GmlEncoderv321 method createMultiPointFromJtsGeometry.

private void createMultiPointFromJtsGeometry(MultiPoint geom, MultiPointType xbMultiPoint, String id) throws EncodingException {
    for (int i = 0; i < geom.getNumGeometries(); i++) {
        Geometry geometry = geom.getGeometryN(i);
        if (geometry instanceof Point) {
            PointType pt = xbMultiPoint.addNewPointMember().addNewPoint();
            pt.setId(id + "_" + i);
            createPointFromJtsGeometry((Point) geometry, pt);
        }
    }
}
Also used : EnvelopeOrGeometry(org.n52.shetland.util.EnvelopeOrGeometry) Geometry(org.locationtech.jts.geom.Geometry) AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) MultiPointType(net.opengis.gml.x32.MultiPointType) PointType(net.opengis.gml.x32.PointType) MultiPoint(org.locationtech.jts.geom.MultiPoint) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) Point(org.locationtech.jts.geom.Point)

Aggregations

Geometry (org.locationtech.jts.geom.Geometry)34 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)9 XmlObject (org.apache.xmlbeans.XmlObject)8 ValueGeometry (org.h2.value.ValueGeometry)7 Coordinate (org.locationtech.jts.geom.Coordinate)7 XmlException (org.apache.xmlbeans.XmlException)6 GeometryValue (org.n52.shetland.ogc.om.values.GeometryValue)6 Test (org.junit.Test)5 Point (org.locationtech.jts.geom.Point)5 AbstractGeometry (org.n52.shetland.ogc.gml.AbstractGeometry)5 DecodingException (org.n52.svalbard.decode.exception.DecodingException)4 EncodingException (org.n52.svalbard.encode.exception.EncodingException)4 XmlCursor (org.apache.xmlbeans.XmlCursor)3 Envelope (org.locationtech.jts.geom.Envelope)3 ReferenceType (org.n52.shetland.ogc.gml.ReferenceType)3 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 MultiPointType (net.opengis.gml.x32.MultiPointType)2