use of org.locationtech.jts.geom.Coordinate 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.Coordinate 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.Coordinate 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.Coordinate in project arctic-sea by 52North.
the class GeometryObservationDecodingTest method testObservation.
@Test
public void testObservation() {
assertThat(observation, is(notNullValue()));
final String type = observation.getObservationConstellation().getObservationType();
assertThat(type, is(equalTo(OmConstants.OBS_TYPE_GEOMETRY_OBSERVATION)));
final ObservationValue<?> value = observation.getValue();
assertThat(value, is(instanceOf(SingleObservationValue.class)));
assertThat(value.getPhenomenonTime(), is(instanceOf(TimeInstant.class)));
TimeInstant pt = (TimeInstant) value.getPhenomenonTime();
assertThat(pt.getValue(), is(equalTo(phenomenonTime)));
assertThat(value.getValue(), is(instanceOf(GeometryValue.class)));
GeometryValue v = (GeometryValue) value.getValue();
assertThat(v.getUnit(), is(nullValue()));
Geometry g = v.getValue();
assertThat(g, is(instanceOf(LineString.class)));
assertThat(g.getSRID(), is(2000));
assertThat(g.getNumPoints(), is(2));
assertThat(g.getCoordinates()[0], is(equalTo(new Coordinate(52, 7))));
assertThat(g.getCoordinates()[1], is(equalTo(new Coordinate(51, 7))));
}
Aggregations