Search in sources :

Example 26 with Geometry

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

the class PointObservation method setValue.

@Override
public void setValue(ObservationValue<?> value) {
    if (value instanceof StreamingValue<?>) {
        super.setValue(value);
    } else if (value.getValue() instanceof CvDiscretePointCoverage) {
        super.setValue(value);
    } else {
        CvDiscretePointCoverage cvDiscretePointCoverage = new CvDiscretePointCoverage(getObservationID());
        cvDiscretePointCoverage.setRangeType(new ReferenceType(getObservationConstellation().getObservablePropertyIdentifier()));
        cvDiscretePointCoverage.setUnit(((AbstractObservationValue<?>) value).getUnit());
        Geometry geometry = null;
        String domainExtent = "";
        if (isSetSpatialFilteringProfileParameter() && getSpatialFilteringProfileParameter().getValue() instanceof GeometryValue) {
            GeometryValue geometryValue = (GeometryValue) getSpatialFilteringProfileParameter().getValue();
            geometry = getSpatialFilteringProfileParameter().getValue().getValue();
            domainExtent = geometryValue.getGmlId();
        } else if (checkForFeatureGeometry(this)) {
            geometry = getGeometryFromFeature(this);
            domainExtent = getObservationConstellation().getFeatureOfInterest().getGmlId();
        }
        if (geometry != null) {
            cvDiscretePointCoverage.setDomainExtent("#" + geometry.getGeometryType() + "_" + domainExtent);
            Point point = null;
            if (geometry instanceof Point) {
                point = (Point) geometry;
            } else {
                point = geometry.getCentroid();
            }
            cvDiscretePointCoverage.setValue(new PointValuePair(point, value.getValue()));
        }
        super.setValue(new SingleObservationValue<>(value.getPhenomenonTime(), cvDiscretePointCoverage));
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) CvDiscretePointCoverage(org.n52.shetland.ogc.om.values.CvDiscretePointCoverage) AbstractObservationValue(org.n52.shetland.ogc.om.AbstractObservationValue) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) StreamingValue(org.n52.shetland.ogc.om.StreamingValue) Point(org.locationtech.jts.geom.Point) ReferenceType(org.n52.shetland.ogc.gml.ReferenceType) PointValuePair(org.n52.shetland.ogc.om.PointValuePair)

Example 27 with Geometry

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

the class JTSHelperTest method factoryFromGeometryShouldSetSrid.

@Test
public void factoryFromGeometryShouldSetSrid() {
    GeometryFactory factory = getGeometryFactoryForSRID(4326);
    assertThat(factory, is(notNullValue()));
    Geometry g = factory.createPoint(new Coordinate(1, 2));
    factory = getGeometryFactory(g);
    assertThat(factory, is(notNullValue()));
    g = factory.createPoint(new Coordinate(1, 2));
    assertThat(g, is(notNullValue()));
    assertThat(g.getSRID(), is(4326));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) JTSHelperForTesting.randomCoordinate(org.n52.shetland.util.JTSHelperForTesting.randomCoordinate) Test(org.junit.Test)

Example 28 with Geometry

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

the class GeoJSONTest method readWriteTest.

