Search in sources :

Example 1 with Point

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

the class GeoJSONTest method testPointWithZCoordinate.

@Test
public void testPointWithZCoordinate() throws GeoJSONDecodingException, IOException {
    Point geometry = randomPoint(2000);
    geometry.apply(new RandomZCoordinateFilter());
    geometry.geometryChanged();
    readWriteTest(geometry);
}
Also used : Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) Test(org.junit.Test)

Example 2 with Point

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

the class SensorMLDecoderV101 method parseLocation.

/**
 * Parses the location
 *
 * @param location XML location
 *
 * @return SOS location
 *
 * @throws DecodingException if an error occurs
 */
private org.n52.shetland.ogc.sensorML.elements.SmlLocation parseLocation(final SmlLocation2 location) throws DecodingException {
    if (!location.isSetPoint()) {
        throw new DecodingException(XmlHelper.getLocalName(location), "Error while parsing the sml:location of the SensorML " + "(point is not set, only point is supported)!");
    }
    org.n52.shetland.ogc.sensorML.elements.SmlLocation sosSmlLocation = null;
    final Object point = decodeXmlElement(location.getPoint());
    if (point instanceof Point) {
        sosSmlLocation = new org.n52.shetland.ogc.sensorML.elements.SmlLocation((Point) point);
    }
    return sosSmlLocation;
}
Also used : DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlObject(org.apache.xmlbeans.XmlObject) Point(org.locationtech.jts.geom.Point)

Example 3 with Point

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

the class GmlEncoderv311 method createPosition.

private XmlObject createPosition(Geometry geom, Optional<Object> optional) throws UnsupportedEncoderInputException {
    String gmlId = (optional != null && optional.isPresent() && optional.get() instanceof String) ? (String) optional.get() : null;
    if (geom instanceof Point) {
        PointType xbPoint = PointType.Factory.newInstance(getXmlOptions());
        if (gmlId != null) {
            xbPoint.setId(geom.getGeometryType() + "_" + gmlId);
        }
        createPointFromJtsGeometry((Point) geom, xbPoint);
        return xbPoint;
    } else if (geom instanceof LineString) {
        LineStringType xbLineString = LineStringType.Factory.newInstance(getXmlOptions());
        if (gmlId != null) {
            xbLineString.setId(geom.getGeometryType() + "_" + gmlId);
        }
        createLineStringFromJtsGeometry((LineString) geom, xbLineString);
        return xbLineString;
    } else if (geom instanceof Polygon) {
        PolygonType xbPolygon = PolygonType.Factory.newInstance(getXmlOptions());
        if (gmlId != null) {
            xbPolygon.setId(geom.getGeometryType() + "_" + gmlId);
        }
        createPolygonFromJtsGeometry((Polygon) geom, xbPolygon);
        return xbPolygon;
    } else {
        throw new UnsupportedEncoderInputException(this, geom);
    }
}
Also used : LineString(org.locationtech.jts.geom.LineString) PointType(net.opengis.gml.PointType) PolygonType(net.opengis.gml.PolygonType) LineString(org.locationtech.jts.geom.LineString) Point(org.locationtech.jts.geom.Point) LineStringType(net.opengis.gml.LineStringType) Polygon(org.locationtech.jts.geom.Polygon) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 4 with Point

use of org.locationtech.jts.geom.Point 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 5 with Point

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

the class SamplingEncoderv100 method createFeature.

