Search in sources :

Example 16 with Geometry

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

the class GmlEncoderv311 method encode.

@Override
public XmlObject encode(Object element, EncodingContext ctx) throws EncodingException {
    XmlObject encodedObject = null;
    if (element instanceof Time) {
        encodedObject = createTime((Time) element, ctx);
    } else if (element instanceof Geometry) {
        encodedObject = createPosition((Geometry) element, ctx.get(XmlBeansEncodingFlags.GMLID));
    } else if (element instanceof CategoryValue) {
        encodedObject = createReferenceTypeForCategroyValue((CategoryValue) element);
    } else if (element instanceof org.n52.shetland.ogc.gml.ReferenceType) {
        encodedObject = createReferencType((org.n52.shetland.ogc.gml.ReferenceType) element);
    } else if (element instanceof CodeWithAuthority) {
        encodedObject = createCodeWithAuthorityType((CodeWithAuthority) element);
    } else if (element instanceof QuantityValue) {
        encodedObject = createMeasureType((QuantityValue) element);
    } else if (element instanceof org.n52.shetland.ogc.gml.CodeType) {
        encodedObject = createCodeType((org.n52.shetland.ogc.gml.CodeType) element);
    } else if (element instanceof AbstractFeature) {
        encodedObject = createFeature((AbstractFeature) element);
    } else if (element instanceof ReferencedEnvelope) {
        encodedObject = createEnvelope((ReferencedEnvelope) element);
    } else if (element instanceof EnvelopeOrGeometry) {
        EnvelopeOrGeometry geom = (EnvelopeOrGeometry) element;
        if (geom.getGeometry().isPresent()) {
            encodedObject = createPosition(geom.getGeometry().get(), ctx.get(XmlBeansEncodingFlags.GMLID));
        } else if (geom.getEnvelope().isPresent()) {
            encodedObject = createEnvelope(geom.getEnvelope().get());
        } else {
            throw new UnsupportedEncoderInputException(this, element);
        }
    } else if (element instanceof GenericMetaData) {
        encodedObject = createGenericMetaData((GenericMetaData) element, ctx);
    } else {
        throw new UnsupportedEncoderInputException(this, element);
    }
    XmlHelper.validateDocument(encodedObject, EncodingException::new);
    return encodedObject;
}
Also used : GenericMetaData(org.n52.shetland.ogc.gml.GenericMetaData) EncodingException(org.n52.svalbard.encode.exception.EncodingException) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) Time(org.n52.shetland.ogc.gml.time.Time) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) Geometry(org.locationtech.jts.geom.Geometry) EnvelopeOrGeometry(org.n52.shetland.util.EnvelopeOrGeometry) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) EnvelopeOrGeometry(org.n52.shetland.util.EnvelopeOrGeometry) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue) CodeType(net.opengis.gml.CodeType) XmlObject(org.apache.xmlbeans.XmlObject) CodeWithAuthority(org.n52.shetland.ogc.gml.CodeWithAuthority)

Example 17 with Geometry

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

the class GmlEncoderv321 method createPosition.

