Search in sources :

Example 1 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 2 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 3 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 4 with LngLatAlt

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

the class LineStringTest method itShouldSerializeMultiPoint.

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

Example 5 with LngLatAlt

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

the class MultiLineStringTest method itShouldSerialize.

@Test
public void itShouldSerialize() throws Exception {
    MultiLineString multiLineString = new MultiLineString();
    multiLineString.add(Arrays.asList(new LngLatAlt(100, 0), new LngLatAlt(101, 1)));
    multiLineString.add(Arrays.asList(new LngLatAlt(102, 2), new LngLatAlt(103, 3)));
    assertEquals("{\"type\":\"MultiLineString\",\"coordinates\":" + "[[[100.0,0.0],[101.0,1.0]],[[102.0,2.0],[103.0,3.0]]]}", mapper.writeValueAsString(multiLineString));
}
Also used : MultiLineString(org.geojson.MultiLineString) LngLatAlt(org.geojson.LngLatAlt) Test(org.junit.Test)

Aggregations

LngLatAlt (org.geojson.LngLatAlt)16 Test (org.junit.Test)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 MultiPoint (org.geojson.MultiPoint)3 Polygon (org.geojson.Polygon)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 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MultiLineString (org.geojson.MultiLineString)1 MultiPolygon (org.geojson.MultiPolygon)1 Location (org.onebusaway.gtfs.model.Location)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 CollectSurveyContext (org.openforis.collect.model.CollectSurveyContext)1 SamplingDesignItem (org.openforis.collect.model.SamplingDesignItem)1