use of com.vividsolutions.jts.geom.Point in project series-rest-api by 52North.
the class GeoJSONEncoder method encode.
protected ObjectNode encode(MultiPoint geometry, int parentSrid) {
ObjectNode json = jsonFactory.objectNode();
ArrayNode list = json.put(JSONConstants.TYPE, JSONConstants.MULTI_POINT).putArray(JSONConstants.COORDINATES);
for (int i = 0; i < geometry.getNumGeometries(); ++i) {
list.add(encodeCoordinates((Point) geometry.getGeometryN(i)));
}
encodeCRS(json, geometry, parentSrid);
return json;
}
use of com.vividsolutions.jts.geom.Point in project series-rest-api by 52North.
the class CRSUtilsTest method setUp.
@Before
public void setUp() throws Exception {
referenceHelper = CRSUtils.createEpsgStrictAxisOrder();
Point ll = referenceHelper.createPoint(6.4, 51.9, DEFAULT_CRS);
Point ur = referenceHelper.createPoint(8.9, 53.4, DEFAULT_CRS);
// EastingNorthing ll = new EastingNorthing(6.4, 51.9, DEFAULT_CRS);
// EastingNorthing ur = new EastingNorthing(8.9, 53.4, DEFAULT_CRS);
bbox = new BoundingBox(ll, ur, DEFAULT_CRS);
}
use of com.vividsolutions.jts.geom.Point in project series-rest-api by 52North.
the class GeotoolsJTSReferenceTester method shouldCreateCRS84.
@Test
public void shouldCreateCRS84() throws Exception {
CRSUtils respectEpsgOrder = CRSUtils.createEpsgStrictAxisOrder();
GeometryFactory strictFactory = respectEpsgOrder.createGeometryFactory("EPSG:4326");
Point strictPoint = strictFactory.createPoint(new Coordinate(52.3, 7.4));
LOGGER.info("EPSG:4326 as JTS point (strict EPSG order): {}", strictPoint);
LOGGER.info("Transformed to CRS:84: {}", respectEpsgOrder.transform(strictPoint, "EPSG:4326", "CRS:84"));
}
use of com.vividsolutions.jts.geom.Point in project series-rest-api by 52North.
the class GeoJSONTest method randomPoint.
private Point randomPoint(int srid) {
Point geometry = geometryFactory.createPoint(randomCoordinate());
geometry.setSRID(srid);
return geometry;
}
use of com.vividsolutions.jts.geom.Point 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;
}
Aggregations