private XmlObject createPosition(Geometry geom, EncodingContext ctx) throws EncodingException {
    String foiId = ctx.<String>get(XmlBeansEncodingFlags.GMLID).orElse(null);
    if (geom instanceof Point) {
        PointType xbPoint = PointType.Factory.newInstance(getXmlOptions());
        xbPoint.setId(getGmlID(geom, foiId));
        createPointFromJtsGeometry((Point) geom, xbPoint);
        if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
            PointDocument xbPointDoc = PointDocument.Factory.newInstance(getXmlOptions());
            xbPointDoc.setPoint(xbPoint);
            return xbPointDoc;
        } else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
            GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
            geometryPropertyType.setAbstractGeometry(xbPoint);
            geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_POINT_32, PointType.type);
            return geometryPropertyType;
        }
        return xbPoint;
    } else if (geom instanceof LineString) {
        LineStringType xbLineString = LineStringType.Factory.newInstance(getXmlOptions());
        xbLineString.setId(getGmlID(geom, foiId));
        createLineStringFromJtsGeometry((LineString) geom, xbLineString);
        if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
            LineStringDocument xbLineStringDoc = LineStringDocument.Factory.newInstance(getXmlOptions());
            xbLineStringDoc.setLineString(xbLineString);
            return xbLineStringDoc;
        } else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
            GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
            geometryPropertyType.setAbstractGeometry(xbLineString);
            geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_LINESTRING_32, LineStringType.type);
            return geometryPropertyType;
        }
        return xbLineString;
    } else if (geom instanceof MultiLineString) {
        MultiCurveType xbMultiCurve = MultiCurveType.Factory.newInstance(getXmlOptions());
        xbMultiCurve.setId(getGmlID(geom, foiId));
        xbMultiCurve.setSrsName(getSrsName(geom));
        for (int i = 0; i < geom.getNumGeometries(); ++i) {
            Geometry lineString = geom.getGeometryN(i);
            LineStringType xbLineString = LineStringType.Factory.newInstance(getXmlOptions());
            xbLineString.setId(getGmlID(geom, foiId));
            xbLineString.addNewPosList().setStringValue(JTSHelper.getCoordinatesString(lineString));
            CurvePropertyType xbCurveMember = xbMultiCurve.addNewCurveMember();
            xbCurveMember.addNewAbstractCurve().set(xbLineString);
            XmlHelper.substituteElement(xbCurveMember.getAbstractCurve(), xbLineString);
        }
        if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
            MultiCurveDocument xbMultiCurveDoc = MultiCurveDocument.Factory.newInstance(getXmlOptions());
            xbMultiCurveDoc.setMultiCurve(xbMultiCurve);
            return xbMultiCurveDoc;
        } else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
            GeometryPropertyType xbGeometryProperty = GeometryPropertyType.Factory.newInstance(getXmlOptions());
            xbGeometryProperty.addNewAbstractGeometry().set(xbMultiCurve);
            XmlHelper.substituteElement(xbGeometryProperty.getAbstractGeometry(), xbMultiCurve);
            return xbGeometryProperty;
        } else {
            return xbMultiCurve;
        }
    } else if (geom instanceof Polygon) {
        PolygonType xbPolygon = PolygonType.Factory.newInstance(getXmlOptions());
        xbPolygon.setId(getGmlID(geom, foiId));
        createPolygonFromJtsGeometry((Polygon) geom, xbPolygon);
        if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
            PolygonDocument xbPolygonDoc = PolygonDocument.Factory.newInstance(getXmlOptions());
            xbPolygonDoc.setPolygon(xbPolygon);
            return xbPolygonDoc;
        } else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
            GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
            geometryPropertyType.setAbstractGeometry(xbPolygon);
            geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_POLYGON_32, PolygonType.type);
            return geometryPropertyType;
        }
        return xbPolygon;
    } else if (geom instanceof MultiPoint) {
        MultiPointType xbMultiPoint = MultiPointType.Factory.newInstance(getXmlOptions());
        String id = getGmlID(geom, foiId);
        xbMultiPoint.setId(id);
        createMultiPointFromJtsGeometry((MultiPoint) geom, xbMultiPoint, id);
        if (ctx.has(XmlBeansEncodingFlags.DOCUMENT)) {
            MultiPointDocument xbMultiPointDoc = MultiPointDocument.Factory.newInstance(getXmlOptions());
            xbMultiPointDoc.setMultiPoint(xbMultiPoint);
            return xbMultiPointDoc;
        } else if (ctx.has(XmlBeansEncodingFlags.PROPERTY_TYPE)) {
            GeometryPropertyType geometryPropertyType = GeometryPropertyType.Factory.newInstance(getXmlOptions());
            geometryPropertyType.setAbstractGeometry(xbMultiPoint);
            geometryPropertyType.getAbstractGeometry().substitute(GmlConstants.QN_MULTI_POINT_32, PolygonType.type);
            return geometryPropertyType;
        }
        return xbMultiPoint;
    } else {
        throw new UnsupportedEncoderInputException(this, geom);
    }
}
Also used : MultiPoint(org.locationtech.jts.geom.MultiPoint) MultiLineString(org.locationtech.jts.geom.MultiLineString) PolygonDocument(net.opengis.gml.x32.PolygonDocument) MultiPointDocument(net.opengis.gml.x32.MultiPointDocument) PointDocument(net.opengis.gml.x32.PointDocument) MultiCurveType(net.opengis.gml.x32.MultiCurveType) MultiCurveDocument(net.opengis.gml.x32.MultiCurveDocument) PolygonType(net.opengis.gml.x32.PolygonType) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) MultiPoint(org.locationtech.jts.geom.MultiPoint) Point(org.locationtech.jts.geom.Point) LineStringType(net.opengis.gml.x32.LineStringType) MultiPointType(net.opengis.gml.x32.MultiPointType) MultiPointDocument(net.opengis.gml.x32.MultiPointDocument) MultiPoint(org.locationtech.jts.geom.MultiPoint) Point(org.locationtech.jts.geom.Point) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) EnvelopeOrGeometry(org.n52.shetland.util.EnvelopeOrGeometry) Geometry(org.locationtech.jts.geom.Geometry) AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) LineStringDocument(net.opengis.gml.x32.LineStringDocument) MultiPointType(net.opengis.gml.x32.MultiPointType) PointType(net.opengis.gml.x32.PointType) CurvePropertyType(net.opengis.gml.x32.CurvePropertyType) Polygon(org.locationtech.jts.geom.Polygon) GeometryPropertyType(net.opengis.gml.x32.GeometryPropertyType)

