File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -360,3 +360,8 @@ st_exterior_ring(st_sf(a = 1, geom = spl1))
360360st_exterior_ring(smpl1 [[1 ]])
361361st_exterior_ring(st_sfc(smpl1 ))
362362st_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()
You can’t perform that action at this time.
0 commit comments