Skip to content

Commit dc02f71

Browse files
authored
Merge pull request #2468 from rouault/fix_2466
CPL_area(): use proper casts to OGRGeometry subtypes, in particular to fix issues with GeometryCollection of Polygon
2 parents 5f44d8d + 88f4f55 commit dc02f71

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/gdal_geom.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ Rcpp::NumericVector CPL_area(Rcpp::List sfc) {
1212
for (size_t i = 0; i < g.size(); i++) {
1313
if (g[i]->getDimension() == 2) {
1414
OGRwkbGeometryType gt = OGR_GT_Flatten(g[i]->getGeometryType());
15-
if (gt == wkbMultiSurface || gt == wkbMultiPolygon) {
15+
if (OGR_GT_IsSubClassOf(gt, wkbGeometryCollection)) {
16+
// will match OGRMultiPolygon, OGRMultiSurface and OGRGeometryCollection
1617
OGRGeometryCollection *gc = (OGRGeometryCollection *) g[i];
1718
out[i] = gc->get_Area();
18-
} else {
19+
} else if (OGR_GT_IsSurface(gt)) {
1920
OGRSurface *surf = (OGRSurface *) g[i];
2021
out[i] = surf->get_Area();
21-
}
22+
} else {
23+
out[i] = 0.0; // not supposed to happen, but who knows...
24+
}
2225
} else
2326
out[i] = 0.0;
2427
OGRGeometryFactory::destroyGeometry(g[i]);

0 commit comments

Comments
 (0)