use of org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature 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
}
}
}
use of org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature in project arctic-sea by 52North.
the class TrajectoryObservation method checkForFeature.
/**
* Create geometry for featureOfInterest from
* {@link TimeLocationValueTriple}s
*
* @param values
* The {@link TimeLocationValueTriple}s to check for
* featureOfInterest
*/
private void checkForFeature(List<TimeLocationValueTriple> values) {
AbstractFeature featureOfInterest = getObservationConstellation().getFeatureOfInterest();
if (featureOfInterest instanceof AbstractSamplingFeature) {
AbstractSamplingFeature sf = (AbstractSamplingFeature) featureOfInterest;
Coordinate[] coords = getCoordinates(values);
int srid = 0;
if (sf.isSetGeometry()) {
srid = sf.getGeometry().getSRID();
coords = (Coordinate[]) ArrayUtils.addAll(sf.getGeometry().getCoordinates(), coords);
} else {
TimeLocationValueTriple next = values.iterator().next();
if (next.isSetLocation()) {
srid = next.getLocation().getSRID();
}
}
try {
if (coords.length == 1) {
Point point = new GeometryFactory().createPoint(coords[0]);
point.setSRID(srid);
sf.setGeometry(point);
} else if (coords.length > 1) {
LineString lineString = new GeometryFactory().createLineString(coords);
lineString.setSRID(srid);
sf.setGeometry(lineString);
}
} catch (InvalidSridException e) {
// TODO
}
}
}
use of org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature 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.features.samplingFeatures.AbstractSamplingFeature in project arctic-sea by 52North.
the class MultiPointObservation method getPoint.
/**
* Get the point from samplingGeometry or featureOfInterest
*
* @return The {@link Point}
*/
private Point getPoint() {
Point point = null;
if (isSetSpatialFilteringProfileParameter()) {
Geometry geometry = getSpatialFilteringProfileParameter().getValue().getValue();
point = geometry.getInteriorPoint();
point.setSRID(geometry.getSRID());
} else {
if (getObservationConstellation().getFeatureOfInterest() instanceof AbstractSamplingFeature && ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).isSetGeometry()) {
Geometry geometry = ((AbstractSamplingFeature) getObservationConstellation().getFeatureOfInterest()).getGeometry();
point = geometry.getInteriorPoint();
point.setSRID(geometry.getSRID());
}
}
return point;
}
use of org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature in project arctic-sea by 52North.
the class SpecimenDecoderv20 method getSampledFeatures.
/**
* Parse {@link FeaturePropertyType} sampledFeature to
* {@link AbstractFeature} list.
*
* @param sampledFeature
* SampledFeature to parse
* @return List with the parsed sampledFeature
* @throws DecodingException
* If an error occurs
*/
private List<AbstractFeature> getSampledFeatures(final FeaturePropertyType sampledFeature) throws DecodingException {
final List<AbstractFeature> sampledFeatures = new ArrayList<AbstractFeature>(1);
if (sampledFeature != null && !sampledFeature.isNil()) {
// if xlink:href is set
if (sampledFeature.getHref() != null && !sampledFeature.getHref().isEmpty()) {
if (sampledFeature.getHref().startsWith("#")) {
sampledFeatures.add(new SamplingFeature(null, sampledFeature.getHref().replace("#", "")));
} else {
final AbstractSamplingFeature sampFeat = new SamplingFeature(new CodeWithAuthority(sampledFeature.getHref()));
if (sampledFeature.getTitle() != null && !sampledFeature.getTitle().isEmpty()) {
sampFeat.addName(new CodeType(sampledFeature.getTitle()));
}
sampledFeatures.add(sampFeat);
}
} else {
XmlObject abstractFeature = null;
if (sampledFeature.getAbstractFeature() != null) {
abstractFeature = sampledFeature.getAbstractFeature();
} else if (sampledFeature.getDomNode().hasChildNodes()) {
try {
abstractFeature = XmlObject.Factory.parse(XmlHelper.getNodeFromNodeList(sampledFeature.getDomNode().getChildNodes()));
} catch (final XmlException xmle) {
throw new DecodingException("Error while parsing feature request!", xmle);
}
}
if (abstractFeature != null) {
final Object decodedObject = decodeXmlObject(abstractFeature);
if (decodedObject instanceof AbstractFeature) {
sampledFeatures.add((AbstractFeature) decodedObject);
}
}
throw new DecodingException("The requested sampledFeature type is not supported by this service!");
}
}
return sampledFeatures;
}
Aggregations