use of com.vividsolutions.jts.geom.GeometryFactory in project ddf by codice.
the class JTSGeometryWrapperTest method testComputeJTSPeerWithGeometry.
@Test
public void testComputeJTSPeerWithGeometry() {
GeometryFactory fac = new GeometryFactory();
Geometry toWrap = fac.createPoint(new Coordinate(0, 0));
toTest = new JTSGeometryWrapper(toWrap);
assertEquals(toWrap, toTest.computeJTSPeer());
}
use of com.vividsolutions.jts.geom.GeometryFactory in project ddf by codice.
the class GeospatialEvaluator method buildGeometry.
public static Geometry buildGeometry(String gmlText) throws IOException, SAXException, ParserConfigurationException {
String methodName = "buildGeometry";
LOGGER.debug("ENTERING: {}", methodName);
Geometry geometry = null;
gmlText = supportSRSName(gmlText);
try {
LOGGER.debug("Creating geoTools Configuration ...");
Configuration config = new org.geotools.gml3.GMLConfiguration();
LOGGER.debug("Parsing geoTools configuration");
Parser parser = new Parser(config);
LOGGER.debug("Parsing gmlText");
geometry = (Geometry) (parser.parse(new StringReader(gmlText)));
LOGGER.debug("geometry (before conversion): {}", geometry.toText());
// The metadata schema states that <gml:pos> elements specify points in
// LAT,LON order. But WKT specifies points in LON,LAT order. When the geoTools
// libraries return the geometry data, it's WKT is in LAT,LON order (which is
// incorrect).
// As a workaround here, for Polygons and Points (which are currently the only spatial
// criteria supported) we must swap the x,y of each coordinate so that they are
// specified in LON,LAT order and then use the swapped coordinates to create a new
// Polygon or Point to be returned to the caller.
GeometryFactory geometryFactory = new GeometryFactory();
if (geometry instanceof Polygon) {
// Build new array of coordinates using the swapped coordinates
ArrayList<Coordinate> newCoords = new ArrayList<Coordinate>();
// Swap each coordinate's x,y so that they specify LON,LAT order
for (Coordinate coord : geometry.getCoordinates()) {
newCoords.add(new Coordinate(coord.y, coord.x));
}
// Create a new polygon using the swapped coordinates
Polygon polygon = new Polygon(geometryFactory.createLinearRing(newCoords.toArray(new Coordinate[newCoords.size()])), null, geometryFactory);
// this logs the transformed WKT
LOGGER.debug("Translates to {}", polygon.toText());
// with LON,LAT ordered points
LOGGER.debug("EXITING: {}", methodName);
return polygon;
}
if (geometry instanceof Point) {
// Create a new point using the swapped coordinates that specify LON,LAT order
Point point = geometryFactory.createPoint(new Coordinate(geometry.getCoordinate().y, geometry.getCoordinate().x));
// this logs the transformed WKT
LOGGER.debug("Translates to {}", point.toText());
// with a LON,LAT ordered point
LOGGER.debug("EXITING: {}", methodName);
return point;
}
} catch (Exception e) {
LOGGER.debug("Exception using geotools", e);
}
LOGGER.debug("No translation done for geometry - probably not good ...");
LOGGER.debug("EXITING: {}", methodName);
return geometry;
}
use of com.vividsolutions.jts.geom.GeometryFactory in project ddf by codice.
the class TestCswRecordMapperFilterVisitor method testVisitBeyond.
@Test
public void testVisitBeyond() {
GeometryFactory geoFactory = new GeometryFactory();
double val = 30;
Expression pt1 = factory.literal(geoFactory.createPoint(new Coordinate(4, 5)));
Expression pt2 = factory.literal(geoFactory.createPoint(new Coordinate(6, 7)));
Beyond filter = factory.beyond(pt1, pt2, val, "kilometers");
Beyond duplicate = (Beyond) visitor.visit(filter, null);
assertThat(duplicate.getExpression1(), is(pt1));
assertThat(duplicate.getExpression2(), is(pt2));
assertThat(duplicate.getDistanceUnits(), is(UomOgcMapping.METRE.name()));
assertThat(duplicate.getDistance(), is(1000 * val));
}
use of com.vividsolutions.jts.geom.GeometryFactory in project ddf by codice.
the class TestCswRecordMapperFilterVisitor method testIntersectsUtm.
@Test
public void testIntersectsUtm() throws FactoryException, TransformException {
double lon = 33.45;
double lat = 25.22;
double easting = 545328.48;
double northing = 2789384.24;
CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:32636");
GeometryFactory geoFactory = new GeometryFactory();
Geometry utmPoint = geoFactory.createPoint(new Coordinate(easting, northing));
utmPoint.setUserData(sourceCRS);
Expression pt1 = factory.literal(geoFactory.createPoint(new Coordinate(1, 2)));
Expression pt2 = factory.literal(utmPoint);
Intersects filter = factory.intersects(pt1, pt2);
visitor.visit(filter, null);
assertThat(pt2, instanceOf(Literal.class));
Literal literalExpression = (Literal) pt2;
assertThat(literalExpression.getValue(), instanceOf(Geometry.class));
Geometry geometry = (Geometry) literalExpression.getValue();
assertThat(geometry.getCoordinates()[0].x, closeTo(lon, .00001));
assertThat(geometry.getCoordinates()[0].y, closeTo(lat, .00001));
}
use of com.vividsolutions.jts.geom.GeometryFactory in project ddf by codice.
the class FeatureCollectionConverterWfs10 method getBounds.
private Geometry getBounds(List<Metacard> metacards) {
if (metacards != null) {
List<Geometry> geometries = new ArrayList<Geometry>();
for (Metacard card : metacards) {
if (null != card.getLocation()) {
Geometry geo = XmlNode.readGeometry(card.getLocation());
if (null != geo) {
geometries.add(geo);
}
}
}
Geometry allGeometry = new GeometryCollection(geometries.toArray(new Geometry[0]), new GeometryFactory());
return allGeometry;
} else {
LOGGER.debug("List of metacards was null.");
return null;
}
}
Aggregations