I currently use GRASS' r.mapcalc to find the difference between vector and raster data using a loop and temporary files and layers.
Is it possible to do the core calculation between raster with a vector data more directly either within GRASS, in some external tool, or some python script?
#!/bin/bash
TOPO=mytopo
g.region -p rast=mytopo res=10
for file in INPUTS/* ; do
imbase=${file#INPUTS/} # strip off the directory prefix
v.in.ogr input=$file output=temp_a --overwrite
v.to.rast in=temp_a out=temp_b use=attr column=elev --overwrite
r.mapcalc "temp_c" = "(if( "temp_b" <= "$TOPO" ,null(),if( "$TOPO" <0,0, "temp_b" - "$TOPO" )))"
r.out.gdal input=temp_c -c format=GTiff type=Float32 output=OUTPUTS/$imbase
end
g.remove temp_a
g.remove temp_b
g.remove temp_c
I like GRASS' the ability to do the mapcalc on resolutions and extents other than my source data. but although this works, the process seems seems awkward and slow for numbers of files in the hundreds. Ideally, I'd like something like the below:
gdalogr_diff.py mytopo.tif PG:dbname=warmerda -sql "SELECT elev[${timeslice}] from temp_output" -f GTiff out_${timeslice}.tif