[GRASS-user] Clipping rasters

Hi,

I thought I created a clipped DEM by rasterising an irregular vector
boundary and then using a mask to create the clipped DEM from a
rectangular DEM.

For example:
-----
# convert vector border to raster
v.to.rast input="border" output="border" use="cat" type="area" layer=1
value=1 rows=4096 |

# set the mask to the raster border
r.mask border

# create the clipped DEM
r.mapcalc

dem_clipped=dem_full

# remove the mask
r.mask -r
-----

But it turns out I was wrong, the 'clipped' raster just contains NULL
values outside of the border raster. What did I do wrong? Is there a
better way to clip a raster to a vector boundary?

Thanks
Hanlie

Hanlie Pretorius wrote:

I thought I created a clipped DEM by rasterising an irregular vector
boundary and then using a mask to create the clipped DEM from a
rectangular DEM.

For example:
-----

#first, check and set your region of interest
g.region vect=border -pa

# convert vector border to raster
v.to.rast input="border" output="border" use="cat" type="area" layer=1
value=1 rows=4096 |

# set the mask to the raster border
r.mask border

# create the clipped DEM
r.mapcalc

>dem_clipped=dem_full

# remove the mask
r.mask -r
-----

But it turns out I was wrong, the 'clipped' raster just contains NULL
values outside of the border raster. What did I do wrong? Is there a
better way to clip a raster to a vector boundary?

So, always check the region ;-). I think this is the best (and only?) way to
clip.

Regards, Nikos

Hanlie Pretorius pisze:

Hi,

I thought I created a clipped DEM by rasterising an irregular vector
boundary and then using a mask to create the clipped DEM from a
rectangular DEM.

For example:
-----
# convert vector border to raster
v.to.rast input="border" output="border" use="cat" type="area" layer=1
value=1 rows=4096 |

# set the mask to the raster border
r.mask border

# create the clipped DEM
r.mapcalc
  

dem_clipped=dem_full
    
# remove the mask
r.mask -r
-----

But it turns out I was wrong, the 'clipped' raster just contains NULL
values outside of the border raster. What did I do wrong? Is there a
better way to clip a raster to a vector boundary?

Thanks
Hanlie
_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user
  

nothing, everything is OK, if you want change raster size (i.e remove areas outside vector) just do

g.region vect=border

v.to.rast input="border" output="border" use="cat" type="area" layer=1
value=1 rows=4096 etc..
but you will still will have null values outside the the vector, if it has irregular shape
J.

2010/8/10, Nikos Alexandris <nikos.alexandris@felis.uni-freiburg.de>:

Hanlie Pretorius wrote:

I thought I created a clipped DEM by rasterising an irregular vector
boundary and then using a mask to create the clipped DEM from a
rectangular DEM.

For example:
-----

#first, check and set your region of interest
g.region vect=border -pa

Tried this with the same result, as Jarek points out in the second
reply. So, I assume it's impossible to have a raster with an irregular
boundary in GRASS?

# convert vector border to raster
v.to.rast input="border" output="border" use="cat" type="area" layer=1
value=1 rows=4096 |

# set the mask to the raster border
r.mask border

# create the clipped DEM
r.mapcalc

>dem_clipped=dem_full

# remove the mask
r.mask -r
-----

But it turns out I was wrong, the 'clipped' raster just contains NULL
values outside of the border raster. What did I do wrong? Is there a
better way to clip a raster to a vector boundary?

So, always check the region ;-). I think this is the best (and only?) way to
clip.

Regards, Nikos

Hanlie Pretorius pisze:

2010/8/10, Nikos Alexandris <nikos.alexandris@felis.uni-freiburg.de>:
  

Hanlie Pretorius wrote:

I thought I created a clipped DEM by rasterising an irregular vector
boundary and then using a mask to create the clipped DEM from a
rectangular DEM.

For example:
-----
      

#first, check and set your region of interest
g.region vect=border -pa
    
Tried this with the same result, as Jarek points out in the second
reply. So, I assume it's impossible to have a raster with an irregular
boundary in GRASS?

# convert vector border to raster
v.to.rast input="border" output="border" use="cat" type="area" layer=1
value=1 rows=4096 |

# set the mask to the raster border
r.mask border
      # create the clipped DEM
r.mapcalc

dem_clipped=dem_full
        

# remove the mask
r.mask -r
-----

But it turns out I was wrong, the 'clipped' raster just contains NULL
values outside of the border raster. What did I do wrong? Is there a
better way to clip a raster to a vector boundary?
      

So, always check the region ;-). I think this is the best (and only?) way to
clip.

Regards, Nikos

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user
  

raster is a matrix of values so it is always rectangular. Null is not a value, NULL is lack of value. Irregular raster is a rectangural raster with null (transparent) cells outside the border
J.

Hanlie Pretorius wrote:
...

Nikos A:

> #first, check and set your region of interest
> g.region vect=border -pa

Tried this with the same result, as Jarek points out in the second
reply. So, I assume it's impossible to have a raster with an irregular
boundary in GRASS?

(
I don't think so. GRASS raster engine is eXtremely powerfull. You can even
sketch circles if you'd like using r.mapcalc
)

>> # convert vector border to raster
>> v.to.rast input="border" output="border" use="cat" type="area" layer=1
>> value=1 rows=4096 |
>>
>> # set the mask to the raster border
>> r.mask border

#replace the above and use r.mapcalc instead:
r.mapcalc MASK=border

>> # create the clipped DEM
>> r.mapcalc

>> >dem_clipped=dem_full
>>
>> # remove the mask
>> r.mask -r
>> -----

Nikos

2010/8/10 Nikos Alexandris <nikos.alexandris@felis.uni-freiburg.de>:

>> # set the mask to the raster border
>> r.mask border

#replace the above and use r.mapcalc instead:
r.mapcalc MASK=border

why?

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa

Hanlie P:
...

Tried this with the same result, as Jarek points out in the second
reply.

Sort of off-topic (but important to me): for some reason Jarek's e-mails got
filtered and dropped in another folder that is why I replied (again) about
g.region.

Nikos

On Tuesday 10 of August 2010 18:02:12 Martin Landa wrote:

2010/8/10 Nikos Alexandris <nikos.alexandris@felis.uni-freiburg.de>:
>> >> # set the mask to the raster border
>> >> r.mask border
>
> #replace the above and use r.mapcalc instead:
> r.mapcalc MASK=border

why?

Right. I should first ask what the values compose the raster that is to become
a MASK. In the past I had problems with r.mask (if it is important I will
trace down the thread) I think when using it on floating point maps (values
like 0.2, 0.3, 0.4, etc.) and they got rounded (or truncated?) to 0 or
something similar.

But, in this case the "value=1" is assigned so it should make no difference. I
was too quick. Sorry.

Nikos