Skip to content

Commit

Permalink
MultiPolygon; closes #2463
Browse files Browse the repository at this point in the history
  • Loading branch information
edzer committed Oct 29, 2024
1 parent 90980f7 commit 13a42be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/sfc-sfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,16 @@ LogicalVector sfc_is_empty(List sfc) {
}
}
}
} else
is_empty = (item_len == 0) || (TYPEOF(item) == VECSXP && Rf_length(VECTOR_ELT(item, 0)) == 0); // #2463
} else {
if (item_len == 0)
is_empty = true;
else if (TYPEOF(item) == VECSXP) { // #2463
item = VECTOR_ELT(item, 0);
is_empty = Rf_length(item) == 0 || // e.g. POLYGON with 1 ring without coordinates
(TYPEOF(item) == VECSXP && Rf_length(VECTOR_ELT(item, 0)) == 0); // same for one level deeper, e.g. MULTIPOLYGON:
} else
is_empty = false;
}
out[i] = is_empty;
}

Expand Down
5 changes: 5 additions & 0 deletions tests/sfc.R
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,8 @@ st_exterior_ring(st_sf(a = 1, geom = spl1))
st_exterior_ring(smpl1[[1]])
st_exterior_ring(st_sfc(smpl1))
st_exterior_ring(st_sf(a = 1, geom = st_sfc(smpl1)))

'{"type":"Polygon","coordinates":[[]]}' |> read_sf() |> st_is_empty()
# '{"type":"Polygon","coordinates":[]}' |> read_sf() |> st_is_empty() # breaks on GDAL < 3.9 or so
'{"type":"MultiPolygon","coordinates":[[[]]]}' |> read_sf() |> st_is_empty()
'{"type":"MultiPolygon","coordinates":[[]]}' |> read_sf() |> st_is_empty()

0 comments on commit 13a42be

Please sign in to comment.