Search in sources :

Example 11 with Coordinate

use of org.locationtech.jts.geom.Coordinate in project arctic-sea by 52North.

the class GeoJSONTest method randomLinearRing.

private LinearRing randomLinearRing(int srid) {
    Coordinate p = randomCoordinate();
    LinearRing geometry = geometryFactory.createLinearRing(new Coordinate[] { p, randomCoordinate(), randomCoordinate(), randomCoordinate(), p });
    geometry.setSRID(srid);
    return geometry;
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) LinearRing(org.locationtech.jts.geom.LinearRing)

Example 12 with Coordinate

use of org.locationtech.jts.geom.Coordinate 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(", ", ",");
}
Also used : WKTWriter(org.locationtech.jts.io.WKTWriter) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) PrecisionModel(org.locationtech.jts.geom.PrecisionModel) Before(org.junit.Before)

Example 13 with Coordinate

use of org.locationtech.jts.geom.Coordinate in project h2database by h2database.

the class TestSpatial method getRandomGeometry.

/**
 * Generate a random line string under the given bounding box.
 *
 * @param geometryRand the random generator
 * @param minX Bounding box min x
 * @param maxX Bounding box max x
 * @param minY Bounding box min y
 * @param maxY Bounding box max y
 * @param maxLength LineString maximum length
 * @return A segment within this bounding box
 */
static Geometry getRandomGeometry(Random geometryRand, double minX, double maxX, double minY, double maxY, double maxLength) {
    GeometryFactory factory = new GeometryFactory();
    // Create the start point
    Coordinate start = new Coordinate(geometryRand.nextDouble() * (maxX - minX) + minX, geometryRand.nextDouble() * (maxY - minY) + minY);
    // Compute an angle
    double angle = geometryRand.nextDouble() * Math.PI * 2;
    // Compute length
    double length = geometryRand.nextDouble() * maxLength;
    // Compute end point
    Coordinate end = new Coordinate(start.x + Math.cos(angle) * length, start.y + Math.sin(angle) * length);
    return factory.createLineString(new Coordinate[] { start, end });
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate)

Example 14 with Coordinate

use of org.locationtech.jts.geom.Coordinate in project h2database by h2database.

the class TestSpatial method testEquals.

/**
 * Test equality method on ValueGeometry
 */
private void testEquals() {
    // 3d equality test
    ValueGeometry geom3d = ValueGeometry.get("POLYGON ((67 13 6, 67 18 5, 59 18 4, 59 13 6,  67 13 6))");
    ValueGeometry geom2d = ValueGeometry.get("POLYGON ((67 13, 67 18, 59 18, 59 13,  67 13))");
    assertFalse(geom3d.equals(geom2d));
    // SRID equality test
    GeometryFactory geometryFactory = new GeometryFactory();
    Geometry geometry = geometryFactory.createPoint(new Coordinate(0, 0));
    geometry.setSRID(27572);
    ValueGeometry valueGeometry = ValueGeometry.getFromGeometry(geometry);
    Geometry geometry2 = geometryFactory.createPoint(new Coordinate(0, 0));
    geometry2.setSRID(5326);
    ValueGeometry valueGeometry2 = ValueGeometry.getFromGeometry(geometry2);
    assertFalse(valueGeometry.equals(valueGeometry2));
    ValueGeometry valueGeometry3 = ValueGeometry.getFromGeometry(geometry);
    assertEquals(valueGeometry, valueGeometry3);
    assertEquals(geometry.getSRID(), valueGeometry3.getGeometry().getSRID());
    // Check illegal geometry (no WKB representation)
    try {
        ValueGeometry.get("POINT EMPTY");
        fail("expected this to throw IllegalArgumentException");
    } catch (IllegalArgumentException ex) {
    // expected
    }
}
Also used : ValueGeometry(org.h2.value.ValueGeometry) Geometry(org.locationtech.jts.geom.Geometry) ValueGeometry(org.h2.value.ValueGeometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate)

Example 15 with Coordinate

use of org.locationtech.jts.geom.Coordinate in project arctic-sea by 52North.

the class ProfileObservation method setFeatureGeometry.

private void setFeatureGeometry(List<Coordinate> coordinates, int srid) {
    AbstractFeature featureOfInterest = getObservationConstellation().getFeatureOfInterest();
    if (featureOfInterest instanceof AbstractSamplingFeature) {
        AbstractSamplingFeature sf = (AbstractSamplingFeature) featureOfInterest;
        Coordinate[] coords = coordinates.toArray(new Coordinate[0]);
        try {
            LineString lineString = new GeometryFactory().createLineString(coords);
            lineString.setSRID(srid);
            sf.setGeometry(lineString);
            sf.setFeatureType(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_CURVE);
        } catch (InvalidSridException e) {
        // TODO
        }
    }
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) InvalidSridException(org.n52.shetland.ogc.om.features.samplingFeatures.InvalidSridException) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature)

Aggregations

Coordinate (org.locationtech.jts.geom.Coordinate)19 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)13 Geometry (org.locationtech.jts.geom.Geometry)7 Test (org.junit.Test)4 PrecisionModel (org.locationtech.jts.geom.PrecisionModel)4 LineString (org.locationtech.jts.geom.LineString)3 Point (org.locationtech.jts.geom.Point)3 SimpleResultSet (org.h2.tools.SimpleResultSet)2 ValueGeometry (org.h2.value.ValueGeometry)2 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)2 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)2 InvalidSridException (org.n52.shetland.ogc.om.features.samplingFeatures.InvalidSridException)2 GeometryValue (org.n52.shetland.ogc.om.values.GeometryValue)2 JTSHelperForTesting.randomCoordinate (org.n52.shetland.util.JTSHelperForTesting.randomCoordinate)2 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 Before (org.junit.Before)1