Skip to content

Commit cff3a00

Browse files
committed
Fix empty multipolygon
1 parent f6119fb commit cff3a00

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/main/groovy/geoscript/geom/MultiPolygon.groovy

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,13 @@ class MultiPolygon extends GeometryCollection {
118118
* Create a JTS MultiPolygon from a List of Polygons
119119
*/
120120
private static create(Polygon... polygons) {
121-
Geometry.factory.createMultiPolygon(polygons.collect{
121+
if (polygons.size() == 0) {
122+
Geometry.factory.createMultiPolygon()
123+
} else {
124+
Geometry.factory.createMultiPolygon(polygons.collect {
122125
polygon -> polygon.g
123126
}.toArray() as JtsPolygon[])
127+
}
124128
}
125129

126130
/**
@@ -133,17 +137,21 @@ class MultiPolygon extends GeometryCollection {
133137
if (p.size() > 0) {
134138
create(*p)
135139
} else {
136-
create(new Polygon())
140+
Geometry.factory.createMultiPolygon()
137141
}
138142
}
139143

140144
/**
141145
* Create a JTS MultiPolygon from a List of Polygons or a List of List of Doubles
142146
*/
143147
private static create(List polygons) {
144-
List<Polygon> p = polygons.collect{poly ->
145-
(poly instanceof Polygon) ? poly : new Polygon(poly)
148+
if (polygons.isEmpty()) {
149+
Geometry.factory.createMultiPolygon()
150+
} else {
151+
List<Polygon> p = polygons.collect { poly ->
152+
(poly instanceof Polygon) ? poly : new Polygon(poly)
153+
}
154+
create(*p)
146155
}
147-
create(*p)
148156
}
149157
}

0 commit comments

Comments
 (0)