[R-sig-Geo] Convert geojson file to R

Miluji Sb m||uj|@b @end|ng |rom gm@||@com
Mon Nov 28 21:08:13 CET 2022


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 using gmail.com> wrote:

> 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 using gmail.com> wrote:
>
>> Greetings everyone,
>>
>> I would like to convert the geojson file (
>>
>> https://drive.google.com/file/d/18h3sOjZg5jp5euLTWRi5mC40Sja8TZDN/view?usp=sharing
>> )
>> 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 highly
>> 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]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo using r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list