Search in sources :

Example 6 with Coordinate

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

the class OmObservationTest method should_have_SpatialFilteringProfileParameter.

@Test
public final void should_have_SpatialFilteringProfileParameter() throws OwsExceptionReport, DecodingException {
    OmObservation omObservation = new OmObservation();
    NamedValue<Geometry> namedValue = new NamedValue<>();
    namedValue.setName(new ReferenceType(OmConstants.PARAM_NAME_SAMPLING_GEOMETRY));
    GeometryFactory fac = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326);
    namedValue.setValue(new GeometryValue(fac.createPoint(new Coordinate(34.5, 76.4))));
    // test no parameter is set
    assertFalse(omObservation.isSetParameter());
    assertFalse(omObservation.isSetSpatialFilteringProfileParameter());
    omObservation.addParameter(namedValue);
    // test with set SpatialFilteringProfile parameter
    assertTrue(omObservation.isSetParameter());
    assertTrue(omObservation.isSetSpatialFilteringProfileParameter());
    assertThat(omObservation.getSpatialFilteringProfileParameter(), is(equalTo(namedValue)));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) PrecisionModel(org.locationtech.jts.geom.PrecisionModel) ReferenceType(org.n52.shetland.ogc.gml.ReferenceType) Test(org.junit.Test)

Example 7 with Coordinate

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

the class SweEnvelope method toEnvelope.

public Envelope toEnvelope() throws OwsExceptionReport {
    Coordinate min = getLowerCornerAsCoordinate();
    Coordinate max = getUpperCornerAsCoordinate();
    if (min != null && max != null) {
        if (this.northingFirst) {
            return new Envelope(min.y, max.y, min.x, max.x);
        } else {
            return new Envelope(min.x, max.x, min.y, max.y);
        }
    }
    return null;
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) Envelope(org.locationtech.jts.geom.Envelope)

Example 8 with Coordinate

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

the class GeoJSONDecoder method decodeCoordinate.

protected Coordinate decodeCoordinate(JsonNode node) throws GeoJSONDecodingException {
    if (!node.isArray()) {
        throw new GeoJSONDecodingException(EXPECTED_ARRAY);
    }
    final int dim = node.size();
    if (dim < DIM_2D) {
        throw new GeoJSONDecodingException("coordinates may have at least 2 dimensions");
    }
    if (dim > DIM_3D) {
        throw new GeoJSONDecodingException("coordinates may have at most 3 dimensions");
    }
    final Coordinate coordinate = new Coordinate();
    for (int i = 0; i < dim; ++i) {
        if (node.get(i).isNumber()) {
            coordinate.setOrdinate(i, node.get(i).doubleValue());
        } else {
            throw new GeoJSONDecodingException("coordinate index " + i + " has to be a number");
        }
    }
    return coordinate;
}
Also used : Coordinate(org.locationtech.jts.geom.Coordinate) GeoJSONDecodingException(org.n52.svalbard.coding.json.GeoJSONDecodingException) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Example 9 with Coordinate

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

the class JTSHelperTest method factoryFromSridShouldSetSrid.

@Test
public void factoryFromSridShouldSetSrid() {
    GeometryFactory factory = getGeometryFactoryForSRID(4326);
    assertThat(factory, is(notNullValue()));
    Geometry g = factory.createPoint(new Coordinate(1, 2));
    assertThat(g, is(notNullValue()));
    assertThat(g.getSRID(), is(4326));
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) JTSHelperForTesting.randomCoordinate(org.n52.shetland.util.JTSHelperForTesting.randomCoordinate) Test(org.junit.Test)

Example 10 with Coordinate

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

the class ReverseOf method matches.

@Override
public boolean matches(Object item) {
    if (item == null || item.getClass() != original.getClass()) {
        return false;
    }
    Geometry geom = (Geometry) item;
    Coordinate[] orig = original.getCoordinates();
    Coordinate[] switched = geom.getCoordinates();
    if (orig.length != switched.length) {
        return false;
    }
    for (int i = 0; i < orig.length; ++i) {
        if (!isSwitched(orig[i], switched[i])) {
            return false;
        }
    }
    return true;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) Coordinate(org.locationtech.jts.geom.Coordinate)

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