use of org.locationtech.jts.geom.Polygon in project ddf by codice.
the class OpenSearchParserImplTest method populateMultipleSearchesSpatial.
@Test
public void populateMultipleSearchesSpatial() throws ParseException {
double lat = 43.25;
double lon = -123.45;
double radius = 10000;
final PointRadius pointRadius = new PointRadius(lon, lat, radius);
final Polygon polygon = GEOMETRY_FACTORY.createPolygon(GEOMETRY_FACTORY.createLinearRing(new Coordinate[] { new Coordinate(1, 1), new Coordinate(5, 1), new Coordinate(5, 5), new Coordinate(1, 5), new Coordinate(1, 1) }), null);
final Geometry geometry = new WKTReader().read(WKT_GEOMETRY);
final BoundingBox boundingBox = new BoundingBox(170, 50, -150, 60);
openSearchParser.populateSpatial(webClient, geometry, boundingBox, polygon, pointRadius, Arrays.asList("q,src,mr,start,count,mt,dn,lat,lon,radius,bbox,geometry,polygon,dtstart,dtend,dateName,filter,sort".split(",")));
assertQueryParameterPopulated(OpenSearchConstants.GEOMETRY, WKT_GEOMETRY);
assertQueryParameterPopulated(OpenSearchConstants.POLYGON, "1.0,1.0,1.0,5.0,5.0,5.0,5.0,1.0,1.0,1.0");
assertQueryParameterPopulated(OpenSearchConstants.BBOX, "170.0,50.0,-150.0,60.0");
assertQueryParameterPopulated(OpenSearchConstants.LAT, String.valueOf(lat));
assertQueryParameterPopulated(OpenSearchConstants.LON, String.valueOf(lon));
assertQueryParameterPopulated(OpenSearchConstants.RADIUS, String.valueOf(radius));
}
use of org.locationtech.jts.geom.Polygon in project ddf by codice.
the class Wfs20JTStoGML321Converter method createGeometryPropertyType.
private static GeometryPropertyType createGeometryPropertyType(Geometry geometry, String srsName) {
final GeometryPropertyType geometryPropertyType = GML320_OBJECT_FACTORY.createGeometryPropertyType();
if (geometry instanceof Point) {
PointType pointType = convertToPointType((Point) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertPointTypeToJAXB(pointType));
} else if (geometry instanceof LineString) {
LineStringType lineStringType = convertToLineStringType((LineString) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertLineStringTypeToJAXB(lineStringType));
} else if (geometry instanceof Polygon) {
PolygonType polygonType = convertToPolygonType((Polygon) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertPolygonTypeToJAXB(polygonType));
} else if (geometry instanceof MultiPoint) {
MultiPointType multiPointType = convertToMultiPointType((MultiPoint) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertMultiPointTypeToJAXB(multiPointType));
} else if (geometry instanceof MultiLineString) {
MultiCurveType multiCurveType = convertToMultiLineStringType((MultiLineString) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertMultiCurveTypeToJAXB(multiCurveType));
} else if (geometry instanceof MultiPolygon) {
MultiSurfaceType multiSurfaceType = convertToMultiSurfaceType((MultiPolygon) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertMultiSurfaceTypeToJAXB(multiSurfaceType));
} else if (geometry instanceof GeometryCollection) {
MultiGeometryType multiGeometryType = convertToMultiGeometryType((GeometryCollection) geometry, srsName);
geometryPropertyType.setAbstractGeometry(convertMultiGeometryTypeToJAXB(multiGeometryType));
} else {
throw new IllegalArgumentException();
}
return geometryPropertyType;
}
use of org.locationtech.jts.geom.Polygon in project ddf by codice.
the class WfsFilterDelegate method createGeometryOperand.
private JAXBElement<?> createGeometryOperand(String wkt) {
String convertedWkt = convertWktToLatLonOrdering(wkt);
Geometry wktGeometry = null;
try {
wktGeometry = getGeometryFromWkt(convertedWkt);
} catch (ParseException e) {
throw new UnsupportedOperationException("Unable to parse WKT Geometry [" + convertedWkt + "]", e);
}
if (wktGeometry instanceof Polygon) {
GeometryOperand polygonOperand = new GeometryOperand();
polygonOperand.setName(Wfs20Constants.POLYGON);
if (isGeometryOperandSupported(polygonOperand)) {
return createPolygon(wktGeometry);
}
GeometryOperand envelopeOperand = new GeometryOperand();
envelopeOperand.setName(Wfs20Constants.ENVELOPE);
if (isGeometryOperandSupported(envelopeOperand)) {
return createEnvelope(wktGeometry);
}
} else if (wktGeometry instanceof Point) {
GeometryOperand pointOperand = new GeometryOperand();
pointOperand.setName(Wfs20Constants.POINT);
if (isGeometryOperandSupported(pointOperand)) {
return createPoint(wktGeometry);
}
} else if (wktGeometry instanceof LineString) {
GeometryOperand lineStringOperand = new GeometryOperand();
lineStringOperand.setName(Wfs20Constants.LINESTRING);
if (isGeometryOperandSupported(lineStringOperand)) {
return createLineString(wktGeometry);
}
}
throw new UnsupportedOperationException(MessageFormat.format(NOT_SUPPORTED_MSG, "Geometry Operand from WKT", convertedWkt));
}
use of org.locationtech.jts.geom.Polygon in project arctic-sea by 52North.
the class GeoJSONDecoder method decodeMultiPolygon.
protected MultiPolygon decodeMultiPolygon(JsonNode node, GeometryFactory fac) throws GeoJSONDecodingException {
JsonNode coordinates = requireCoordinates(node);
Polygon[] polygons = new Polygon[coordinates.size()];
for (int i = 0; i < coordinates.size(); ++i) {
polygons[i] = decodePolygonCoordinates(coordinates.get(i), fac);
}
return fac.createMultiPolygon(polygons);
}
use of org.locationtech.jts.geom.Polygon in project presto by prestodb.
the class JtsGeometrySerde method readPolygon.
private static Geometry readPolygon(SliceInput input, boolean multitype) {
skipEsriType(input);
skipEnvelope(input);
int partCount = input.readInt();
if (partCount == 0) {
if (multitype) {
return GEOMETRY_FACTORY.createMultiPolygon();
}
return GEOMETRY_FACTORY.createPolygon();
}
int pointCount = input.readInt();
int[] startIndexes = new int[partCount];
for (int i = 0; i < partCount; i++) {
startIndexes[i] = input.readInt();
}
int[] partLengths = new int[partCount];
if (partCount > 1) {
partLengths[0] = startIndexes[1];
for (int i = 1; i < partCount - 1; i++) {
partLengths[i] = startIndexes[i + 1] - startIndexes[i];
}
}
partLengths[partCount - 1] = pointCount - startIndexes[partCount - 1];
LinearRing shell = null;
List<LinearRing> holes = new ArrayList<>();
List<Polygon> polygons = new ArrayList<>();
try {
for (int i = 0; i < partCount; i++) {
Coordinate[] coordinates = readCoordinates(input, partLengths[i]);
if (isClockwise(coordinates)) {
// next polygon has started
if (shell != null) {
polygons.add(GEOMETRY_FACTORY.createPolygon(shell, holes.toArray(new LinearRing[0])));
holes.clear();
}
shell = GEOMETRY_FACTORY.createLinearRing(coordinates);
} else {
holes.add(GEOMETRY_FACTORY.createLinearRing(coordinates));
}
}
polygons.add(GEOMETRY_FACTORY.createPolygon(shell, holes.toArray(new LinearRing[0])));
} catch (IllegalArgumentException e) {
throw new TopologyException("Error constructing Polygon: " + e.getMessage());
}
if (multitype) {
return GEOMETRY_FACTORY.createMultiPolygon(polygons.toArray(new Polygon[0]));
}
return getOnlyElement(polygons);
}
Aggregations