Search in sources :

Example 11 with GeometryFactory

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

the class JTSHelperTest method shouldReverseMultiPolygon.

@Test
public void shouldReverseMultiPolygon() throws OwsExceptionReport {
    final GeometryFactory factory = getGeometryFactoryForSRID(4326);
    testReverse(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)) }) }));
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Polygon(org.locationtech.jts.geom.Polygon) Test(org.junit.Test)

Example 12 with GeometryFactory

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

the class JTSHelperTest method factoryFromSridShouldSetSrid.

@Test
public void factoryFromSridShouldSetSrid() {
    GeometryFactory factory = getGeometryFactoryForSRID(4326);
    assertThat(factory, is(notNullValue()));
    Geometry 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 13 with GeometryFactory

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

the class JTSHelperTest method shouldReverseMultiLineString.

@Test
public void shouldReverseMultiLineString() throws OwsExceptionReport {
    final GeometryFactory factory = getGeometryFactoryForSRID(4326);
    testReverse(factory.createMultiLineString(new LineString[] { factory.createLineString(randomCoordinateRing(21)), factory.createLineString(randomCoordinateRing(21)), factory.createLineString(randomCoordinateRing(15)) }));
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) LineString(org.locationtech.jts.geom.LineString) Test(org.junit.Test)

Example 14 with GeometryFactory

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

the class ODataFesParserTest method setup.

@Before
public void setup() {
    this.parser = new ODataFesParser();
    this.geometryFactory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING_SINGLE), 4326);
    this.polygon = this.geometryFactory.createPolygon(new Coordinate[] { new Coordinate(-15.46, 77.98), new Coordinate(-93.51, 38.27), new Coordinate(47.10, -1.05), new Coordinate(58.71, 70.61), new Coordinate(-15.46, 77.98) });
    this.wktGeometry = new WKTWriter().write(polygon).replaceFirst(" ", "").replaceAll(", ", ",");
}
Also used : WKTWriter(org.locationtech.jts.io.WKTWriter) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) PrecisionModel(org.locationtech.jts.geom.PrecisionModel) Before(org.junit.Before)

Example 15 with GeometryFactory

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

the class ODataFesParser method parseGeometry.

/**
 * Parse the value expression as an {@code Geometry} in WKT or EWKT format. Geographies are handled as if they would
 * be geometries.
 *
 * @param val the geometry value
 *
 * @return the geometry
 *
 * @throws DecodingException if the geometry is invalid
 */
private static Geometry parseGeometry(ValueExpr val) throws DecodingException {
    String value = val.getValue();
    if (value.startsWith(GEOGRAPHY_TYPE)) {
        value = value.substring(GEOGRAPHY_TYPE.length());
    }
    if (value.startsWith(GEOMETRY_TYPE)) {
        value = value.substring(GEOMETRY_TYPE.length());
    }
    value = stripQuotes(value).toUpperCase();
    int srid = 4326;
    if (value.startsWith(SRID_PREFIX)) {
        int sep = value.indexOf(';');
        if (sep > SRID_PREFIX.length() && value.length() > sep) {
            try {
                srid = Integer.parseInt(value.substring(SRID_PREFIX.length(), sep));
            } catch (NumberFormatException ex) {
                throw invalidGeometry(val, ex);
            }
            value = value.substring(sep + 1);
        } else {
            throw invalidGeometry(val);
        }
    }
    PrecisionModel precisionModel = new PrecisionModel(PrecisionModel.FLOATING);
    GeometryFactory geometryFactory = new GeometryFactory(precisionModel, srid);
    WKTReader wktReader = new WKTReader(geometryFactory);
    try {
        return wktReader.read(value);
    } catch (ParseException ex) {
        throw invalidGeometry(val, ex);
    }
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) PrecisionModel(org.locationtech.jts.geom.PrecisionModel) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader)

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