use of com.vividsolutions.jts.geom.CoordinateList in project OsmAnd-tools by osmandapp.
the class Ring method toLinearRing.
public LinearRing toLinearRing() {
GeometryFactory geometryFactory = new GeometryFactory();
CoordinateList coordinates = new CoordinateList();
for (Node node : border.getNodes()) {
coordinates.add(new Coordinate(node.getLatitude(), node.getLongitude()), true);
}
coordinates.closeRing();
return geometryFactory.createLinearRing(coordinates.toCoordinateArray());
}
use of com.vividsolutions.jts.geom.CoordinateList in project incubator-rya by apache.
the class EventDocumentConverter method fromDocument.
@Override
public Event fromDocument(final Document document) throws DocumentConverterException {
requireNonNull(document);
final boolean isInstant;
// Preconditions.
if (!document.containsKey(SUBJECT)) {
throw new DocumentConverterException("Could not convert document '" + document + "' because its '" + SUBJECT + "' field is missing.");
}
if (document.containsKey(INSTANT)) {
isInstant = true;
} else {
isInstant = false;
}
final String subject = document.getString(SUBJECT);
final Event.Builder builder = new Event.Builder().setSubject(new RyaURI(subject));
if (document.containsKey(GEO_KEY)) {
final Document geoObj = (Document) document.get(GEO_KEY);
final GeometryFactory geoFact = new GeometryFactory();
final String typeString = (String) geoObj.get("type");
final CoordinateList coords = new CoordinateList();
final Geometry geo;
if (typeString.equals("Point")) {
final List<Double> point = (List<Double>) geoObj.get("coordinates");
final Coordinate coord = new Coordinate(point.get(0), point.get(1));
geo = geoFact.createPoint(coord);
} else if (typeString.equals("LineString")) {
final List<List<Double>> pointsList = (List<List<Double>>) geoObj.get("coordinates");
for (final List<Double> point : pointsList) {
coords.add(new Coordinate(point.get(0), point.get(1)));
}
geo = geoFact.createLineString(coords.toCoordinateArray());
} else {
final List<List<List<Double>>> pointsList = (List<List<List<Double>>>) geoObj.get("coordinates");
if (pointsList.size() == 1) {
final List<List<Double>> poly = pointsList.get(0);
for (final List<Double> point : poly) {
coords.add(new Coordinate(point.get(0), point.get(1)));
}
geo = geoFact.createPolygon(coords.toCoordinateArray());
} else {
final List<List<Double>> first = pointsList.get(0);
final CoordinateList shellCoords = new CoordinateList();
for (final List<Double> point : pointsList.get(0)) {
shellCoords.add(new Coordinate(point.get(0), point.get(1)));
}
final LinearRing shell = geoFact.createLinearRing(shellCoords.toCoordinateArray());
final List<List<List<Double>>> holesPoints = pointsList.subList(1, pointsList.size() - 1);
final LinearRing[] holes = new LinearRing[holesPoints.size()];
for (int ii = 0; ii < holes.length; ii++) {
final List<List<Double>> holePoints = holesPoints.get(ii);
final CoordinateList shells = new CoordinateList();
for (final List<Double> point : pointsList.get(0)) {
shells.add(new Coordinate(point.get(0), point.get(1)));
}
holes[ii] = geoFact.createLinearRing(shells.toCoordinateArray());
}
geo = geoFact.createPolygon(shell, holes);
}
}
builder.setGeometry(geo);
}
if (isInstant) {
// we already know the key exists
final Date date = (Date) document.get(INSTANT);
final DateTime dt = new DateTime(date.getTime());
final TemporalInstant instant = new TemporalInstantRfc3339(dt);
builder.setTemporalInstant(instant);
} else if (document.containsKey(INTERVAL_START)) {
Date date = (Date) document.get(INTERVAL_START);
DateTime dt = new DateTime(date.getTime());
final TemporalInstant begining = new TemporalInstantRfc3339(dt);
date = (Date) document.get(INTERVAL_END);
dt = new DateTime(date.getTime());
final TemporalInstant end = new TemporalInstantRfc3339(dt);
final TemporalInterval interval = new TemporalInterval(begining, end);
builder.setTemporalInterval(interval);
}
return builder.build();
}
Aggregations