use of org.locationtech.jts.geom.Coordinate in project h2database by h2database.
the class TestSpatial method pointTable.
/**
* This method is called via reflection from the database.
*
* @param x the x position of the point
* @param y the y position of the point
* @return a result set with this point
*/
public static ResultSet pointTable(double x, double y) {
GeometryFactory factory = new GeometryFactory();
SimpleResultSet rs = new SimpleResultSet();
rs.addColumn("THE_GEOM", Types.JAVA_OBJECT, "GEOMETRY", 0, 0);
rs.addRow(factory.createPoint(new Coordinate(x, y)));
return rs;
}
use of org.locationtech.jts.geom.Coordinate in project h2database by h2database.
the class TestSpatial method testGeometryDataType.
private void testGeometryDataType() {
GeometryFactory geometryFactory = new GeometryFactory();
Geometry geometry = geometryFactory.createPoint(new Coordinate(0, 0));
assertEquals(Value.GEOMETRY, DataType.getTypeFromClass(geometry.getClass()));
}
use of org.locationtech.jts.geom.Coordinate in project h2database by h2database.
the class TestSpatial method testSpatialValues.
private void testSpatialValues() throws SQLException {
deleteDb("spatial");
Connection conn = getConnection(URL);
Statement stat = conn.createStatement();
stat.execute("create memory table test" + "(id int primary key, polygon geometry)");
stat.execute("insert into test values(1, " + "'POLYGON ((1 1, 1 2, 2 2, 1 1))')");
ResultSet rs = stat.executeQuery("select * from test");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
assertEquals("POLYGON ((1 1, 1 2, 2 2, 1 1))", rs.getString(2));
GeometryFactory f = new GeometryFactory();
Polygon polygon = f.createPolygon(new Coordinate[] { new Coordinate(1, 1), new Coordinate(1, 2), new Coordinate(2, 2), new Coordinate(1, 1) });
assertTrue(polygon.equals(rs.getObject(2)));
rs = stat.executeQuery("select * from test where polygon = " + "'POLYGON ((1 1, 1 2, 2 2, 1 1))'");
assertTrue(rs.next());
assertEquals(1, rs.getInt(1));
stat.executeQuery("select * from test where polygon > " + "'POLYGON ((1 1, 1 2, 2 2, 1 1))'");
stat.executeQuery("select * from test where polygon < " + "'POLYGON ((1 1, 1 2, 2 2, 1 1))'");
stat.execute("drop table test");
conn.close();
deleteDb("spatial");
}
use of org.locationtech.jts.geom.Coordinate in project arctic-sea by 52North.
the class ProfileObservation method setValue.
@Override
public void setValue(ObservationValue<?> value) {
if (value instanceof StreamingValue<?>) {
super.setValue(value);
} else if (value.getValue() instanceof RectifiedGridCoverage || value.getValue() instanceof ReferencableGridCoverage) {
super.setValue(value);
} else if (value.getValue() instanceof ProfileValue) {
ProfileValue profile = (ProfileValue) value.getValue();
RectifiedGridCoverage rectifiedGridCoverage = new RectifiedGridCoverage(getObservationID());
rectifiedGridCoverage.setUnit(value.getValue().getUnit());
rectifiedGridCoverage.setRangeParameters(getObservationConstellation().getObservablePropertyIdentifier());
List<Coordinate> coordinates = Lists.newArrayList();
int srid = 0;
for (ProfileLevel level : profile.getValue()) {
if (level.isSetLevelEnd()) {
rectifiedGridCoverage.addValue(new QuantityRangeValue(level.getLevelStart().getValue(), level.getLevelEnd().getValue(), level.getLevelStart().getUnit()), level.getSimpleValue());
} else {
rectifiedGridCoverage.addValue(level.getLevelStart(), level.getSimpleValue());
}
if (level.isSetLocation()) {
Coordinate coordinate = level.getLocation().getCoordinate();
coordinate.z = level.getLevelStart().getValue().doubleValue();
coordinates.add(coordinate);
if (srid == 0) {
srid = level.getLocation().getSRID();
}
}
}
if (CollectionHelper.isNotEmpty(coordinates)) {
setFeatureGeometry(coordinates, srid);
}
super.setValue(new SingleObservationValue<>(value.getPhenomenonTime(), rectifiedGridCoverage));
} else {
QuantityValue heightDepth = new QuantityValue(0.0);
if (isSetHeightDepthParameter()) {
heightDepth = (QuantityValue) getHeightDepthParameter().getValue();
removeParameter(getHeightDepthParameter());
}
RectifiedGridCoverage rectifiedGridCoverage = new RectifiedGridCoverage(getObservationID());
rectifiedGridCoverage.setUnit(value.getValue().getUnit());
rectifiedGridCoverage.addValue(heightDepth, value.getValue());
super.setValue(new SingleObservationValue<>(value.getPhenomenonTime(), rectifiedGridCoverage));
}
}
use of org.locationtech.jts.geom.Coordinate 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;
}
Aggregations