Search in sources :

Example 1 with Point

use of org.geojson.Point in project geojson-jackson by opendatalab-de.

the class PointTest method itShouldSerializeAPointWithAdditionalAttributes.

@Test
public void itShouldSerializeAPointWithAdditionalAttributes() throws JsonProcessingException {
    Point point = new Point(100, 0, 256, 345d, 678d);
    assertEquals("{\"type\":\"Point\",\"coordinates\":[100.0,0.0,256.0,345.0,678.0]}", mapper.writeValueAsString(point));
}
Also used : Point(org.geojson.Point) Test(org.junit.Test)

Example 2 with Point

use of org.geojson.Point in project geojson-jackson by opendatalab-de.

the class PointTest method itShouldSerializeAPointWithAltitude.

@Test
public void itShouldSerializeAPointWithAltitude() throws Exception {
    Point point = new Point(100, 0, 256);
    assertEquals("{\"type\":\"Point\",\"coordinates\":[100.0,0.0,256.0]}", mapper.writeValueAsString(point));
}
Also used : Point(org.geojson.Point) Test(org.junit.Test)

Example 3 with Point

use of org.geojson.Point in project OpenTripPlanner by opentripplanner.

the class BanoGeocoder method geocode.

/**
 */
@Override
public GeocoderResults geocode(String address, Envelope bbox) {
    try {
        URL banoUrl = getBanoGeocoderUrl(address, bbox);
        URLConnection conn = banoUrl.openConnection();
        InputStream in = conn.getInputStream();
        FeatureCollection featureCollection = mapper.readValue(in, FeatureCollection.class);
        in.close();
        List<GeocoderResult> geocoderResults = new ArrayList<GeocoderResult>();
        for (Feature feature : featureCollection.getFeatures()) {
            GeoJsonObject geom = feature.getGeometry();
            if (geom instanceof Point) {
                Point p = (Point) geom;
                GeocoderResult res = new GeocoderResult();
                res.setLat(p.getCoordinates().getLatitude());
                res.setLng(p.getCoordinates().getLongitude());
                res.setDescription(feature.getProperties().get("label").toString());
                /*
                     * Note: We also have here as properties a break-down of other details, such as
                     * the house number, street, city, postcode... Can be useful if needed.
                     */
                geocoderResults.add(res);
            } else {
            // Should not happen according to the API
            }
        }
        return new GeocoderResults(geocoderResults);
    } catch (IOException e) {
        LOG.error("Error processing BANO geocoder results", e);
        return new GeocoderResults(e.getLocalizedMessage());
    }
}
Also used : GeocoderResults(org.opentripplanner.geocoder.GeocoderResults) FeatureCollection(org.geojson.FeatureCollection) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Point(org.geojson.Point) IOException(java.io.IOException) GeoJsonObject(org.geojson.GeoJsonObject) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) Feature(org.geojson.Feature) URL(java.net.URL) URLConnection(java.net.URLConnection) GeocoderResult(org.opentripplanner.geocoder.GeocoderResult)

Example 4 with Point

use of org.geojson.Point in project geojson-jackson by opendatalab-de.

the class PointTest method itShouldSerializeAPoint.

@Test
public void itShouldSerializeAPoint() throws Exception {
    Point point = new Point(100, 0);
    assertEquals("{\"type\":\"Point\",\"coordinates\":[100.0,0.0]}", mapper.writeValueAsString(point));
}
Also used : Point(org.geojson.Point) Test(org.junit.Test)

Example 5 with Point

use of org.geojson.Point in project geojson-jackson by opendatalab-de.

the class PointTest method itShouldDeserializeAPoint.

@Test
public void itShouldDeserializeAPoint() throws Exception {
    GeoJsonObject value = mapper.readValue("{\"type\":\"Point\",\"coordinates\":[100.0,5.0]}", GeoJsonObject.class);
    assertNotNull(value);
    assertTrue(value instanceof Point);
    Point point = (Point) value;
    assertLngLatAlt(100, 5, Double.NaN, point.getCoordinates());
}
Also used : Point(org.geojson.Point) GeoJsonObject(org.geojson.GeoJsonObject) Test(org.junit.Test)

Aggregations

Point (org.geojson.Point)9 Test (org.junit.Test)8 GeoJsonObject (org.geojson.GeoJsonObject)4 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 ArrayList (java.util.ArrayList)1 Crs (org.geojson.Crs)1 Feature (org.geojson.Feature)1 FeatureCollection (org.geojson.FeatureCollection)1 GeocoderResult (org.opentripplanner.geocoder.GeocoderResult)1 GeocoderResults (org.opentripplanner.geocoder.GeocoderResults)1