diff --git a/NEWS.md b/NEWS.md index 2b03ba660..3a0aec891 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # version 1.0-19 +* fix ambiguities in `CPL_area` and `CPL_length` revealed in testing with GDAL 3.10.0 release candidates ; #2466, #2468, #2429 + * improve test on empty geometries, which changed in 1.0-18; #2463 * `gdal_utils()` `ogrinfo` has an argument `read_only` which, when `TRUE` (or `options` includes `"-ro"`), opens a datasource in read-only mode (#2460; `sf` did this before 1.0-17); by default a datasource is opened in update (read-write) mode (since sf 1.0-17; #2420) diff --git a/src/gdal_geom.cpp b/src/gdal_geom.cpp index db1781bd2..46991f5a6 100644 --- a/src/gdal_geom.cpp +++ b/src/gdal_geom.cpp @@ -12,14 +12,19 @@ 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) { +// PR 2468 +// 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 + } else { + out[i] = 0.0; // not supposed to happen, but who knows... + } + } else out[i] = 0.0; OGRGeometryFactory::destroyGeometry(g[i]); } @@ -63,8 +68,15 @@ Rcpp::NumericVector CPL_length(Rcpp::List sfc) { } break; default: { - OGRGeometryCollection *a = (OGRGeometryCollection *) g[i]; - out[i] = a->get_Length(); +// PR 2469 +/* OGRGeometryCollection *a = (OGRGeometryCollection *) g[i]; + out[i] = a->get_Length();*/ + if (OGR_GT_IsSubClassOf(gt, wkbGeometryCollection)) { + OGRGeometryCollection *a = (OGRGeometryCollection *) g[i]; + out[i] = a->get_Length(); + } else { + out[i] = 0.0; + } } } OGRGeometryFactory f;