use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class PredicateTest method testGeospatialEvaluatorPointRadiusContains.
@Test
public void testGeospatialEvaluatorPointRadiusContains() throws Exception {
LOGGER.debug("************************** START: testGeospatialEvaluator_PointRadius_Contains() ***********************");
// WKT specifies points in LON LAT order
String geometryWkt = "POINT (44.5 34.5)";
String operation = "point_radius";
// 0.6 degrees
double distance = 0.6 * NM_PER_DEG_LAT * METERS_PER_NM;
// latitude in
// meters
double radiusInDegrees = (distance * 180.0) / (Math.PI * EQUATORIAL_RADIUS_IN_METERS);
LOGGER.debug("distance (in meters) = " + distance + ", radiusInDegrees = " + radiusInDegrees);
GeospatialPredicate predicate = new GeospatialPredicate(geometryWkt, operation, radiusInDegrees);
Geometry geoCriteria = predicate.getGeoCriteria();
LOGGER.debug("geoCriteria.toText() = {}", geoCriteria.toText());
String geospatialXml = "<gml:Polygon xmlns:gml=\"http://www.opengis.net/gml\" gml:id=\"BGE-1\">\n" + " <gml:exterior>\n" + " <gml:LinearRing>\n" + " <gml:pos>34.0 44.0</gml:pos>\n" + " <gml:pos>33.0 44.0</gml:pos>\n" + " <gml:pos>33.0 45.0</gml:pos>\n" + " <gml:pos>34.0 45.0</gml:pos>\n" + " <gml:pos>34.0 44.0</gml:pos>\n" + " </gml:LinearRing>\n" + " </gml:exterior>\n" + "</gml:Polygon>";
Geometry input = GeospatialEvaluator.buildGeometry(geospatialXml);
LOGGER.debug("input.toText() = {}", input.toText());
GeospatialEvaluationCriteria gec = new GeospatialEvaluationCriteriaImpl(geoCriteria, operation, input, radiusInDegrees);
boolean status = GeospatialEvaluator.evaluate(gec);
assertTrue(status);
LOGGER.debug("************************** END: testGeospatialEvaluator_PointRadius_Contains() ***********************");
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class GmdConverter method addGeospatialExtent.
protected void addGeospatialExtent(MetacardImpl metacard, XstreamPathValueTracker pathValueTracker) {
String wkt = metacard.getLocation();
if (StringUtils.isNotBlank(wkt)) {
WKTReader reader = new WKTReader();
Geometry geometry = null;
try {
geometry = reader.read(wkt);
} catch (ParseException e) {
LOGGER.debug("Unable to parse geometry {}", wkt, e);
}
if (geometry != null) {
Envelope bounds = geometry.getEnvelopeInternal();
String westLon = Double.toString(bounds.getMinX());
String eastLon = Double.toString(bounds.getMaxX());
String southLat = Double.toString(bounds.getMinY());
String northLat = Double.toString(bounds.getMaxY());
pathValueTracker.add(new Path(GmdConstants.BBOX_WEST_LON_PATH), westLon);
pathValueTracker.add(new Path(GmdConstants.BBOX_EAST_LON_PATH), eastLon);
pathValueTracker.add(new Path(GmdConstants.BBOX_SOUTH_LAT_PATH), southLat);
pathValueTracker.add(new Path(GmdConstants.BBOX_NORTH_LAT_PATH), northLat);
}
}
}
use of com.vividsolutions.jts.geom.Geometry in project ddf by codice.
the class CswMarshallHelper method writeBoundingBox.
static void writeBoundingBox(HierarchicalStreamWriter writer, MarshallingContext context, Metacard metacard) {
Set<AttributeDescriptor> attrDescs = metacard.getMetacardType().getAttributeDescriptors();
List<Geometry> geometries = new LinkedList<>();
for (AttributeDescriptor ad : attrDescs) {
if (ad.getType() != null && AttributeType.AttributeFormat.GEOMETRY.equals(ad.getType().getAttributeFormat())) {
Attribute attr = metacard.getAttribute(ad.getName());
if (attr != null) {
if (ad.isMultiValued()) {
for (Serializable value : attr.getValues()) {
geometries.add(XmlNode.readGeometry((String) value));
}
} else {
geometries.add(XmlNode.readGeometry((String) attr.getValue()));
}
}
}
}
Geometry allGeometry = new GeometryCollection(geometries.toArray(new Geometry[geometries.size()]), new GeometryFactory());
Envelope bounds = allGeometry.getEnvelopeInternal();
if (!bounds.isNull()) {
String bbox = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_BOUNDING_BOX;
String lower = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_LOWER_CORNER;
String upper = CswConstants.OWS_NAMESPACE_PREFIX + CswConstants.NAMESPACE_DELIMITER + CswConstants.OWS_UPPER_CORNER;
writer.startNode(bbox);
writer.addAttribute(CswConstants.CRS, CswConstants.SRS_URL);
writer.startNode(lower);
writer.setValue(bounds.getMinX() + " " + bounds.getMinY());
writer.endNode();
writer.startNode(upper);
writer.setValue(bounds.getMaxX() + " " + bounds.getMaxY());
writer.endNode();
writer.endNode();
}
}
use of com.vividsolutions.jts.geom.Geometry 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.Geometry in project ddf by codice.
the class WfsFilterDelegate method createEnvelopeFromWkt.
private Envelope createEnvelopeFromWkt(String wkt) {
Envelope envelope = null;
try {
Geometry geo = getGeometryFromWkt(wkt);
envelope = geo.getEnvelopeInternal();
} catch (ParseException e) {
throw new IllegalArgumentException("Unable to parse WKT String", e);
}
return envelope;
}
Aggregations