use of org.geotoolkit.gml.xml.AbstractRingProperty in project geotoolkit by Geomatys.
the class GeometryTransformer method convertPolygonLike.
private Polygon convertPolygonLike(AbstractRingProperty exteriorProperty, final List<? extends AbstractRingProperty> interiorProperties) {
final AbstractRing exterior = exteriorProperty.getAbstractRing();
final Geometry extRing = new GeometryTransformer(exterior, this).get();
// Check now to avoid costly parsing of interior geometries
if (!(extRing instanceof LinearRing)) {
throw new UnconvertibleObjectException("Cannot create a polygon, because its exterior is not a ring");
}
final LinearRing[] interiors;
try {
final Stream<? extends AbstractRingProperty> interiorStream = interiorProperties == null ? Stream.empty() : interiorProperties.stream();
interiors = interiorStream.map(AbstractRingProperty::getAbstractRing).map(ring -> new GeometryTransformer(ring, this).get()).map(LinearRing.class::cast).toArray(size -> new LinearRing[size]);
} catch (ClassCastException e) {
throw new UnconvertibleObjectException("Cannot create a polygon, because some of its interior geometries are not rings", e);
}
final Polygon poly = GF.createPolygon((LinearRing) extRing, interiors);
applyCRS(poly);
return poly;
}
Aggregations