Example 18 with Geometry

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

the class SamplingEncoderv20 method encodeShape.

private void encodeShape(ShapeType xbShape, AbstractSamplingFeature sampFeat) throws EncodingException {
    Encoder<XmlObject, Geometry> encoder = getEncoder(GmlConstants.NS_GML_32, sampFeat.getGeometry());
    if (encoder != null) {
        XmlObject xmlObject = encoder.encode(sampFeat.getGeometry(), EncodingContext.of(XmlBeansEncodingFlags.GMLID, sampFeat.getGmlId()));
        if (xbShape.isSetAbstractGeometry()) {
            xbShape.getAbstractGeometry().set(xmlObject);
        } else {
            xbShape.addNewAbstractGeometry().set(xmlObject);
        }
        XmlHelper.substituteElement(xbShape.getAbstractGeometry(), xmlObject);
    } else {
        throw new EncodingException("Error while encoding geometry for feature, needed encoder is missing!");
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlObject(org.apache.xmlbeans.XmlObject)

Example 19 with Geometry

use of org.locationtech.jts.geom.Geometry in project h2database by h2database.

the class MVSpatialIndex method getKey.

private SpatialKey getKey(SearchRow row) {
    Value v = row.getValue(columnIds[0]);
    if (v == ValueNull.INSTANCE) {
        return new SpatialKey(row.getKey());
    }
    Geometry g = ((ValueGeometry) v.convertTo(Value.GEOMETRY)).getGeometryNoCopy();
    Envelope env = g.getEnvelopeInternal();
    return new SpatialKey(row.getKey(), (float) env.getMinX(), (float) env.getMaxX(), (float) env.getMinY(), (float) env.getMaxY());
}
Also used : SpatialKey(org.h2.mvstore.rtree.SpatialKey) ValueGeometry(org.h2.value.ValueGeometry) Geometry(org.locationtech.jts.geom.Geometry) ValueGeometry(org.h2.value.ValueGeometry) Value(org.h2.value.Value) VersionedValue(org.h2.mvstore.db.TransactionStore.VersionedValue) Envelope(org.locationtech.jts.geom.Envelope)

Example 20 with Geometry

use of org.locationtech.jts.geom.Geometry in project h2database by h2database.

the class TestSpatial method testEquals.

/**
 * Test equality method on ValueGeometry
 */
private void testEquals() {
    // 3d equality test
    ValueGeometry geom3d = ValueGeometry.get("POLYGON ((67 13 6, 67 18 5, 59 18 4, 59 13 6,  67 13 6))");
    ValueGeometry geom2d = ValueGeometry.get("POLYGON ((67 13, 67 18, 59 18, 59 13,  67 13))");
    assertFalse(geom3d.equals(geom2d));
    // SRID equality test
    GeometryFactory geometryFactory = new GeometryFactory();
    Geometry geometry = geometryFactory.createPoint(new Coordinate(0, 0));
    geometry.setSRID(27572);
    ValueGeometry valueGeometry = ValueGeometry.getFromGeometry(geometry);
    Geometry geometry2 = geometryFactory.createPoint(new Coordinate(0, 0));
    geometry2.setSRID(5326);
    ValueGeometry valueGeometry2 = ValueGeometry.getFromGeometry(geometry2);
    assertFalse(valueGeometry.equals(valueGeometry2));
    ValueGeometry valueGeometry3 = ValueGeometry.getFromGeometry(geometry);
    assertEquals(valueGeometry, valueGeometry3);
    assertEquals(geometry.getSRID(), valueGeometry3.getGeometry().getSRID());
    // Check illegal geometry (no WKB representation)
    try {
        ValueGeometry.get("POINT EMPTY");
        fail("expected this to throw IllegalArgumentException");
    } catch (IllegalArgumentException ex) {
    // expected
    }
}
Also used : ValueGeometry(org.h2.value.ValueGeometry) Geometry(org.locationtech.jts.geom.Geometry) ValueGeometry(org.h2.value.ValueGeometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate)

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