Search in sources :

Example 6 with LineString

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

the class GmlEncoderv321 method createLineStringFromJtsGeometry.

/**
 * Creates a XML LineString from a SOS LineString.
 *
 * @param jtsLineString
 *            SOS LineString
 * @param xbLst
 *            XML LinetSring
 */
private void createLineStringFromJtsGeometry(LineString jtsLineString, LineStringType xbLst) {
    String srsName = getSrsName(jtsLineString);
    xbLst.setSrsName(srsName);
    DirectPositionListType xbPosList = xbLst.addNewPosList();
    xbPosList.setSrsName(srsName);
    xbPosList.setStringValue(JTSHelper.getCoordinatesString(jtsLineString));
}
Also used : DirectPositionListType(net.opengis.gml.x32.DirectPositionListType) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString)

Example 7 with LineString

use of org.locationtech.jts.geom.LineString 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)

Example 8 with LineString

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

the class GeoJSONDecoder method decodeMultiLineString.

protected MultiLineString decodeMultiLineString(JsonNode node, GeometryFactory fac) throws GeoJSONDecodingException {
    JsonNode coordinates = requireCoordinates(node);
    LineString[] lineStrings = new LineString[coordinates.size()];
    for (int i = 0; i < coordinates.size(); ++i) {
        JsonNode coords = coordinates.get(i);
        lineStrings[i] = fac.createLineString(decodeCoordinates(coords));
    }
    return fac.createMultiLineString(lineStrings);
}
Also used : MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString) JsonNode(com.fasterxml.jackson.databind.JsonNode) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 9 with LineString

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

the class ProfileObservation method setFeatureGeometry.

private void setFeatureGeometry(List<Coordinate> coordinates, int srid) {
    AbstractFeature featureOfInterest = getObservationConstellation().getFeatureOfInterest();
    if (featureOfInterest instanceof AbstractSamplingFeature) {
        AbstractSamplingFeature sf = (AbstractSamplingFeature) featureOfInterest;
        Coordinate[] coords = coordinates.toArray(new Coordinate[0]);
        try {
            LineString lineString = new GeometryFactory().createLineString(coords);
            lineString.setSRID(srid);
            sf.setGeometry(lineString);
            sf.setFeatureType(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_CURVE);
        } catch (InvalidSridException e) {
        // TODO
        }
    }
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) InvalidSridException(org.n52.shetland.ogc.om.features.samplingFeatures.InvalidSridException) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature)

Example 10 with LineString

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

the class TrajectoryObservation method checkForFeature.

/**
 * Create geometry for featureOfInterest from
 * {@link TimeLocationValueTriple}s
 *
 * @param values
 *            The {@link TimeLocationValueTriple}s to check for
 *            featureOfInterest
 */
private void checkForFeature(List<TimeLocationValueTriple> values) {
    AbstractFeature featureOfInterest = getObservationConstellation().getFeatureOfInterest();
    if (featureOfInterest instanceof AbstractSamplingFeature) {
        AbstractSamplingFeature sf = (AbstractSamplingFeature) featureOfInterest;
        Coordinate[] coords = getCoordinates(values);
        int srid = 0;
        if (sf.isSetGeometry()) {
            srid = sf.getGeometry().getSRID();
            coords = (Coordinate[]) ArrayUtils.addAll(sf.getGeometry().getCoordinates(), coords);
        } else {
            TimeLocationValueTriple next = values.iterator().next();
            if (next.isSetLocation()) {
                srid = next.getLocation().getSRID();
            }
        }
        try {
            if (coords.length == 1) {
                Point point = new GeometryFactory().createPoint(coords[0]);
                point.setSRID(srid);
                sf.setGeometry(point);
            } else if (coords.length > 1) {
                LineString lineString = new GeometryFactory().createLineString(coords);
                lineString.setSRID(srid);
                sf.setGeometry(lineString);
            }
        } catch (InvalidSridException e) {
        // TODO
        }
    }
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) InvalidSridException(org.n52.shetland.ogc.om.features.samplingFeatures.InvalidSridException) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) Point(org.locationtech.jts.geom.Point) Point(org.locationtech.jts.geom.Point) TimeLocationValueTriple(org.n52.shetland.ogc.om.TimeLocationValueTriple)

Aggregations

LineString (org.locationtech.jts.geom.LineString)13 Point (org.locationtech.jts.geom.Point)8 MultiLineString (org.locationtech.jts.geom.MultiLineString)7 Polygon (org.locationtech.jts.geom.Polygon)5 MultiPoint (org.locationtech.jts.geom.MultiPoint)4 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)3 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)3 DirectPositionListType (net.opengis.gml.x32.DirectPositionListType)2 XmlCursor (org.apache.xmlbeans.XmlCursor)2 Test (org.junit.Test)2 Coordinate (org.locationtech.jts.geom.Coordinate)2 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)2 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)2 InvalidSridException (org.n52.shetland.ogc.om.features.samplingFeatures.InvalidSridException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 AbstractRingPropertyType (net.opengis.gml.AbstractRingPropertyType)1 AbstractRingType (net.opengis.gml.AbstractRingType)1 DirectPositionListType (net.opengis.gml.DirectPositionListType)1