Skip to content

Commit d3e2c54

Browse files
committed
address r-spatial#2466, incorporate r-spatial#2468 and r-spatial#2469
1 parent 0d1a48b commit d3e2c54

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# version 1.0-19
22

3+
* fix ambiguities in `CPL_area` and `CPL_length` revealed in testing with GDAL 3.10.0 release candidates ; #2466, #2468, #2429
4+
35
* improve test on empty geometries, which changed in 1.0-18; #2463
46

57
* `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)

src/gdal_geom.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@ 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+
// PR 2468
16+
// if (gt == wkbMultiSurface || gt == wkbMultiPolygon) {
17+
if (OGR_GT_IsSubClassOf(gt, wkbGeometryCollection)) {
18+
// will match OGRMultiPolygon, OGRMultiSurface and OGRGeometryCollection
1619
OGRGeometryCollection *gc = (OGRGeometryCollection *) g[i];
1720
out[i] = gc->get_Area();
18-
} else {
21+
} else if (OGR_GT_IsSurface(gt)) {
1922
OGRSurface *surf = (OGRSurface *) g[i];
2023
out[i] = surf->get_Area();
21-
}
22-
} else
24+
} else {
25+
out[i] = 0.0; // not supposed to happen, but who knows...
26+
}
27+
} else
2328
out[i] = 0.0;
2429
OGRGeometryFactory::destroyGeometry(g[i]);
2530
}
@@ -63,8 +68,15 @@ Rcpp::NumericVector CPL_length(Rcpp::List sfc) {
6368
}
6469
break;
6570
default: {
66-
OGRGeometryCollection *a = (OGRGeometryCollection *) g[i];
67-
out[i] = a->get_Length();
71+
// PR 2469
72+
/* OGRGeometryCollection *a = (OGRGeometryCollection *) g[i];
73+
out[i] = a->get_Length();*/
74+
if (OGR_GT_IsSubClassOf(gt, wkbGeometryCollection)) {
75+
OGRGeometryCollection *a = (OGRGeometryCollection *) g[i];
76+
out[i] = a->get_Length();
77+
} else {
78+
out[i] = 0.0;
79+
}
6880
}
6981
}
7082
OGRGeometryFactory f;

0 commit comments

Comments
 (0)