geosnap.io.get_gadm

geosnap.io.get_gadm(code, level=0, use_fsspec=True, gpkg=True, n_retries=3)[source]

Collect data from GADM as a geodataframe.

Parameters:
codestr

three character ISO code for a country

levelint, optional

which geometry level to collect, by default 0

use_fsspecbool

whether to use the fsspec library

gpkgbool

whether to read from a geopackage or shapefile. If True, geopackage will be read; shapefile if False. Ignored if using fsspec

n_retriesint optional

number of retries in case read fails from direct stream from GADM. Ignored if using fsspec.

Returns:
geopandas.GeoDataFrame

geodataframe containing GADM data

Notes

If not using the fsspec package, this function uses fiona’s syntax to read a geodataframe directly with geopandas read_file function. Unfortunately, sometimes the operation fails before the read is complete resulting in an error–or occasionally, a geodataframe with missing rows. Repeating the call sometimes helps.

When using fsspec, the function doesn’t suffer these issues, but requires an additional dependency. If fsspec is available, this function its syntax to store a temporary file which is then read in by geopandas. In theory, the file could be read into fsspec directly without storing it in a temporary directory, but when reading a bytestream of GPKG, geopandas does not allow the specification of a particular layer (so reading GPKG with this method would always returns the layer with index 0 in the geopackage file).