protected void readWriteTest(final Geometry geom) {
    try {
        JsonNode json = enc.encodeJSON(geom);
        Geometry parsed = dec.decodeJSON(json, false);
        JsonNode json2 = enc.encodeJSON(parsed);
        errors.checkThat(geom, is(equalTo(parsed)));
        errors.checkThat(json, is(ValidationMatchers.instanceOf(SchemaConstants.Common.GEOMETRY)));
        errors.checkThat(json2, is(ValidationMatchers.instanceOf(SchemaConstants.Common.GEOMETRY)));
        errors.checkThat(json, is(equalTo(json2)));
    } catch (EncodingException | DecodingException ex) {
        errors.addError(ex);
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) JSONEncodingException(org.n52.svalbard.encode.json.JSONEncodingException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) JsonNode(com.fasterxml.jackson.databind.JsonNode) GeoJSONDecodingException(org.n52.svalbard.coding.json.GeoJSONDecodingException) DecodingException(org.n52.svalbard.decode.exception.DecodingException)

Example 29 with Geometry

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

the class GeometryObservationDecodingTest method testObservation.

@Test
public void testObservation() {
    assertThat(observation, is(notNullValue()));
    final String type = observation.getObservationConstellation().getObservationType();
    assertThat(type, is(equalTo(OmConstants.OBS_TYPE_GEOMETRY_OBSERVATION)));
    final ObservationValue<?> value = observation.getValue();
    assertThat(value, is(instanceOf(SingleObservationValue.class)));
    assertThat(value.getPhenomenonTime(), is(instanceOf(TimeInstant.class)));
    TimeInstant pt = (TimeInstant) value.getPhenomenonTime();
    assertThat(pt.getValue(), is(equalTo(phenomenonTime)));
    assertThat(value.getValue(), is(instanceOf(GeometryValue.class)));
    GeometryValue v = (GeometryValue) value.getValue();
    assertThat(v.getUnit(), is(nullValue()));
    Geometry g = v.getValue();
    assertThat(g, is(instanceOf(LineString.class)));
    assertThat(g.getSRID(), is(2000));
    assertThat(g.getNumPoints(), is(2));
    assertThat(g.getCoordinates()[0], is(equalTo(new Coordinate(52, 7))));
    assertThat(g.getCoordinates()[1], is(equalTo(new Coordinate(51, 7))));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) TimeInstant(org.n52.shetland.ogc.gml.time.TimeInstant) Test(org.junit.Test)

Example 30 with Geometry

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

the class AbstractWmlEncoderv20 method createMonitoringPoint.

/**
 * Creates a WaterML 2.0 MonitoringPoint XML object from SOS feature object
 *
 * @param absFeature
 *            SOS feature
 * @return WaterML 2.0 MonitoringPoint XML object
 * @throws EncodingException
 *             If an error occurs
 */
protected XmlObject createMonitoringPoint(AbstractFeature absFeature) throws EncodingException {
    if (absFeature instanceof AbstractSamplingFeature) {
        AbstractSamplingFeature sampFeat = (AbstractSamplingFeature) absFeature;
        StringBuilder builder = new StringBuilder();
        builder.append("mp_");
        builder.append(JavaHelper.generateID(absFeature.getIdentifierCodeWithAuthority().getValue()));
        absFeature.setGmlId(builder.toString());
        MonitoringPointDocument monitoringPointDoc = MonitoringPointDocument.Factory.newInstance(getXmlOptions());
        if (sampFeat.isSetXml()) {
            try {
                XmlObject feature = XmlObject.Factory.parse(sampFeat.getXml());
                if (XmlHelper.getNamespace(feature).equals(WaterMLConstants.NS_WML_20)) {
                    if (feature instanceof MonitoringPointDocument) {
                        monitoringPointDoc = (MonitoringPointDocument) feature;
                    } else if (feature instanceof MonitoringPointType) {
                        monitoringPointDoc.setSFSpatialSamplingFeature((MonitoringPointType) feature);
                    }
                    XmlHelper.updateGmlIDs(monitoringPointDoc.getDomNode(), absFeature.getGmlId(), null);
                    return monitoringPointDoc;
                }
            } catch (XmlException xmle) {
                throw new EncodingException("Error while encoding GetFeatureOfInterest response, invalid samplingFeature description!", xmle);
            }
        }
        MonitoringPointType mpt = monitoringPointDoc.addNewMonitoringPoint();
        // set gml:id
        mpt.setId(absFeature.getGmlId());
        if (sampFeat.isSetIdentifier()) {
            XmlObject xmlObject = encodeGML(sampFeat.getIdentifierCodeWithAuthority());
            if (xmlObject != null) {
                mpt.addNewIdentifier().set(xmlObject);
            }
        }
        if (sampFeat.isSetName()) {
            for (CodeType sosName : sampFeat.getName()) {
                mpt.addNewName().set(encodeGML(sosName));
            }
        }
        if (sampFeat.isSetDescription()) {
            if (!mpt.isSetDescription()) {
                mpt.addNewDescription();
            }
            mpt.getDescription().setStringValue(sampFeat.getDescription());
        }
        // TODO: CHECK
        if (sampFeat.getSampledFeatures() != null && !sampFeat.getSampledFeatures().isEmpty()) {
            if (sampFeat.getSampledFeatures().size() == 1) {
                XmlObject encodeObjectToXml = encodeObjectToXml(GmlConstants.NS_GML_32, sampFeat.getSampledFeatures().get(0));
                mpt.addNewSampledFeature().set(encodeObjectToXml);
            } else {
                FeatureCollection featureCollection = new FeatureCollection();
                featureCollection.setGmlId("sampledFeatures_" + absFeature.getGmlId());
                for (AbstractFeature sampledFeature : sampFeat.getSampledFeatures()) {
                    featureCollection.addMember(sampledFeature);
                }
                XmlObject encodeObjectToXml = encodeGML(featureCollection);
                mpt.addNewSampledFeature().set(encodeObjectToXml);
            }
        } else {
            mpt.addNewSampledFeature().setHref(GmlConstants.NIL_UNKNOWN);
        }
        if (sampFeat.isSetParameter()) {
            addParameter(mpt, sampFeat);
        }
        // set position
        ShapeType xbShape = mpt.addNewShape();
        Encoder<XmlObject, Geometry> encoder = getEncoder(getEncoderKey(GmlConstants.NS_GML_32, sampFeat.getGeometry()));
        if (encoder != null) {
            XmlObject xmlObject = encoder.encode(sampFeat.getGeometry(), new EncodingContext().with(XmlBeansEncodingFlags.GMLID, absFeature.getGmlId()));
            xbShape.addNewAbstractGeometry().set(xmlObject);
            XmlHelper.substituteElement(xbShape.getAbstractGeometry(), xmlObject);
        } else {
            throw new EncodingException("Error while encoding geometry for feature, needed encoder is missing!");
        }
        if (absFeature instanceof WmlMonitoringPoint) {
            addMonitoringPointValues(mpt, (WmlMonitoringPoint) absFeature);
        }
        sampFeat.wasEncoded();
        return monitoringPointDoc;
    }
    throw new UnsupportedEncoderInputException(this, absFeature);
}
Also used : MonitoringPointType(net.opengis.waterml.x20.MonitoringPointType) MonitoringPointDocument(net.opengis.waterml.x20.MonitoringPointDocument) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) EncodingException(org.n52.svalbard.encode.exception.EncodingException) ShapeType(net.opengis.samplingSpatial.x20.ShapeType) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) WmlMonitoringPoint(org.n52.shetland.ogc.om.series.wml.WmlMonitoringPoint) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) Geometry(org.locationtech.jts.geom.Geometry) FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) XmlException(org.apache.xmlbeans.XmlException) CodeType(org.n52.shetland.ogc.gml.CodeType) XmlObject(org.apache.xmlbeans.XmlObject)

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