use of org.rutebanken.tiamat.geo.DoubleValuesToCoordinateSequence in project tiamat by entur.
the class PolygonConverter method convertFrom.
@Override
public Polygon convertFrom(PolygonType polygonType, Type<Polygon> type, MappingContext mappingContext) {
Optional<List<Double>> optionalExteriorValues = Optional.ofNullable(polygonType).map(PolygonType::getExterior).map(this::extractValues);
Optional<List<List<Double>>> interiorValues = Optional.ofNullable(polygonType).map(PolygonType::getInterior).map(list -> list.stream().map(this::extractValues).collect(Collectors.toList())).filter(list -> !list.isEmpty());
if (optionalExteriorValues.isPresent()) {
List<Double> exteriorValues = optionalExteriorValues.get();
CoordinateSequence exteriorCoordinateSequence = doubleValuesToCoordinateSequence.convert(exteriorValues);
LinearRing exteriorLinearRing = new LinearRing(exteriorCoordinateSequence, geometryFactory);
LinearRing[] interiorHoles = null;
if (interiorValues.isPresent()) {
interiorHoles = interiorValues.get().stream().map(doubleValuesToCoordinateSequence::convert).map(coordinateSequence -> new LinearRing(coordinateSequence, geometryFactory)).toArray(size -> new LinearRing[size]);
}
return new Polygon(exteriorLinearRing, interiorHoles, geometryFactory);
}
logger.warn("Cannot convert polygon from PolygonType. Cannot find exterior values: {}", polygonType);
return null;
}
Aggregations