Skip to content

Commit 13a42be

Browse files
committed
MultiPolygon; closes #2463
1 parent 90980f7 commit 13a42be

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/sfc-sfg.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,16 @@ LogicalVector sfc_is_empty(List sfc) {
119119
}
120120
}
121121
}
122-
} else
123-
is_empty = (item_len == 0) || (TYPEOF(item) == VECSXP && Rf_length(VECTOR_ELT(item, 0)) == 0); // #2463
122+
} else {
123+
if (item_len == 0)
124+
is_empty = true;
125+
else if (TYPEOF(item) == VECSXP) { // #2463
126+
item = VECTOR_ELT(item, 0);
127+
is_empty = Rf_length(item) == 0 || // e.g. POLYGON with 1 ring without coordinates
128+
(TYPEOF(item) == VECSXP && Rf_length(VECTOR_ELT(item, 0)) == 0); // same for one level deeper, e.g. MULTIPOLYGON:
129+
} else
130+
is_empty = false;
131+
}
124132
out[i] = is_empty;
125133
}
126134

tests/sfc.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,8 @@ st_exterior_ring(st_sf(a = 1, geom = spl1))
360360
st_exterior_ring(smpl1[[1]])
361361
st_exterior_ring(st_sfc(smpl1))
362362
st_exterior_ring(st_sf(a = 1, geom = st_sfc(smpl1)))
363+
364+
'{"type":"Polygon","coordinates":[[]]}' |> read_sf() |> st_is_empty()
365+
# '{"type":"Polygon","coordinates":[]}' |> read_sf() |> st_is_empty() # breaks on GDAL < 3.9 or so
366+
'{"type":"MultiPolygon","coordinates":[[[]]]}' |> read_sf() |> st_is_empty()
367+
'{"type":"MultiPolygon","coordinates":[[]]}' |> read_sf() |> st_is_empty()

0 commit comments

Comments
 (0)