Search in sources :

Example 21 with GeometryFactory

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

Example 22 with GeometryFactory

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

the class MultiPointObservation method getEnvelope.

/**
 * Get the envelope from {@link PointValuePair}s {@link List}
 *
 * @param pointValuePairs
 *            The {@link PointValuePair}s to get the envelope from
 * @return The envelope of the {@link PointValuePair}s
 */
private Geometry getEnvelope(List<PointValuePair> pointValuePairs) {
    Envelope envelope = new Envelope();
    GeometryFactory factory = null;
    int srid = 4326;
    if (CollectionHelper.isNotEmpty(pointValuePairs)) {
        for (PointValuePair pointValuePair : pointValuePairs) {
            if (factory == null && pointValuePair.getPoint() != null) {
                factory = pointValuePair.getPoint().getFactory();
            }
            if (pointValuePair.getPoint().getSRID() > 0) {
                srid = pointValuePair.getPoint().getSRID();
            }
            envelope.expandToInclude(pointValuePair.getPoint().getEnvelopeInternal());
        }
    } else {
        if (isSetSpatialFilteringProfileParameter()) {
            Geometry geometry = getSpatialFilteringProfileParameter().getValue().getValue();
            if (geometry != null) {
                if (factory == null) {
                    factory = geometry.getFactory();
                }
                if (geometry.getSRID() > 0) {
                    srid = geometry.getSRID();
                }
                envelope.expandToInclude(geometry.getEnvelopeInternal());
            }
        } else {
            if (getObservationConstellation().getFeatureOfInterest() instanceof AbstractSamplingFeature && ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).isSetGeometry()) {
                Geometry geometry = ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).getGeometry();
                if (geometry != null) {
                    if (factory == null) {
                        factory = geometry.getFactory();
                    }
                    if (geometry.getSRID() > 0) {
                        srid = geometry.getSRID();
                    }
                    envelope.expandToInclude(geometry.getEnvelopeInternal());
                }
            }
        }
    }
    if (factory == null) {
        factory = JTSHelper.getGeometryFactoryForSRID(srid);
    }
    Geometry geometry = factory.toGeometry(envelope);
    geometry.setSRID(srid);
    return geometry;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) Envelope(org.locationtech.jts.geom.Envelope) Point(org.locationtech.jts.geom.Point) PointValuePair(org.n52.shetland.ogc.om.PointValuePair)

Example 23 with GeometryFactory

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

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

the class MultiPointCoverage method getExtent.

/**
 * Get the extent of all {@link Point}s
 *
 * @return The extent as {@link Polygon}
 */
public Polygon getExtent() {
    if (isSetValue()) {
        int srid = -1;
        List<Coordinate> coordinates = Lists.newLinkedList();
        for (PointValuePair pointValuePair : getValue()) {
            Point point = pointValuePair.getPoint();
            coordinates.add(point.getCoordinate());
            if (point.getSRID() != srid) {
                srid = point.getSRID();
            }
        }
        GeometryFactory geometryFactory;
        if (srid > 0) {
            geometryFactory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), srid);
        } else {
            geometryFactory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING));
        }
        return geometryFactory.createPolygon(coordinates.toArray(new Coordinate[coordinates.size()]));
    }
    return null;
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) PrecisionModel(org.locationtech.jts.geom.PrecisionModel) Point(org.locationtech.jts.geom.Point) Point(org.locationtech.jts.geom.Point) PointValuePair(org.n52.shetland.ogc.om.PointValuePair)

Example 25 with GeometryFactory

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

the class AbstractMultiPointCoverageTypeEncoder method encodeMultiPointDomain.

private void encodeMultiPointDomain(DiscreteCoverageType dct, PointValueLists pointValues) throws EncodingException {
    MultiPointDomainDocument mpdd = MultiPointDomainDocument.Factory.newInstance();
    DomainSetType mpdst = mpdd.addNewMultiPointDomain();
    GeometryFactory factory = pointValues.getPoints().get(0).getFactory();
    MultiPoint multiPoint = factory.createMultiPoint(pointValues.getPoints().toArray(new Point[0]));
    EncodingContext ec = EncodingContext.of(XmlBeansEncodingFlags.GMLID, JavaHelper.generateID(multiPoint.toString())).with(XmlBeansEncodingFlags.PROPERTY_TYPE, true);
    XmlObject encodedGeometry = encodeGML(multiPoint, ec);
    mpdst.addNewAbstractGeometry().set(encodedGeometry);
    substitute(mpdst.getAbstractGeometry(), encodedGeometry);
    dct.setDomainSet(mpdst);
}
Also used : MultiPoint(org.locationtech.jts.geom.MultiPoint) MultiPointDomainDocument(net.opengis.gml.x32.MultiPointDomainDocument) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) XmlObject(org.apache.xmlbeans.XmlObject) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) DomainSetType(net.opengis.gml.x32.DomainSetType)

Aggregations

GeometryFactory (org.locationtech.jts.geom.GeometryFactory)26 Coordinate (org.locationtech.jts.geom.Coordinate)13 Geometry (org.locationtech.jts.geom.Geometry)9 Test (org.junit.Test)8 PrecisionModel (org.locationtech.jts.geom.PrecisionModel)6 LineString (org.locationtech.jts.geom.LineString)4 Point (org.locationtech.jts.geom.Point)4 Envelope (org.locationtech.jts.geom.Envelope)3 Polygon (org.locationtech.jts.geom.Polygon)3 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)3 XmlObject (org.apache.xmlbeans.XmlObject)2 SimpleResultSet (org.h2.tools.SimpleResultSet)2 ValueGeometry (org.h2.value.ValueGeometry)2 LinearRing (org.locationtech.jts.geom.LinearRing)2 ParseException (org.locationtech.jts.io.ParseException)2 WKTReader (org.locationtech.jts.io.WKTReader)2 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)2 PointValuePair (org.n52.shetland.ogc.om.PointValuePair)2 InvalidSridException (org.n52.shetland.ogc.om.features.samplingFeatures.InvalidSridException)2 JTSHelperForTesting.randomCoordinate (org.n52.shetland.util.JTSHelperForTesting.randomCoordinate)2