Skip to content

Commit

Permalink
address r-spatial#2466, incorporate r-spatial#2468 and r-spatial#2469
Browse files Browse the repository at this point in the history
  • Loading branch information
rsbivand committed Nov 1, 2024
1 parent 0d1a48b commit d3e2c54
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
24 changes: 18 additions & 6 deletions src/gdal_geom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d3e2c54

Please sign in to comment.