Search in sources :

Example 1 with DoubleValuesToCoordinateSequence

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;
}
Also used : CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) LinearRing(org.locationtech.jts.geom.LinearRing) LoggerFactory(org.slf4j.LoggerFactory) PolygonType(net.opengis.gml._3.PolygonType) Coordinate(org.locationtech.jts.geom.Coordinate) Autowired(org.springframework.beans.factory.annotation.Autowired) MappingContext(ma.glasnost.orika.MappingContext) ArrayList(java.util.ArrayList) DoubleValuesToCoordinateSequence(org.rutebanken.tiamat.geo.DoubleValuesToCoordinateSequence) DirectPositionListType(net.opengis.gml._3.DirectPositionListType) BidirectionalConverter(ma.glasnost.orika.converter.BidirectionalConverter) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Logger(org.slf4j.Logger) ObjectFactory(net.opengis.gml._3.ObjectFactory) LinearRingType(net.opengis.gml._3.LinearRingType) JAXBElement(javax.xml.bind.JAXBElement) Type(ma.glasnost.orika.metadata.Type) Collectors(java.util.stream.Collectors) LineString(org.locationtech.jts.geom.LineString) AtomicLong(java.util.concurrent.atomic.AtomicLong) AbstractRingPropertyType(net.opengis.gml._3.AbstractRingPropertyType) Component(org.springframework.stereotype.Component) List(java.util.List) Polygon(org.locationtech.jts.geom.Polygon) Optional(java.util.Optional) CoordinateSequence(org.locationtech.jts.geom.CoordinateSequence) DoubleValuesToCoordinateSequence(org.rutebanken.tiamat.geo.DoubleValuesToCoordinateSequence) ArrayList(java.util.ArrayList) List(java.util.List) PolygonType(net.opengis.gml._3.PolygonType) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Collectors (java.util.stream.Collectors)1 JAXBElement (javax.xml.bind.JAXBElement)1 MappingContext (ma.glasnost.orika.MappingContext)1 BidirectionalConverter (ma.glasnost.orika.converter.BidirectionalConverter)1 Type (ma.glasnost.orika.metadata.Type)1 AbstractRingPropertyType (net.opengis.gml._3.AbstractRingPropertyType)1 DirectPositionListType (net.opengis.gml._3.DirectPositionListType)1 LinearRingType (net.opengis.gml._3.LinearRingType)1 ObjectFactory (net.opengis.gml._3.ObjectFactory)1 PolygonType (net.opengis.gml._3.PolygonType)1 Coordinate (org.locationtech.jts.geom.Coordinate)1 CoordinateSequence (org.locationtech.jts.geom.CoordinateSequence)1 GeometryFactory (org.locationtech.jts.geom.GeometryFactory)1 LineString (org.locationtech.jts.geom.LineString)1 LinearRing (org.locationtech.jts.geom.LinearRing)1 Polygon (org.locationtech.jts.geom.Polygon)1