Search in sources :

Example 1 with PrecisionModel

use of org.locationtech.jts.geom.PrecisionModel in project h2database by h2database.

the class ValueGeometry method get.

/**
 * Get or create a geometry value for the given geometry.
 *
 * @param s the WKT representation of the geometry
 * @param srid the srid of the object
 * @return the value
 */
public static ValueGeometry get(String s, int srid) {
    try {
        GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), srid);
        Geometry g = new WKTReader(geometryFactory).read(s);
        return get(g);
    } catch (ParseException ex) {
        throw DbException.convert(ex);
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) PrecisionModel(org.locationtech.jts.geom.PrecisionModel) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader)

Example 2 with PrecisionModel

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

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

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

use of org.locationtech.jts.geom.PrecisionModel 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)6 PrecisionModel (org.locationtech.jts.geom.PrecisionModel)6 Coordinate (org.locationtech.jts.geom.Coordinate)4 Geometry (org.locationtech.jts.geom.Geometry)2 ParseException (org.locationtech.jts.io.ParseException)2 WKTReader (org.locationtech.jts.io.WKTReader)2 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Point (org.locationtech.jts.geom.Point)1 WKTWriter (org.locationtech.jts.io.WKTWriter)1 ReferenceType (org.n52.shetland.ogc.gml.ReferenceType)1 Time (org.n52.shetland.ogc.gml.time.Time)1 PointValuePair (org.n52.shetland.ogc.om.PointValuePair)1 GeometryValue (org.n52.shetland.ogc.om.values.GeometryValue)1