Skip to content

Commit

Permalink
CPL_area(): use proper casts to OGRGeometry subtypes, in particular t…
Browse files Browse the repository at this point in the history
…o fix issues with GeometryCollection of Polygon

Fixes #2466
  • Loading branch information
rouault committed Nov 1, 2024
1 parent 0d1a48b commit 88f4f55
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 88f4f55

Please sign in to comment.