Search in sources :

Example 1 with Geometry

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);
    }
}
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 Geometry

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;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry)

Example 3 with Geometry

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());
}
Also used : ValueGeometry(org.h2.value.ValueGeometry) Geometry(org.locationtech.jts.geom.Geometry) SpatialKey(org.h2.mvstore.rtree.SpatialKey) ValueGeometry(org.h2.value.ValueGeometry) Value(org.h2.value.Value) Envelope(org.locationtech.jts.geom.Envelope)

Example 4 with Geometry

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()));
}
Also used : ValueGeometry(org.h2.value.ValueGeometry) Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate)

Example 5 with Geometry

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);
    }
}
Also used : ValueGeometry(org.h2.value.ValueGeometry) Geometry(org.locationtech.jts.geom.Geometry) SQLException(java.sql.SQLException) ParseException(org.locationtech.jts.io.ParseException) WKTReader(org.locationtech.jts.io.WKTReader)

Aggregations

Geometry (org.locationtech.jts.geom.Geometry)34 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)9 XmlObject (org.apache.xmlbeans.XmlObject)8 ValueGeometry (org.h2.value.ValueGeometry)7 Coordinate (org.locationtech.jts.geom.Coordinate)7 XmlException (org.apache.xmlbeans.XmlException)6 GeometryValue (org.n52.shetland.ogc.om.values.GeometryValue)6 Test (org.junit.Test)5 Point (org.locationtech.jts.geom.Point)5 AbstractGeometry (org.n52.shetland.ogc.gml.AbstractGeometry)5 DecodingException (org.n52.svalbard.decode.exception.DecodingException)4 EncodingException (org.n52.svalbard.encode.exception.EncodingException)4 XmlCursor (org.apache.xmlbeans.XmlCursor)3 Envelope (org.locationtech.jts.geom.Envelope)3 ReferenceType (org.n52.shetland.ogc.gml.ReferenceType)3 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 MultiPointType (net.opengis.gml.x32.MultiPointType)2