use of com.vividsolutions.jts.geom.Polygon in project ddf by codice.
the class TestWfs10JTStoGML200Converter method testGeometryToPolygonGML.
@Test
public void testGeometryToPolygonGML() throws JAXBException, SAXException, IOException, ParseException, NullPointerException {
Polygon polygon = (Polygon) getGeometryFromWkt(POLYGON);
assertThat(polygon == null, is(Boolean.FALSE));
String polygonGML = Wfs10JTStoGML200Converter.convertGeometryToGML(polygon).replaceAll("\n", "");
assertThat(StringUtils.isEmpty(polygonGML), is(Boolean.FALSE));
Diff diff = XMLUnit.compareXML(polygonGML, POLYGON_GML);
assertTrue(XMLUNIT_SIMILAR, diff.similar());
assertTrue(XMLUNIT_IDENTICAL, diff.identical());
}
use of com.vividsolutions.jts.geom.Polygon in project ddf by codice.
the class WfsFilterDelegate method createGeometryOperand.
private JAXBElement<? extends AbstractGeometryType> createGeometryOperand(String wkt) {
String convertedWkt = wkt;
Geometry wktGeometry = null;
try {
wktGeometry = getGeometryFromWkt(convertedWkt);
} catch (ParseException e) {
throw new IllegalArgumentException("Unable to parse WKT Geometry [" + convertedWkt + "]", e);
}
if (wktGeometry instanceof Polygon) {
if (isGeometryOperandSupported(Wfs10Constants.POLYGON)) {
return createPolygon(convertedWkt);
} else {
throw new IllegalArgumentException("The Polygon operand is not supported.");
}
} else if (wktGeometry instanceof Point) {
if (isGeometryOperandSupported(Wfs10Constants.POINT)) {
return createPoint(convertedWkt);
} else {
throw new IllegalArgumentException("The Point operand is not supported.");
}
} else if (wktGeometry instanceof LineString) {
if (isGeometryOperandSupported(Wfs10Constants.LINESTRING)) {
return createLineString(wktGeometry);
} else {
throw new IllegalArgumentException("The LineString operand is not supported.");
}
} else if (wktGeometry instanceof MultiPoint) {
if (isGeometryOperandSupported(Wfs10Constants.MULTI_POINT)) {
return createMultiPoint(wktGeometry);
} else {
throw new IllegalArgumentException("The MultiPoint operand is not supported.");
}
} else if (wktGeometry instanceof MultiLineString) {
if (isGeometryOperandSupported(Wfs10Constants.MULTI_LINESTRING)) {
return createMultiLineString(wktGeometry);
} else {
throw new IllegalArgumentException("The MultiLineString operand is not supported.");
}
} else if (wktGeometry instanceof MultiPolygon) {
if (isGeometryOperandSupported(Wfs10Constants.MULTI_POLYGON)) {
return createMultiPolygon(wktGeometry);
} else {
throw new IllegalArgumentException("The MultiPolygon operand is not supported.");
}
} else if (wktGeometry instanceof GeometryCollection) {
if (isGeometryOperandSupported(Wfs10Constants.GEOMETRY_COLLECTION)) {
return createGeometryCollection(wktGeometry);
} else {
throw new IllegalArgumentException("The GeometryCollection operand is not supported.");
}
}
throw new IllegalArgumentException("Unable to create Geometry from WKT String");
}
use of com.vividsolutions.jts.geom.Polygon in project GeoGig by boundlessgeo.
the class GeoGigFeatureSourceTest method testGetBoundsQuery.
@Test
public void testGetBoundsQuery() throws Exception {
ReferencedEnvelope bounds;
Filter filter;
filter = ff.id(Collections.singleton(ff.featureId(RepositoryTestCase.idP2)));
bounds = pointsSource.getBounds(new Query(pointsName, filter));
assertEquals(boundsOf(points2), bounds);
ReferencedEnvelope queryBounds = boundsOf(points1, points2);
Polygon geometry = JTS.toGeometry(queryBounds);
filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
bounds = pointsSource.getBounds(new Query(pointsName, filter));
assertEquals(boundsOf(points1, points2), bounds);
ReferencedEnvelope transformedQueryBounds;
CoordinateReferenceSystem queryCrs = CRS.decode("EPSG:3857");
transformedQueryBounds = queryBounds.transform(queryCrs, true);
geometry = JTS.toGeometry(transformedQueryBounds);
geometry.setUserData(queryCrs);
filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
bounds = pointsSource.getBounds(new Query(pointsName, filter));
assertEquals(boundsOf(points1, points2), bounds);
filter = ECQL.toFilter("sp = 'StringProp2_3' OR ip = 2000");
bounds = linesSource.getBounds(new Query(linesName, filter));
assertEquals(boundsOf(lines3, lines2), bounds);
}
use of com.vividsolutions.jts.geom.Polygon in project GeoGig by boundlessgeo.
the class GeoGigFeatureSourceTest method testGetCount.
@Test
public void testGetCount() throws Exception {
assertEquals(3, pointsSource.getCount(Query.ALL));
assertEquals(3, linesSource.getCount(Query.ALL));
Filter filter;
filter = ff.id(Collections.singleton(ff.featureId(RepositoryTestCase.idP2)));
assertEquals(1, pointsSource.getCount(new Query(pointsName, filter)));
ReferencedEnvelope queryBounds = boundsOf(points1, points2);
Polygon geometry = JTS.toGeometry(queryBounds);
filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
assertEquals(2, pointsSource.getCount(new Query(pointsName, filter)));
ReferencedEnvelope transformedQueryBounds;
CoordinateReferenceSystem queryCrs = CRS.decode("EPSG:3857");
transformedQueryBounds = queryBounds.transform(queryCrs, true);
geometry = JTS.toGeometry(transformedQueryBounds);
geometry.setUserData(queryCrs);
filter = ff.intersects(ff.property(pointsType.getGeometryDescriptor().getLocalName()), ff.literal(geometry));
assertEquals(2, pointsSource.getCount(new Query(pointsName, filter)));
filter = ECQL.toFilter("sp = 'StringProp2_3' OR ip = 2000");
assertEquals(2, linesSource.getCount(new Query(linesName, filter)));
}
use of com.vividsolutions.jts.geom.Polygon in project dhis2-core by dhis2.
the class GeoUtils method checkPointWithMultiPolygon.
/**
* Check if the point coordinate falls within the polygon/MultiPolygon Shape
*
* @param longitude the longitude.
* @param latitude the latitude.
* @param multiPolygonJson the GeoJSON coordinates of the MultiPolygon
* @param featureType the featureType of the MultiPolygon.
*/
public static boolean checkPointWithMultiPolygon(double longitude, double latitude, String multiPolygonJson, FeatureType featureType) {
try {
boolean contains = false;
GeometryJSON gtjson = new GeometryJSON();
Point point = getGeoJsonPoint(longitude, latitude);
if (point != null && point.isValid()) {
if (featureType == FeatureType.POLYGON) {
Polygon polygon = gtjson.readPolygon(new StringReader("{\"type\":\"Polygon\", \"coordinates\":" + multiPolygonJson + "}"));
contains = polygon.contains(point);
} else if (featureType == FeatureType.MULTI_POLYGON) {
MultiPolygon multiPolygon = gtjson.readMultiPolygon(new StringReader("{\"type\":\"MultiPolygon\", \"coordinates\":" + multiPolygonJson + "}"));
contains = multiPolygon.contains(point);
}
}
return contains;
} catch (Exception ex) {
return false;
}
}
Aggregations