Saturday 25 January 2020

python - how to overlay shapefile and raster?


I have a shapefile with polygons. And I have a global raster file. I want to overlay the shapefile's polygons onto the raster grid and calculate the mean raster value for each polygon.


How can I do this using GDAL, writing the results to the shapefile?



Answer



Following advice I got on the gdal-dev mailing list, I used StarSpan:


starspan --vector V --raster R1 R2 ... --stats mystats.csv avg mode


The results are saved to CSV format. At that time, that was already enough for me, but it should be possible to somehow forge a Shapefile from that info.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...