Setting GDAL configuration options through R

I use the wonderful sf package to load to my .geojson files. I have one particularly large files (250MB) that is giving my problems due to the size limit set by GDAL when using the GEOJSON driver, as documented here. To read my file, I have to increase the OGR_GEOJSON_MAX_OBJ_SIZE "configuration option" from the default 200MB to at least 251MB.

Is there a way to set this option through an R package (such as sf)? st_read has an argument that lets you specify so-called "Open options" and it would be nice to be able to do this for "configuration options". I don't really understand what's going on under the hood when reading .geojsonfiles with st_readbut my understanding is that it uses GDAL which in turn uses the GEOJSON driver to read the file. So a possibility is to change the option directly in GDAL as documented here. This, however, leads me to another question: where can I find the GDAL installation and how to interact with it? I am assuming it was installed when I installed the sfpackage.

In short I need a way to set the option to read larger .geojson files in my script so that it is reproducible.

Any help is appreciated!

Hi @mafw, I believe this variable is set through the environment variable rather than the options. You can set it using sys.setenv(OGR_GEOJSON_MAX_OBJ_SIZE=500).

There are also dedicated geojson R readers that you could try, such as geojson and geojsonR.

2 Likes

Thanks for the tip @etiennebr! It worked by setting it to 1000MB, but not 500MB. This is a little strange as the file is 220MB. I see from the GDAL documentation that the object size is in reference to a single feature, so maybe there's a feature in the data that "unpacks" to larger than 500MB?

Thanks again!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.