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);
}
}
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;
}
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)));
}
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(", ", ",");
}
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);
}
}
Aggregations