Search in sources :

Example 6 with LngLatAlt

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

the class PointSet method writeFeature.

/**
 * This writes either a polygon or lat/lon point defining the feature. In
 * the case of polygons, we convert these back to centroids on import, as
 * OTPA depends on the actual point. The polygons are kept for derivative
 * uses (e.g. visualization)
 *
 * @param i
 *            the feature index
 * @param jgen
 *            the Jackson streaming JSON generator to which the geometry
 *            will be written
 * @throws IOException
 */
private void writeFeature(int i, JsonGenerator jgen, Boolean forcePoints) throws IOException {
    ObjectMapper geomSerializer = new ObjectMapper();
    jgen.writeStartObject();
    {
        jgen.writeStringField("id", ids[i]);
        jgen.writeStringField("type", "Feature");
        jgen.writeFieldName("geometry");
        {
            if (!forcePoints && polygons != null && polygons.length >= i && polygons[i] != null) {
                org.geojson.Polygon p = new org.geojson.Polygon();
                List<LngLatAlt> shell = new ArrayList<LngLatAlt>();
                for (Coordinate c : polygons[i].getExteriorRing().getCoordinates()) {
                    shell.add(new LngLatAlt(c.x, c.y));
                }
                p.add(shell);
                geomSerializer.writeValue(jgen, p);
            } else {
                org.geojson.Point p = new org.geojson.Point(lons[i], lats[i]);
                geomSerializer.writeValue(jgen, p);
            }
        }
        jgen.writeObjectFieldStart("properties");
        {
            writeStructured(i, jgen);
        }
        jgen.writeEndObject();
    }
    jgen.writeEndObject();
}
Also used : Coordinate(com.vividsolutions.jts.geom.Coordinate) ArrayList(java.util.ArrayList) Polygon(com.vividsolutions.jts.geom.Polygon) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LngLatAlt(org.geojson.LngLatAlt)

Example 7 with LngLatAlt

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

the class GeometryUtils method convertPath.

private static Coordinate[] convertPath(List<LngLatAlt> path) {
    Coordinate[] coords = new Coordinate[path.size()];
    int i = 0;
    for (LngLatAlt p : path) {
        coords[i++] = new Coordinate(p.getLatitude(), p.getLongitude());
    }
    return coords;
}
Also used : LngLatAlt(org.geojson.LngLatAlt)

Example 8 with LngLatAlt

use of org.geojson.LngLatAlt in project collect by openforis.

the class SamplingPointsController method loadSamplingPointBounds.

@RequestMapping(value = "survey/{surveyId}/sampling_point_bounds.json", method = GET)
@ResponseBody
public Bounds loadSamplingPointBounds(@PathVariable int surveyId) {
    CollectSurvey survey = surveyManager.loadSurvey(surveyId);
    CollectSurveyContext surveyContext = survey.getContext();
    CoordinateOperations coordinateOperations = surveyContext.getCoordinateOperations();
    SamplingDesignSummaries samplingDesignSummaries = samplingDesignManager.loadBySurvey(survey.getId());
    List<SamplingDesignItem> samplingDesignItems = samplingDesignSummaries.getRecords();
    Bounds bounds = new Bounds();
    for (SamplingDesignItem item : samplingDesignItems) {
        Coordinate coordinate = new Coordinate(item.getX(), item.getY(), item.getSrsId());
        LngLatAlt lngLatAlt = createLngLatAlt(coordinateOperations, coordinate);
        if (lngLatAlt != null) {
            if (bounds.topLeft == null) {
                bounds.topLeft = bounds.topRight = bounds.bottomLeft = bounds.bottomRight = lngLatAlt;
            } else {
                if (lngLatAlt.getLatitude() < bounds.topLeft.getLatitude() && lngLatAlt.getLongitude() < bounds.topLeft.getLongitude()) {
                    bounds.topLeft = lngLatAlt;
                } else if (lngLatAlt.getLatitude() < bounds.topRight.getLatitude() && lngLatAlt.getLongitude() > bounds.topRight.getLongitude()) {
                    bounds.topRight = lngLatAlt;
                } else if (lngLatAlt.getLatitude() > bounds.bottomRight.getLatitude() && lngLatAlt.getLongitude() > bounds.bottomRight.getLongitude()) {
                    bounds.bottomRight = lngLatAlt;
                } else if (lngLatAlt.getLatitude() > bounds.bottomLeft.getLatitude() && lngLatAlt.getLongitude() > bounds.bottomLeft.getLongitude()) {
                    bounds.bottomLeft = lngLatAlt;
                }
            }
        }
    }
    return bounds;
}
Also used : CoordinateOperations(org.openforis.idm.geospatial.CoordinateOperations) Coordinate(org.openforis.idm.model.Coordinate) CollectSurveyContext(org.openforis.collect.model.CollectSurveyContext) SamplingDesignSummaries(org.openforis.collect.model.SamplingDesignSummaries) CollectSurvey(org.openforis.collect.model.CollectSurvey) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem) LngLatAlt(org.geojson.LngLatAlt) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 9 with LngLatAlt

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

