Search in sources :

Example 6 with GeometryFactory

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

the class ProfileValue method getGeometry.

public Geometry getGeometry() {
    if (isSetGeometry()) {
        TreeMap<Time, Coordinate> map = new TreeMap<>();
        int srid = -1;
        for (ProfileLevel level : getValue()) {
            if (level.isSetPhenomenonTime() && level.isSetLocation()) {
                if (srid < 0) {
                    srid = level.getLocation().getSRID();
                }
                map.put(level.getPhenomenonTime(), level.getLocation().getCoordinate());
            }
        }
        if (!map.isEmpty()) {
            if (new HashSet<>(map.values()).size() == 1) {
                return getValue().iterator().next().getLocation();
            } else {
                return new GeometryFactory(new PrecisionModel(), srid).createLineString(map.values().toArray(new Coordinate[1]));
            }
        }
    }
    return null;
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) Time(org.n52.shetland.ogc.gml.time.Time) PrecisionModel(org.locationtech.jts.geom.PrecisionModel) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet)

Example 7 with GeometryFactory

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

the class OmObservationTest method should_have_SpatialFilteringProfileParameter.

@Test
public final void should_have_SpatialFilteringProfileParameter() throws OwsExceptionReport, DecodingException {
    OmObservation omObservation = new OmObservation();
    NamedValue<Geometry> namedValue = new NamedValue<>();
    namedValue.setName(new ReferenceType(OmConstants.PARAM_NAME_SAMPLING_GEOMETRY));
    GeometryFactory fac = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326);
    namedValue.setValue(new GeometryValue(fac.createPoint(new Coordinate(34.5, 76.4))));
    // test no parameter is set
    assertFalse(omObservation.isSetParameter());
    assertFalse(omObservation.isSetSpatialFilteringProfileParameter());
    omObservation.addParameter(namedValue);
    // test with set SpatialFilteringProfile parameter
    assertTrue(omObservation.isSetParameter());
    assertTrue(omObservation.isSetSpatialFilteringProfileParameter());
    assertThat(omObservation.getSpatialFilteringProfileParameter(), is(equalTo(namedValue)));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) PrecisionModel(org.locationtech.jts.geom.PrecisionModel) ReferenceType(org.n52.shetland.ogc.gml.ReferenceType) Test(org.junit.Test)

Example 8 with GeometryFactory

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

the class JTSHelperTest method shouldReverseMultiPoint.

@Test
public void shouldReverseMultiPoint() throws OwsExceptionReport {
    final GeometryFactory factory = getGeometryFactoryForSRID(4326);
    testReverse(factory.createMultiPointFromCoords(randomCoordinates(20)));
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Test(org.junit.Test)

Example 9 with GeometryFactory

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

the class JTSHelperTest method shouldReverseGeometryCollection.

@Test
public void shouldReverseGeometryCollection() throws OwsExceptionReport {
    final GeometryFactory factory = getGeometryFactoryForSRID(4326);
    testReverse(factory.createGeometryCollection(new Geometry[] { factory.createMultiPolygon(new Polygon[] { factory.createPolygon(factory.createLinearRing(randomCoordinateRing(13)), new LinearRing[] { factory.createLinearRing(randomCoordinateRing(130)), factory.createLinearRing(randomCoordinateRing(4121)), factory.createLinearRing(randomCoordinateRing(12)) }), factory.createPolygon(factory.createLinearRing(randomCoordinateRing(8)), new LinearRing[] { factory.createLinearRing(randomCoordinateRing(1101)), factory.createLinearRing(randomCoordinateRing(413)), factory.createLinearRing(randomCoordinateRing(123)) }), factory.createPolygon(factory.createLinearRing(randomCoordinateRing(89)), new LinearRing[] { factory.createLinearRing(randomCoordinateRing(112)), factory.createLinearRing(randomCoordinateRing(4)), factory.createLinearRing(randomCoordinateRing(43)) }) }), factory.createMultiLineString(new LineString[] { factory.createLineString(randomCoordinateRing(21)), factory.createLineString(randomCoordinateRing(21)), factory.createLineString(randomCoordinateRing(15)) }), factory.createPolygon(factory.createLinearRing(randomCoordinateRing(10)), new LinearRing[] { factory.createLinearRing(randomCoordinateRing(10)), factory.createLinearRing(randomCoordinateRing(41)), factory.createLinearRing(randomCoordinateRing(13)) }), getGeometryFactoryForSRID(4326).createLineString(randomCoordinates(10)), getGeometryFactoryForSRID(4326).createLineString(randomCoordinates(10)) }));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) LinearRing(org.locationtech.jts.geom.LinearRing) Test(org.junit.Test)

Example 10 with GeometryFactory

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

the class JTSHelperTest method shouldReversePolygon.

@Test
public void shouldReversePolygon() throws OwsExceptionReport {
    final GeometryFactory factory = getGeometryFactoryForSRID(4326);
    testReverse(factory.createPolygon(factory.createLinearRing(randomCoordinateRing(10)), new LinearRing[] { factory.createLinearRing(randomCoordinateRing(10)), factory.createLinearRing(randomCoordinateRing(41)), factory.createLinearRing(randomCoordinateRing(13)) }));
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) LinearRing(org.locationtech.jts.geom.LinearRing) Test(org.junit.Test)

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