Script performs point-in-polygon (PIP) for multiple points and multiple polygons (raster tile index) and updates the points shapefile with the pixel value from the correct raster.
- GDAL, must also be in the
PATH
- libspatialindex
$ git clone git@github.com:dmofot/pnts_n_polys.git
$ cd pnts_n_polys
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
- points_shapefile (in EPSG 4326) -
input_pnts.shp
- input_rasters OR raster_tile_index -
./tiles/*.tif
ORtile_index_4326.shp
- points_updated_shapefile -
input_pnts_updated.shp
- raster_tile_index -
tile_index_4326.shp
$ python pnts_n_polys.py ./test/test_index_pnts_4326.shp ./test/tiles/*.tif
Loading rasters into tile_index_4326.shp...
Creating new index file...
Loading points from ./test/test_index_pnts_4326.shp...
Building spatial index...
Checking if points are in polygons...
Progress: 100%|█████████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:01<00:00, 93.51pnts/s]
Saving updates to ./test/test_index_pnts_4326_updated.shp...
$ python pnts_n_polys.py ./test/test_index_pnts_4326.shp ./test/tile_index_4326.shp
Loading raster tile index ./test/tile_index_4326.shp...
Loading points from ./test/test_index_pnts_4326.shp...
Building spatial index...
Checking if points are in polygons...
Progress: 100%|█████████████████████████████████████████████████████████████████████████████████████████| 100/100 [00:01<00:00, 96.31pnts/s]
Saving updates to ./test/test_index_pnts_4326_updated.shp...