private XmlObject createFeature(AbstractFeature absFeature) throws EncodingException {
    if (absFeature instanceof AbstractSamplingFeature) {
        AbstractSamplingFeature sampFeat = (AbstractSamplingFeature) absFeature;
        if (sampFeat.getFeatureType().equals(SfConstants.FT_SAMPLINGPOINT) || sampFeat.getFeatureType().equals(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT) || sampFeat.getGeometry() instanceof Point) {
            SamplingPointDocument xbSamplingPointDoc = SamplingPointDocument.Factory.newInstance(getXmlOptions());
            SamplingPointType xbSamplingPoint = xbSamplingPointDoc.addNewSamplingPoint();
            addValuesToFeature(xbSamplingPoint, sampFeat);
            XmlObject xbGeomety = getEncodedGeometry(sampFeat.getGeometry(), absFeature.getGmlId());
            xbSamplingPoint.addNewPosition().addNewPoint().set(xbGeomety);
            sampFeat.wasEncoded();
            return xbSamplingPointDoc;
        } else if (sampFeat.getFeatureType().equals(SfConstants.FT_SAMPLINGCURVE) || sampFeat.getFeatureType().equals(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_CURVE) || sampFeat.getGeometry() instanceof LineString) {
            SamplingCurveDocument xbSamplingCurveDoc = SamplingCurveDocument.Factory.newInstance(getXmlOptions());
            SamplingCurveType xbSamplingCurve = xbSamplingCurveDoc.addNewSamplingCurve();
            addValuesToFeature(xbSamplingCurve, sampFeat);
            XmlObject xbGeomety = getEncodedGeometry(sampFeat.getGeometry(), absFeature.getGmlId());
            xbSamplingCurve.addNewShape().addNewCurve().set(xbGeomety);
            sampFeat.wasEncoded();
            return xbSamplingCurveDoc;
        } else if (sampFeat.getFeatureType().equals(SfConstants.FT_SAMPLINGSURFACE) || sampFeat.getFeatureType().equals(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_SURFACE) || sampFeat.getGeometry() instanceof Polygon) {
            SamplingSurfaceDocument xbSamplingSurfaceDoc = SamplingSurfaceDocument.Factory.newInstance(getXmlOptions());
            SamplingSurfaceType xbSamplingSurface = xbSamplingSurfaceDoc.addNewSamplingSurface();
            addValuesToFeature(xbSamplingSurface, sampFeat);
            XmlObject xbGeomety = getEncodedGeometry(sampFeat.getGeometry(), absFeature.getGmlId());
            xbSamplingSurface.addNewShape().addNewSurface().set(xbGeomety);
            sampFeat.wasEncoded();
            return xbSamplingSurfaceDoc;
        }
    } else if (absFeature instanceof FeatureCollection) {
        createFeatureCollection((FeatureCollection) absFeature);
    }
    throw new UnsupportedEncoderInputException(this, absFeature);
}
Also used : SamplingSurfaceType(net.opengis.sampling.x10.SamplingSurfaceType) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) Point(org.locationtech.jts.geom.Point) SamplingCurveDocument(net.opengis.sampling.x10.SamplingCurveDocument) SamplingCurveType(net.opengis.sampling.x10.SamplingCurveType) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) SamplingPointDocument(net.opengis.sampling.x10.SamplingPointDocument) LineString(org.locationtech.jts.geom.LineString) FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) SamplingPointType(net.opengis.sampling.x10.SamplingPointType) XmlObject(org.apache.xmlbeans.XmlObject) SamplingSurfaceDocument(net.opengis.sampling.x10.SamplingSurfaceDocument) Polygon(org.locationtech.jts.geom.Polygon)

Aggregations

Point (org.locationtech.jts.geom.Point)13 MultiPoint (org.locationtech.jts.geom.MultiPoint)6 Geometry (org.locationtech.jts.geom.Geometry)4 LineString (org.locationtech.jts.geom.LineString)4 XmlObject (org.apache.xmlbeans.XmlObject)3 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)3 Polygon (org.locationtech.jts.geom.Polygon)3 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)3 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)3 MultiPointType (net.opengis.gml.x32.MultiPointType)2 PointType (net.opengis.gml.x32.PointType)2 Coordinate (org.locationtech.jts.geom.Coordinate)2 AbstractGeometry (org.n52.shetland.ogc.gml.AbstractGeometry)2 PointValuePair (org.n52.shetland.ogc.om.PointValuePair)2 EnvelopeOrGeometry (org.n52.shetland.util.EnvelopeOrGeometry)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 LineStringType (net.opengis.gml.LineStringType)1 PointType (net.opengis.gml.PointType)1 PolygonType (net.opengis.gml.PolygonType)1