Search in sources :

Example 16 with GeometryFactory

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

the class FesEncoderv20Test method should_return_BBoxType_for_spatialFilter.

// @Test
// deactivated until test fails on build server.
public final void should_return_BBoxType_for_spatialFilter() throws EncodingException {
    final SpatialFilter filter = new SpatialFilter();
    filter.setOperator(SpatialOperator.BBOX);
    filter.setGeometry(new GeometryFactory().toGeometry(new Envelope(1, 2, 3, 4)));
    filter.setValueReference("valueReference");
    final XmlObject encode = fesEncoder.encode(filter);
    assertThat(encode, is(instanceOf(BBOXType.class)));
    final BBOXType xbBBox = (BBOXType) encode;
    assertThat(xbBBox.isSetExpression(), is(TRUE));
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) BBOXType(net.opengis.fes.x20.BBOXType) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) XmlObject(org.apache.xmlbeans.XmlObject) Envelope(org.locationtech.jts.geom.Envelope)

Example 17 with GeometryFactory

use of org.locationtech.jts.geom.GeometryFactory 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 18 with GeometryFactory

use of org.locationtech.jts.geom.GeometryFactory 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 19 with GeometryFactory

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

the class GeoJSONDecoder method decodeGeometry.

protected Geometry decodeGeometry(Object o, GeometryFactory parentFactory) throws GeoJSONDecodingException {
    if (!(o instanceof JsonNode)) {
        throw new GeoJSONDecodingException("Cannot decode " + o);
    }
    final JsonNode node = (JsonNode) o;
    final String type = getType(node);
    final GeometryFactory factory = getGeometryFactory(node, parentFactory);
    switch(type) {
        case JSONConstants.POINT:
            return decodePoint(node, factory);
        case JSONConstants.MULTI_POINT:
            return decodeMultiPoint(node, factory);
        case JSONConstants.LINE_STRING:
            return decodeLineString(node, factory);
        case JSONConstants.MULTI_LINE_STRING:
            return decodeMultiLineString(node, factory);
        case JSONConstants.POLYGON:
            return decodePolygon(node, factory);
        case JSONConstants.MULTI_POLYGON:
            return decodeMultiPolygon(node, factory);
        case JSONConstants.GEOMETRY_COLLECTION:
            return decodeGeometryCollection(node, factory);
        default:
            throw new GeoJSONDecodingException("Unkown geometry type: " + type);
    }
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) GeoJSONDecodingException(org.n52.svalbard.coding.json.GeoJSONDecodingException) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString)

Example 20 with GeometryFactory

use of org.locationtech.jts.geom.GeometryFactory 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

GeometryFactory (org.locationtech.jts.geom.GeometryFactory)26 Coordinate (org.locationtech.jts.geom.Coordinate)13 Geometry (org.locationtech.jts.geom.Geometry)9 Test (org.junit.Test)8 PrecisionModel (org.locationtech.jts.geom.PrecisionModel)6 LineString (org.locationtech.jts.geom.LineString)4 Point (org.locationtech.jts.geom.Point)4 Envelope (org.locationtech.jts.geom.Envelope)3 Polygon (org.locationtech.jts.geom.Polygon)3 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)3 XmlObject (org.apache.xmlbeans.XmlObject)2 SimpleResultSet (org.h2.tools.SimpleResultSet)2 ValueGeometry (org.h2.value.ValueGeometry)2 LinearRing (org.locationtech.jts.geom.LinearRing)2 ParseException (org.locationtech.jts.io.ParseException)2 WKTReader (org.locationtech.jts.io.WKTReader)2 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)2 PointValuePair (org.n52.shetland.ogc.om.PointValuePair)2 InvalidSridException (org.n52.shetland.ogc.om.features.samplingFeatures.InvalidSridException)2 JTSHelperForTesting.randomCoordinate (org.n52.shetland.util.JTSHelperForTesting.randomCoordinate)2