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();
}
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;
}
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;
}
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));
}
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));
}
Aggregations