Search in sources :

Example 1 with Coordinate

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

Example 2 with Coordinate

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()));
}
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 3 with Coordinate

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");
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) Statement(java.sql.Statement) Connection(java.sql.Connection) SimpleResultSet(org.h2.tools.SimpleResultSet) ResultSet(java.sql.ResultSet) Polygon(org.locationtech.jts.geom.Polygon)

Example 4 with Coordinate

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));
    }
}
Also used : StreamingValue(org.n52.shetland.ogc.om.StreamingValue) Coordinate(org.locationtech.jts.geom.Coordinate) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) ProfileLevel(org.n52.shetland.ogc.om.values.ProfileLevel) QuantityRangeValue(org.n52.shetland.ogc.om.values.QuantityRangeValue) RectifiedGridCoverage(org.n52.shetland.ogc.om.values.RectifiedGridCoverage) ReferencableGridCoverage(org.n52.shetland.ogc.om.values.ReferencableGridCoverage) ProfileValue(org.n52.shetland.ogc.om.values.ProfileValue)

Example 5 with Coordinate

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

Aggregations

Coordinate (org.locationtech.jts.geom.Coordinate)320 Test (org.junit.Test)135 Geometry (org.locationtech.jts.geom.Geometry)63 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)59 LineString (org.locationtech.jts.geom.LineString)52 Point (org.locationtech.jts.geom.Point)49 Polygon (org.locationtech.jts.geom.Polygon)43 LinearRing (org.locationtech.jts.geom.LinearRing)39 AbstractArcTest (eu.esdihumboldt.util.geometry.interpolation.AbstractArcTest)37 ArcByCenterPoint (eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)32 ArrayList (java.util.ArrayList)29 Test (org.junit.jupiter.api.Test)26 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)25 Arc (eu.esdihumboldt.util.geometry.interpolation.model.Arc)20 ArcByPointsImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByPointsImpl)17 ArcByCenterPointImpl (eu.esdihumboldt.util.geometry.interpolation.model.impl.ArcByCenterPointImpl)16 GeometryWrapper (org.apache.jena.geosparql.implementation.GeometryWrapper)15 MultiPoint (org.locationtech.jts.geom.MultiPoint)15 ArcByPoints (eu.esdihumboldt.util.geometry.interpolation.model.ArcByPoints)14 Instance (eu.esdihumboldt.hale.common.instance.model.Instance)12