use of org.locationtech.jts.geom.GeometryFactory 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.locationtech.jts.geom.GeometryFactory 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.locationtech.jts.geom.GeometryFactory in project arctic-sea by 52North.
the class JTSHelperTest method factoryFromGeometryShouldSetSrid.
@Test
public void factoryFromGeometryShouldSetSrid() {
GeometryFactory factory = getGeometryFactoryForSRID(4326);
assertThat(factory, is(notNullValue()));
Geometry g = factory.createPoint(new Coordinate(1, 2));
factory = getGeometryFactory(g);
assertThat(factory, is(notNullValue()));
g = factory.createPoint(new Coordinate(1, 2));
assertThat(g, is(notNullValue()));
assertThat(g.getSRID(), is(4326));
}
use of org.locationtech.jts.geom.GeometryFactory 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;
}
use of org.locationtech.jts.geom.GeometryFactory in project arctic-sea by 52North.
the class AbstractMultiPointCoverageTypeEncoder method encodeMultiPointDomain.
private void encodeMultiPointDomain(DiscreteCoverageType dct, PointValueLists pointValues) throws EncodingException {
MultiPointDomainDocument mpdd = MultiPointDomainDocument.Factory.newInstance();
DomainSetType mpdst = mpdd.addNewMultiPointDomain();
GeometryFactory factory = pointValues.getPoints().get(0).getFactory();
MultiPoint multiPoint = factory.createMultiPoint(pointValues.getPoints().toArray(new Point[0]));
EncodingContext ec = EncodingContext.of(XmlBeansEncodingFlags.GMLID, JavaHelper.generateID(multiPoint.toString())).with(XmlBeansEncodingFlags.PROPERTY_TYPE, true);
XmlObject encodedGeometry = encodeGML(multiPoint, ec);
mpdst.addNewAbstractGeometry().set(encodedGeometry);
substitute(mpdst.getAbstractGeometry(), encodedGeometry);
dct.setDomainSet(mpdst);
}
Aggregations