use of com.vividsolutions.jts.geom.LineString in project elasticsearch by elastic.
the class GeoJSONShapeParserTests method testParseLineString.
public void testParseLineString() throws IOException {
XContentBuilder lineGeoJson = XContentFactory.jsonBuilder().startObject().field("type", "LineString").startArray("coordinates").startArray().value(100.0).value(0.0).endArray().startArray().value(101.0).value(1.0).endArray().endArray().endObject();
List<Coordinate> lineCoordinates = new ArrayList<>();
lineCoordinates.add(new Coordinate(100, 0));
lineCoordinates.add(new Coordinate(101, 1));
LineString expected = GEOMETRY_FACTORY.createLineString(lineCoordinates.toArray(new Coordinate[lineCoordinates.size()]));
assertGeometryEquals(jtsGeom(expected), lineGeoJson);
}
use of com.vividsolutions.jts.geom.LineString in project elasticsearch by elastic.
the class ShapeBuilderTests method testNewPolygon_coordinates.
public void testNewPolygon_coordinates() {
Polygon polygon = ShapeBuilders.newPolygon(new CoordinatesBuilder().coordinates(new Coordinate(-45, 30), new Coordinate(45, 30), new Coordinate(45, -30), new Coordinate(-45, -30), new Coordinate(-45, 30))).toPolygon();
LineString exterior = polygon.getExteriorRing();
assertEquals(exterior.getCoordinateN(0), new Coordinate(-45, 30));
assertEquals(exterior.getCoordinateN(1), new Coordinate(45, 30));
assertEquals(exterior.getCoordinateN(2), new Coordinate(45, -30));
assertEquals(exterior.getCoordinateN(3), new Coordinate(-45, -30));
}
use of com.vividsolutions.jts.geom.LineString in project elasticsearch-jdbc by jprante.
the class GeoJSONShapeSerializer method serializePolygonCoordinates.
/**
* Serializes the actual coordinates of the given {@link Polygon}
*
* @param polygon Polygon whose coordinates will be serialized
* @param builder XContentBuilder it will be serialized to
* @throws IOException Thrown if an error occurs while writing to the XContentBuilder
*/
private static void serializePolygonCoordinates(Polygon polygon, XContentBuilder builder) throws IOException {
// start outer ring
builder.startArray();
for (Coordinate coordinate : polygon.getExteriorRing().getCoordinates()) {
serializeCoordinate(coordinate, builder);
}
// end outer ring
builder.endArray();
for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
LineString interiorRing = polygon.getInteriorRingN(i);
builder.startArray();
for (Coordinate coordinate : interiorRing.getCoordinates()) {
serializeCoordinate(coordinate, builder);
}
builder.endArray();
}
}
use of com.vividsolutions.jts.geom.LineString in project series-rest-api by 52North.
the class GeoJSONEncoder method encode.
protected ObjectNode encode(MultiLineString geometry, int parentSrid) {
ObjectNode json = jsonFactory.objectNode();
ArrayNode list = json.put(JSONConstants.TYPE, JSONConstants.MULTI_LINE_STRING).putArray(JSONConstants.COORDINATES);
for (int i = 0; i < geometry.getNumGeometries(); ++i) {
list.add(encodeCoordinates((LineString) geometry.getGeometryN(i)));
}
encodeCRS(json, geometry, parentSrid);
return json;
}
use of com.vividsolutions.jts.geom.LineString in project series-rest-api by 52North.
the class GeoJSONTest method testLineStringWithZCoordinate.
@Test
public void testLineStringWithZCoordinate() {
LineString geometry = randomLineString(CRSUtils.EPSG_WGS84);
geometry.apply(new RandomZCoordinateFilter());
geometry.geometryChanged();
readWriteTest(geometry);
}
Aggregations