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