Search in sources :

Example 16 with Coordinate

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

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

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

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

Aggregations

Coordinate (org.locationtech.jts.geom.Coordinate)19 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)13 Geometry (org.locationtech.jts.geom.Geometry)7 Test (org.junit.Test)4 PrecisionModel (org.locationtech.jts.geom.PrecisionModel)4 LineString (org.locationtech.jts.geom.LineString)3 Point (org.locationtech.jts.geom.Point)3 SimpleResultSet (org.h2.tools.SimpleResultSet)2 ValueGeometry (org.h2.value.ValueGeometry)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 GeometryValue (org.n52.shetland.ogc.om.values.GeometryValue)2 JTSHelperForTesting.randomCoordinate (org.n52.shetland.util.JTSHelperForTesting.randomCoordinate)2 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 Before (org.junit.Before)1