Search in sources :

Example 6 with Point

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;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 7 with Point

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);
}
Also used : Point(com.vividsolutions.jts.geom.Point) GeojsonPoint(org.n52.io.geojson.old.GeojsonPoint) Before(org.junit.Before)

Example 8 with Point

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"));
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Coordinate(com.vividsolutions.jts.geom.Coordinate) Point(com.vividsolutions.jts.geom.Point) Test(org.junit.Test)

Example 9 with Point

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;
}
Also used : Point(com.vividsolutions.jts.geom.Point) MultiPoint(com.vividsolutions.jts.geom.MultiPoint)

Example 10 with Point

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;
}
Also used : GeometryFactory(com.vividsolutions.jts.geom.GeometryFactory) Configuration(org.geotools.xml.Configuration) ArrayList(java.util.ArrayList) Point(com.vividsolutions.jts.geom.Point) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) Parser(org.geotools.xml.Parser) Geometry(com.vividsolutions.jts.geom.Geometry) Coordinate(com.vividsolutions.jts.geom.Coordinate) StringReader(java.io.StringReader) Polygon(com.vividsolutions.jts.geom.Polygon)

Aggregations

Point (com.vividsolutions.jts.geom.Point)46 Coordinate (com.vividsolutions.jts.geom.Coordinate)20 Geometry (com.vividsolutions.jts.geom.Geometry)15 Test (org.junit.Test)12 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)11 GeometryFactory (com.vividsolutions.jts.geom.GeometryFactory)9 Polygon (com.vividsolutions.jts.geom.Polygon)9 LineString (com.vividsolutions.jts.geom.LineString)7 MultiLineString (com.vividsolutions.jts.geom.MultiLineString)5 Envelope (com.vividsolutions.jts.geom.Envelope)4 GeometryCollection (com.vividsolutions.jts.geom.GeometryCollection)4 ParseException (com.vividsolutions.jts.io.ParseException)4 ArrayList (java.util.ArrayList)4 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)4 GeojsonPoint (org.n52.io.geojson.old.GeojsonPoint)4 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)3 StringReader (java.io.StringReader)3 SolrQuery (org.apache.solr.client.solrj.SolrQuery)3 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)3 JtsPoint (org.locationtech.spatial4j.shape.jts.JtsPoint)3