Search in sources :

Example 6 with Point

use of org.locationtech.jts.geom.Point 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
        }
    }
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) InvalidSridException(org.n52.shetland.ogc.om.features.samplingFeatures.InvalidSridException) AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) Point(org.locationtech.jts.geom.Point) Point(org.locationtech.jts.geom.Point) TimeLocationValueTriple(org.n52.shetland.ogc.om.TimeLocationValueTriple)

Example 7 with Point

use of org.locationtech.jts.geom.Point 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;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) Point(org.locationtech.jts.geom.Point)

Example 8 with Point

use of org.locationtech.jts.geom.Point 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));
    }
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) CvDiscretePointCoverage(org.n52.shetland.ogc.om.values.CvDiscretePointCoverage) AbstractObservationValue(org.n52.shetland.ogc.om.AbstractObservationValue) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) StreamingValue(org.n52.shetland.ogc.om.StreamingValue) Point(org.locationtech.jts.geom.Point) ReferenceType(org.n52.shetland.ogc.gml.ReferenceType) PointValuePair(org.n52.shetland.ogc.om.PointValuePair)

Example 9 with Point

use of org.locationtech.jts.geom.Point 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;
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Coordinate(org.locationtech.jts.geom.Coordinate) PrecisionModel(org.locationtech.jts.geom.PrecisionModel) Point(org.locationtech.jts.geom.Point) Point(org.locationtech.jts.geom.Point) PointValuePair(org.n52.shetland.ogc.om.PointValuePair)

Example 10 with Point

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

the class GeoJSONTest method randomPoint.

private Point randomPoint(int srid) {
    Point geometry = geometryFactory.createPoint(randomCoordinate());
    geometry.setSRID(srid);
    return geometry;
}
Also used : Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint)

Aggregations

Point (org.locationtech.jts.geom.Point)13 MultiPoint (org.locationtech.jts.geom.MultiPoint)6 Geometry (org.locationtech.jts.geom.Geometry)4 LineString (org.locationtech.jts.geom.LineString)4 XmlObject (org.apache.xmlbeans.XmlObject)3 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)3 Polygon (org.locationtech.jts.geom.Polygon)3 AbstractSamplingFeature (org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature)3 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)3 MultiPointType (net.opengis.gml.x32.MultiPointType)2 PointType (net.opengis.gml.x32.PointType)2 Coordinate (org.locationtech.jts.geom.Coordinate)2 AbstractGeometry (org.n52.shetland.ogc.gml.AbstractGeometry)2 PointValuePair (org.n52.shetland.ogc.om.PointValuePair)2 EnvelopeOrGeometry (org.n52.shetland.util.EnvelopeOrGeometry)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 LineStringType (net.opengis.gml.LineStringType)1 PointType (net.opengis.gml.PointType)1 PolygonType (net.opengis.gml.PolygonType)1