use of org.n52.shetland.ogc.om.PointValuePair in project arctic-sea by 52North.
the class MultiPointObservation method setValue.
@Override
public void setValue(ObservationValue<?> value) {
if (value.getValue() instanceof MultiPointCoverage) {
super.setValue(value);
} else {
MultiPointCoverage multiPointCoverage = new MultiPointCoverage(getObservationID());
multiPointCoverage.setUnit(((AbstractObservationValue<?>) value).getUnit());
multiPointCoverage.addValue(new PointValuePair(getPoint(), value.getValue()));
super.setValue(new SingleObservationValue<>(value.getPhenomenonTime(), multiPointCoverage));
}
}
use of org.n52.shetland.ogc.om.PointValuePair in project arctic-sea by 52North.
the class MultiPointObservation method getEnvelope.
/**
* Get the envelope from {@link PointValuePair}s {@link List}
*
* @param pointValuePairs
* The {@link PointValuePair}s to get the envelope from
* @return The envelope of the {@link PointValuePair}s
*/
private Geometry getEnvelope(List<PointValuePair> pointValuePairs) {
Envelope envelope = new Envelope();
GeometryFactory factory = null;
int srid = 4326;
if (CollectionHelper.isNotEmpty(pointValuePairs)) {
for (PointValuePair pointValuePair : pointValuePairs) {
if (factory == null && pointValuePair.getPoint() != null) {
factory = pointValuePair.getPoint().getFactory();
}
if (pointValuePair.getPoint().getSRID() > 0) {
srid = pointValuePair.getPoint().getSRID();
}
envelope.expandToInclude(pointValuePair.getPoint().getEnvelopeInternal());
}
} else {
if (isSetSpatialFilteringProfileParameter()) {
Geometry geometry = getSpatialFilteringProfileParameter().getValue().getValue();
if (geometry != null) {
if (factory == null) {
factory = geometry.getFactory();
}
if (geometry.getSRID() > 0) {
srid = geometry.getSRID();
}
envelope.expandToInclude(geometry.getEnvelopeInternal());
}
} else {
if (getObservationConstellation().getFeatureOfInterest() instanceof AbstractSamplingFeature && ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).isSetGeometry()) {
Geometry geometry = ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).getGeometry();
if (geometry != null) {
if (factory == null) {
factory = geometry.getFactory();
}
if (geometry.getSRID() > 0) {
srid = geometry.getSRID();
}
envelope.expandToInclude(geometry.getEnvelopeInternal());
}
}
}
}
if (factory == null) {
factory = JTSHelper.getGeometryFactoryForSRID(srid);
}
Geometry geometry = factory.toGeometry(envelope);
geometry.setSRID(srid);
return geometry;
}
use of org.n52.shetland.ogc.om.PointValuePair in project arctic-sea by 52North.
the class PointObservation method setValue.
@Override
public void setValue(ObservationValue<?> value) {
if (value instanceof StreamingValue<?>) {
super.setValue(value);
} else if (value.getValue() instanceof CvDiscretePointCoverage) {
super.setValue(value);
} else {
CvDiscretePointCoverage cvDiscretePointCoverage = new CvDiscretePointCoverage(getObservationID());
cvDiscretePointCoverage.setRangeType(new ReferenceType(getObservationConstellation().getObservablePropertyIdentifier()));
cvDiscretePointCoverage.setUnit(((AbstractObservationValue<?>) value).getUnit());
Geometry geometry = null;
String domainExtent = "";
if (isSetSpatialFilteringProfileParameter() && getSpatialFilteringProfileParameter().getValue() instanceof GeometryValue) {
GeometryValue geometryValue = (GeometryValue) getSpatialFilteringProfileParameter().getValue();
geometry = getSpatialFilteringProfileParameter().getValue().getValue();
domainExtent = geometryValue.getGmlId();
} else if (checkForFeatureGeometry(this)) {
geometry = getGeometryFromFeature(this);
domainExtent = getObservationConstellation().getFeatureOfInterest().getGmlId();
}
if (geometry != null) {
cvDiscretePointCoverage.setDomainExtent("#" + geometry.getGeometryType() + "_" + domainExtent);
Point point = null;
if (geometry instanceof Point) {
point = (Point) geometry;
} else {
point = geometry.getCentroid();
}
cvDiscretePointCoverage.setValue(new PointValuePair(point, value.getValue()));
}
super.setValue(new SingleObservationValue<>(value.getPhenomenonTime(), cvDiscretePointCoverage));
}
}
use of org.n52.shetland.ogc.om.PointValuePair in project arctic-sea by 52North.
the class MultiPointCoverage method getExtent.
/**
* Get the extent of all {@link Point}s
*
* @return The extent as {@link Polygon}
*/
public Polygon getExtent() {
if (isSetValue()) {
int srid = -1;
List<Coordinate> coordinates = Lists.newLinkedList();
for (PointValuePair pointValuePair : getValue()) {
Point point = pointValuePair.getPoint();
coordinates.add(point.getCoordinate());
if (point.getSRID() != srid) {
srid = point.getSRID();
}
}
GeometryFactory geometryFactory;
if (srid > 0) {
geometryFactory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), srid);
} else {
geometryFactory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING));
}
return geometryFactory.createPolygon(coordinates.toArray(new Coordinate[coordinates.size()]));
}
return null;
}
Aggregations