[GRASS-user] automated cropping of reprojected images

Glynn Clements glynn at gclements.plus.com
Thu Jul 13 21:04:25 EDT 2006


Trevor Wiens wrote:

> > > I'm wondering if there is an easy way to crop reprojected images. In
> > > this case it is for landsat images that will eventually be layed
> > > together to cover most of Canada. Thus the extra space that is created
> > > in rotating the images becomes an issue.
> > > 
> > > I tried importing, using r.null and then reprojecting, but when I
> > > exported the file, it didn't make any difference. I also tried
> > > creating a MASK to remove all NULL values, but this too was to no avail
> > > upon export.
> > > 
> > > Any suggestions on how to tackle this would be appreciated.
> > 
> > I'm not entirely sure what you're asking here.
> > 
> > When you export raster map, the resulting file has the same number of
> > rows and columns as the current region at the time that you export. If
> > you shrink the region, you'll get a smaller image.
> > 
> > Or are you referring to something else?
> 
> Sorry for not being clear.
> 
> As Paulo mentioned I am talking about the big black regions around the
> landsat images. I can visually adjust the region, but with the volume
> of images I'm dealing with here, that isn't practical so I'm looking
> for a programmatic method. For example I tried to make a MASK and then
> set g.region rast=MASK, but the MASK includes all the nulls or zeros so
> the region size doesn't change. I also tried creating a copy of the
> file with r.mapcalc using the MASK hoping the end file would have a
> smaller region and then did g.region rast=<mask r.mapcalc output>, but
> the region size again didn't change. I want to set the region to an
> area that only has actual data, not nulls.

Any import module (r.in.*) will produce a map which has the same
number of rows and columns as the image being imported.

Any other module will produce a map which has the same number of rows
and columns as the current region.

Any export module will produce an image which has the same number of
rows and columns as the current region.

Thus, if you want to shrink (crop) an image, you need to modify the
current region.

There isn't a module which does this automatically (it might make a
useful addition to g.region). Approaches which should work incude:

1. Use r.reclass/r.mapcalc to create a binary (0/1 or null/non-null)
map which distingushes "data" cells from "border" cells, use r.to.vect
to convert it to a vector area, then "g.region vect=..." to shrink the
region to fit the vector.

2. Use r.mapcalc to create two FP maps, where every "border" cell is
null and every "data" cell contains the x/y coordinate of the cell's
centre, obtain the min/max values from each map using r.info, then
enlarge the range by half a cell.

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-user mailing list