Skip to content

Commit

Permalink
Merge pull request #2468 from rouault/fix_2466
Browse files Browse the repository at this point in the history
CPL_area(): use proper casts to OGRGeometry subtypes, in particular to fix issues with GeometryCollection of Polygon
  • Loading branch information
edzer authored Nov 2, 2024
2 parents 5f44d8d + 88f4f55 commit dc02f71
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/gdal_geom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ Rcpp::NumericVector CPL_area(Rcpp::List sfc) {
for (size_t i = 0; i < g.size(); i++) {
if (g[i]->getDimension() == 2) {
OGRwkbGeometryType gt = OGR_GT_Flatten(g[i]->getGeometryType());
if (gt == wkbMultiSurface || gt == wkbMultiPolygon) {
if (OGR_GT_IsSubClassOf(gt, wkbGeometryCollection)) {
// will match OGRMultiPolygon, OGRMultiSurface and OGRGeometryCollection
OGRGeometryCollection *gc = (OGRGeometryCollection *) g[i];
out[i] = gc->get_Area();
} else {
} else if (OGR_GT_IsSurface(gt)) {
OGRSurface *surf = (OGRSurface *) g[i];
out[i] = surf->get_Area();
}
} else {
out[i] = 0.0; // not supposed to happen, but who knows...
}
} else
out[i] = 0.0;
OGRGeometryFactory::destroyGeometry(g[i]);
Expand Down

0 comments on commit dc02f71

Please sign in to comment.