This seems to be a weird bug in `st_read`. If you read it with an SQL
query that matches every row it works:
js = st_read("./countrymasks.geojson", query="select * from countrymasks
where 1 = 1")
Reading query `select * from countrymasks where 1 = 1' from data
source `/home/rowlings/Downloads/countrymasks.geojson' using driver
`GeoJSON'
Simple feature collection with 214 features and 15 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: -180 ymin: -55.79439 xmax: 180 ymax: 83.62742
Geodetic CRS: WGS 84
But leave out the query and you get that C code level error. Another
equivalent query would be "select * from countrymasks" (without the
"where" clause) but this
triggers the error too. Very odd. Worth reporting as a bug?
Barry
On Mon, Nov 28, 2022 at 8:08 PM Miluji Sb <milujisb at gmail.com> wrote:
Thank you for reply. When I try using sf, I get the following error;
Error in CPL_read_ogr(dsn, layer, query, as.character(options), quiet, :
attempt to set index 210/210 in SET_STRING_ELT.
Thanks again!
On Mon, Nov 28, 2022 at 1:50 PM Josiah Parry <josiah.parry at gmail.com>
You're going to want to read the file with sf.
Try object <- sf::st_read("~countrymasks.geojson")
On Mon, Nov 28, 2022 at 7:09 AM Miluji Sb <milujisb at gmail.com> wrote:
Greetings everyone,
I would like to convert the geojson file (
)
to a dataframe - essentially obtain which has coordinates matched to a
country.
I have tried the following;
###
states <- geojsonsf::geojson_sf("~/countrymasks.geojson")
geo <- geojsonsf::sf_geojson(states)
sf <- sf::st_read(geo, quiet = T )
df <- as.data.frame(sf::st_coordinates(sf) )
##
But I get the following output, I am a bit lost. Any help will be
appreciated.
Best,
structure(list(X = c(-67.3804401, -67.36091, -67.3805899999999,
-67.3397099999998, -67.3780199, -67.3221199999999), Y =
c(-55.5655699999996,
-55.5840098999999, -55.6004100000001, -55.6149699999997, -55.63521,
-55.6400899999997), L1 = c(1, 1, 1, 1, 1, 1), L2 = c(1, 1, 1,
1, 1, 1), L3 = c(1, 1, 1, 1, 1, 1)), row.names = c(NA, 6L), class =
"data.frame")
[[alternative HTML version deleted]]