Search in sources :

Example 91 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 92 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)

Example 93 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 94 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 95 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)

Aggregations

Coordinate (org.locationtech.jts.geom.Coordinate)348 Test (org.junit.Test)145 Geometry (org.locationtech.jts.geom.Geometry)69 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)65 LineString (org.locationtech.jts.geom.LineString)57 Point (org.locationtech.jts.geom.Point)57 Polygon (org.locationtech.jts.geom.Polygon)47 LinearRing (org.locationtech.jts.geom.LinearRing)45 AbstractArcTest (eu.esdihumboldt.util.geometry.interpolation.AbstractArcTest)37 ArcByCenterPoint (eu.esdihumboldt.util.geometry.interpolation.model.ArcByCenterPoint)32 ArrayList (java.util.ArrayList)32 MultiPolygon (org.locationtech.jts.geom.MultiPolygon)27 Test (org.junit.jupiter.api.Test)26 Arc (eu.esdihumboldt.util.geometry.interpolation.model.Arc)20 MultiPoint (org.locationtech.jts.geom.MultiPoint)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 ArcByPoints (eu.esdihumboldt.util.geometry.interpolation.model.ArcByPoints)14 HashMap (java.util.HashMap)13