use of org.locationtech.jts.geom.Geometry 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.Geometry in project h2database by h2database.
the class ValueGeometry method getGeometry.
/**
* Get a copy of geometry object. Geometry object is mutable. The returned
* object is therefore copied before returning.
*
* @return a copy of the geometry object
*/
public Geometry getGeometry() {
Geometry geometry = getGeometryNoCopy();
Geometry copy = geometry.copy();
/*
* Geometry factory is not preserved in WKB format, but SRID is preserved.
*
* We use a new factory to read geometries from WKB with default SRID value of
* 0.
*
* Geometry.copy() copies the geometry factory and copied value has SRID form
* the factory instead of original SRID value. So we need to copy SRID here with
* non-recommended (but not deprecated) setSRID() method.
*/
copy.setSRID(geometry.getSRID());
return copy;
}
use of org.locationtech.jts.geom.Geometry in project h2database by h2database.
the class SpatialTreeIndex method getKey.
private SpatialKey getKey(SearchRow row) {
if (row == null) {
return null;
}
Value v = row.getValue(columnIds[0]);
if (v == ValueNull.INSTANCE) {
return null;
}
Geometry g = ((ValueGeometry) v.convertTo(Value.GEOMETRY)).getGeometryNoCopy();
Envelope env = g.getEnvelopeInternal();
return new SpatialKey(row.getKey(), (float) env.getMinX(), (float) env.getMaxX(), (float) env.getMinY(), (float) env.getMaxY());
}
use of org.locationtech.jts.geom.Geometry 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.Geometry in project h2database by h2database.
the class TestSpatial method geomFromText.
/**
* Convert the text to a geometry object.
*
* @param text the geometry as a Well Known Text
* @param srid the projection id
* @return Geometry object
*/
public static Geometry geomFromText(String text, int srid) throws SQLException {
WKTReader wktReader = new WKTReader();
try {
Geometry geom = wktReader.read(text);
geom.setSRID(srid);
return geom;
} catch (ParseException ex) {
throw new SQLException(ex);
}
}
Aggregations