use of org.locationtech.jts.geom.GeometryFactory in project arctic-sea by 52North.
the class FesEncoderv20Test method should_return_BBoxType_for_spatialFilter.
// @Test
// deactivated until test fails on build server.
public final void should_return_BBoxType_for_spatialFilter() throws EncodingException {
final SpatialFilter filter = new SpatialFilter();
filter.setOperator(SpatialOperator.BBOX);
filter.setGeometry(new GeometryFactory().toGeometry(new Envelope(1, 2, 3, 4)));
filter.setValueReference("valueReference");
final XmlObject encode = fesEncoder.encode(filter);
assertThat(encode, is(instanceOf(BBOXType.class)));
final BBOXType xbBBox = (BBOXType) encode;
assertThat(xbBBox.isSetExpression(), is(TRUE));
}
use of org.locationtech.jts.geom.GeometryFactory in project h2database by h2database.
the class TestSpatial method getRandomGeometry.
/**
* Generate a random line string under the given bounding box.
*
* @param geometryRand the random generator
* @param minX Bounding box min x
* @param maxX Bounding box max x
* @param minY Bounding box min y
* @param maxY Bounding box max y
* @param maxLength LineString maximum length
* @return A segment within this bounding box
*/
static Geometry getRandomGeometry(Random geometryRand, double minX, double maxX, double minY, double maxY, double maxLength) {
GeometryFactory factory = new GeometryFactory();
// Create the start point
Coordinate start = new Coordinate(geometryRand.nextDouble() * (maxX - minX) + minX, geometryRand.nextDouble() * (maxY - minY) + minY);
// Compute an angle
double angle = geometryRand.nextDouble() * Math.PI * 2;
// Compute length
double length = geometryRand.nextDouble() * maxLength;
// Compute end point
Coordinate end = new Coordinate(start.x + Math.cos(angle) * length, start.y + Math.sin(angle) * length);
return factory.createLineString(new Coordinate[] { start, end });
}
use of org.locationtech.jts.geom.GeometryFactory in project h2database by h2database.
the class TestSpatial method testEquals.
/**
* Test equality method on ValueGeometry
*/
private void testEquals() {
// 3d equality test
ValueGeometry geom3d = ValueGeometry.get("POLYGON ((67 13 6, 67 18 5, 59 18 4, 59 13 6, 67 13 6))");
ValueGeometry geom2d = ValueGeometry.get("POLYGON ((67 13, 67 18, 59 18, 59 13, 67 13))");
assertFalse(geom3d.equals(geom2d));
// SRID equality test
GeometryFactory geometryFactory = new GeometryFactory();
Geometry geometry = geometryFactory.createPoint(new Coordinate(0, 0));
geometry.setSRID(27572);
ValueGeometry valueGeometry = ValueGeometry.getFromGeometry(geometry);
Geometry geometry2 = geometryFactory.createPoint(new Coordinate(0, 0));
geometry2.setSRID(5326);
ValueGeometry valueGeometry2 = ValueGeometry.getFromGeometry(geometry2);
assertFalse(valueGeometry.equals(valueGeometry2));
ValueGeometry valueGeometry3 = ValueGeometry.getFromGeometry(geometry);
assertEquals(valueGeometry, valueGeometry3);
assertEquals(geometry.getSRID(), valueGeometry3.getGeometry().getSRID());
// Check illegal geometry (no WKB representation)
try {
ValueGeometry.get("POINT EMPTY");
fail("expected this to throw IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// expected
}
}
use of org.locationtech.jts.geom.GeometryFactory in project arctic-sea by 52North.
the class GeoJSONDecoder method decodeGeometry.
protected Geometry decodeGeometry(Object o, GeometryFactory parentFactory) throws GeoJSONDecodingException {
if (!(o instanceof JsonNode)) {
throw new GeoJSONDecodingException("Cannot decode " + o);
}
final JsonNode node = (JsonNode) o;
final String type = getType(node);
final GeometryFactory factory = getGeometryFactory(node, parentFactory);
switch(type) {
case JSONConstants.POINT:
return decodePoint(node, factory);
case JSONConstants.MULTI_POINT:
return decodeMultiPoint(node, factory);
case JSONConstants.LINE_STRING:
return decodeLineString(node, factory);
case JSONConstants.MULTI_LINE_STRING:
return decodeMultiLineString(node, factory);
case JSONConstants.POLYGON:
return decodePolygon(node, factory);
case JSONConstants.MULTI_POLYGON:
return decodeMultiPolygon(node, factory);
case JSONConstants.GEOMETRY_COLLECTION:
return decodeGeometryCollection(node, factory);
default:
throw new GeoJSONDecodingException("Unkown geometry type: " + type);
}
}
use of org.locationtech.jts.geom.GeometryFactory 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
}
}
}
Aggregations