[GRASS-user] automated cropping of reprojected images

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.

T
--
Trevor Wiens
twiens@interbaun.com

The significant problems that we face cannot be solved at the same
level of thinking we were at when we created them.
(Albert Einstein)

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?

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

2006/7/13, Glynn Clements <glynn@gclements.plus.com>:

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.

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?

Glinn,

Trevor refers to the black areas in the corners of Landsat scenes. He
want to get rid of those to patch several images together.

IIRC, Dylan has patched several images of California and Arizona.
Haven't seen the results, though. Maybe he could share his experience
=]

--
Paulo Marcondes = PU1/PU2PIX
-22.915 -42.229 = GG87vc (http://www.amsat.org/cgi-bin/gridconv)
Debian GNU/Linux = http://rj.debianbrasil.org = http://www.debian.org

On Thu, 13 Jul 2006 10:51:27 +0100
Glynn Clements <glynn@gclements.plus.com> wrote:

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.

Ideally, it would be nice to be able to determine this using gdal so I
can crop the images with gdalwarp without having to import and export
as the client wants to use these images to check the results of change
analysis after being run between pairs of the original images in the
UTM projection they were acquired in.

T
--
Trevor Wiens
twiens@interbaun.com

The significant problems that we face cannot be solved at the same
level of thinking we were at when we created them.
(Albert Einstein)

On 7/13/06, Trevor Wiens <twiens@interbaun.com> wrote:

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.

Ideally, it would be nice to be able to determine this using gdal so I
can crop the images with gdalwarp without having to import and export
as the client wants to use these images to check the results of change
analysis after being run between pairs of the original images in the
UTM projection they were acquired in.

I have done this a couple times, unfortunately I can not find my
scripts. If my memory serves me, I've done it both in GRASS and with
gdal_translate. My approach was less than elegant, but I simply
subtracted a predefined amount from image extents. With gdal_translate
this would be done with -srcwin, or in GRASS simply by setting a new
region (r.region).

I had enough overlap between images that I did not need to be very
precise. So I reprojected a couple representative images and measured
how wide the no-data bands were after reprojection. I then used this
amount is a fixed cropping value in my scripts.

If you do not have enough overlap between images you could r.patch
them into a single, large image and then "write out" tiles from that
large patched image.

HTH,
Rich

--
Richard Greenwood
richard.greenwood@gmail.com
www.greenwoodmap.com

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@gclements.plus.com>

Glynn Clements napisa?(a):

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.

Glynn,

Not in case of r.out.gdal. It preserves the raster's resolution and
extent (which I like). Ideally, each export module should have a switch
to allow for raster-wise and region-wise export IMHO.

Maciek