[GRASSLIST:6753] Re: batch; clip raster map
Hamish
hamish_nospam at yahoo.com
Wed May 11 07:36:02 EDT 2005
> I hope you can help me with this next two questions too.
>
> #1
> As the scans are quite big i.rectify and r.out.tif take a long time to
>
> perform their tasks.
> So i like to know if there is a way to run this in a batch job so i
> can do all the preprocessing for he several scans and let a batch job
> run over night to rectify and export everything.
> I have never used batch before so if it is possible i need advice how
> to write this batch file.
Yes, first figure out the commands to use, e.g.:
i.rectify -a group=landsat_area1 extension=_1 order=2
i.rectify -a group=landsat_area2 extension=_2 order=2
i.rectify -a group=landsat_area3 extension=_3 order=2
then just make a simple UNIX script by putting those three lines in a
text file and from the command line do:
GRASS 6> . commands.txt
later you can make fancy loops if you have lots of runs to do, for just
a few the cut and paste method works fine.
There are hundreds of books and guides to UNIX shell/bash scripting.
Running r.out.tiff (but perhaps r.out.gdal is better at making
GeoTIFFs?) on the output files requires you to be in a different
location which means you can't run it in the same session as i.rectify.
It is possible to have the script launch GRASS in one location, run the
i.rectify commands, exit, start in the other location and run
r.out.tiff, but I think that is way more complicated than you want to
get into. There is also g.mapset which will let you change
mapset/location mid-session, but it is only lightly tested and I'd use a
lot of caution switching anything other than mapsets with it.
But as exporting a GeoTIFF is very quick compared to i.rectify, don't
worry about it and run that step it in the morning.
note 1: i.rectify in GRASS 6.1-cvs has been changed into a normal module;
i.e. no "we'll email you when it's done" stuff anymore, just 0-100%
complete then exit. This should be a better solution when batch
processing.
note 2: 'i.rectify order=3' seems to be broken. Use order=2 or help fix
the bug. GDAL has the bug as well(?).
see http://intevation.de/rt/webrt?serial_num=3166
> #2
> The scanned maps contain information for a municipality whose border
> is available as shape file. Is there a way to ___clip___ the raster
> map with this shape file so that the outline of the raster map equals
> the border?
Yes,
v.extract where="province='name'"
g.region rast=full_map
v.to.rast use=val output=municipality
g.copy municipality,MASK
r.mapcalc cropped_map=full_map
g.remove MASK
Read the v.to.rast help page: only features with a category number will
be transformed. So v.extract an area not a boundary or use v.category to
add cat numbers to what you want to transform. If both areas and
boundaries have cats, you get different output!
Usually the default actions work correctly and you don't have to worry,
but sometimes you get an odd datafile.
see also v.in.region and v.overlay for cropping a vector map.
Hamish
More information about the grass-user
mailing list