the class MultiPointTest method itShouldSerializeMultiPoint.

@Test
public void itShouldSerializeMultiPoint() throws Exception {
    MultiPoint multiPoint = new MultiPoint(new LngLatAlt(100, 0), new LngLatAlt(101, 1));
    assertEquals("{\"type\":\"MultiPoint\",\"coordinates\":[[100.0,0.0],[101.0,1.0]]}", mapper.writeValueAsString(multiPoint));
}
Also used : MultiPoint(org.geojson.MultiPoint) LngLatAlt(org.geojson.LngLatAlt) Test(org.junit.Test)

Example 10 with LngLatAlt

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

the class MultiPoligonTest method itShouldSerialize.

@Test
public void itShouldSerialize() throws Exception {
    MultiPolygon multiPolygon = new MultiPolygon();
    multiPolygon.add(new Polygon(new LngLatAlt(102, 2), new LngLatAlt(103, 2), new LngLatAlt(103, 3), new LngLatAlt(102, 3), new LngLatAlt(102, 2)));
    Polygon polygon = new Polygon(MockData.EXTERNAL);
    polygon.addInteriorRing(MockData.INTERNAL);
    multiPolygon.add(polygon);
    assertEquals("{\"type\":\"MultiPolygon\",\"coordinates\":[[[[102.0,2.0],[103.0,2.0],[103.0,3.0],[102.0,3.0],[102.0,2.0]]]," + "[[[100.0,0.0],[101.0,0.0],[101.0,1.0],[100.0,1.0],[100.0,0.0]]," + "[[100.2,0.2],[100.8,0.2],[100.8,0.8],[100.2,0.8],[100.2,0.2]]]]}", mapper.writeValueAsString(multiPolygon));
}
Also used : MultiPolygon(org.geojson.MultiPolygon) MultiPolygon(org.geojson.MultiPolygon) Polygon(org.geojson.Polygon) LngLatAlt(org.geojson.LngLatAlt) Test(org.junit.Test)

Aggregations

LngLatAlt (org.geojson.LngLatAlt)14 Test (org.junit.Test)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 MultiPoint (org.geojson.MultiPoint)3 ArrayList (java.util.ArrayList)2 LineString (org.geojson.LineString)2 Coordinate (org.openforis.idm.model.Coordinate)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)1 Polygon (com.vividsolutions.jts.geom.Polygon)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MultiLineString (org.geojson.MultiLineString)1 MultiPolygon (org.geojson.MultiPolygon)1 Polygon (org.geojson.Polygon)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 CollectSurveyContext (org.openforis.collect.model.CollectSurveyContext)1 SamplingDesignItem (org.openforis.collect.model.SamplingDesignItem)1 SamplingDesignSummaries (org.openforis.collect.model.SamplingDesignSummaries)1 CoordinateOperations (org.openforis.idm.geospatial.CoordinateOperations)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1