|
Hi all, I'm using the SIGRID 1000 m grid as the sampling frame for a national Collect Earth assessment. I've downloaded the tile ZIPs and can read the CSVs, each plot has its CE_ID, lat/long and the grid_1 … grid_100 columns. What I'm missing is which province and district each plot falls in (ADM1/ADM2), so I can stratify and report by admin unit. Clipping tile by tile in QGIS is painful since each 10×10° tile is mostly points outside my country. Has anyone automated this and can it also split the tagged plots by grid intensity (separate files for 1×1 km, 2×2 km, etc.)? Thanks! |
Extracting SIGRID 1 km plots for a whole country, tagged with province (ADM1) and district (ADM2) namesI put together a small Python script that automates a common request: take the SIGRID 1000 m grid and pull out every plot that falls inside a given country, with the province and district name attached to each plot. Optionally it also splits the result into one file per SIGRID density (1x1 km, 2x2 km, ... up to 100x100 km). The script is hosted next to the grids so you can grab it directly: https://www.openforis.org/fileadmin/SIGRID_1000m_grids/sigrid_country.py You only need to give it a 2-letter ISO country code, for example bj for Benin or ye for Yemen. Everything else - downloading the right grid tiles, downloading the country boundaries, and doing the spatial join - is automatic. What you getFor a country you get a single CSV, <iso2>_plots_with_districts.csv, with the original SIGRID columns plus two new ones, ADM1NM (province/department) and ADM2NM (district), and containing only the plots that fall inside the country: CE_ID, yCoordinate, xCoordinate, ADM1NM, ADM2NM, grid_1, grid_2, grid_3, ..., grid_100 With the --split-by-density option you additionally get one CSV per density grid, named by country and resolution - Benin_1x1km.csv, Benin_2x2km.csv, Benin_3x3km.csv, ... each holding only the plots flagged for that grid. Prerequisites
geopandas pulls in shapely, pyproj and fiona, which handle the geometry and the point-in-polygon test. UsageDownload sigrid_country.py, then run: Benin - combined country file only
Benin - also split into one file per density grid
Choose an output directory
The first run downloads the grid tiles it needs and caches them under ./sigrid_cache/, so re-runs, or a second country in the same tiles, are fast and do not re-download. How it worksThe script chains together the two data sources that already exist on the Open Foris / EarthMap side:
These features carry the ADM1NM and ADM2NM attributes, which is where the province and district names come from.
About the density gridsEach SIGRID plot carries boolean flags grid_1 ... grid_100. grid_N = true means the plot is a sampling point of the N x N km grid. grid_1 is true for every plot, the full 1 km grid; coarser grids are progressively sparser. The densities actually present are: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, 16, 20, 25, 30, 50, 100 km As a sanity check, the number of plots roughly scales with 1/N^2. For example, the 2x2 km grid has about a quarter of the 1x1 km plots, the 10x10 km grid about 1/100, and so on. Worked examplesBenin (bj): 115,259 plots across all 12 departments and 77 districts. Two tiles downloaded, around 30 s of processing. Yemen (ye): 453,565 plots across 22 governorates. With --split-by-density this produced 17 files, from Yemen_1x1km.csv, with 453,565 plots, down to Yemen_100x100km.csv, with 46 plots. Notes & troubleshooting
|