[GRASS-user] r.to.vect to selected locations only

Hi,

Here's the process I plan to do for my image classification

1. Create an unsupervised classification from TCAP images to get
clusters of pure pixel values.
2. Convert to vector.
3. Create a random location of vector points.
4. From the converted vector layer, select random polygons
(approximately 60 polys for each class).
5. Label training polygons for the desired classification classes
6. Run smap classification

I will be running this method for a series of LANDSAT images (one tile
at a time).

My problem is by converting the whole image from raster to vector
areas, the v.to.rast module reports "Killed" and could not complete
the conversion.
This maybe due to the whole image being large.

Type of Map: raster Number of Categories: 47 |
| Data Type: CELL |
| Rows: 7518 |
| Columns: 8504 |
| Total Cells: 63933072 |
| Projection: UTM (zone 51) |
| N: 746814 S: 532551 Res: 28.5 |
| E: 857451 W: 615087 Res: 28.5 |
| Range of data: min = 1 max = 47

I've tried r.neighbors to reduce number of areas with less than 1-10
pixels, but this process outputs vectors layers with mixed pixel
values, thus making it difficult to use in MLC or SMAP as training
areas.

What I need is to, limit raster to vector conversion to the desired
randomly selected locations only. So that r.to.vect could complete the
conversion.

Any ideas?

maning

--
|---------|----------------------------------------------------------|
| __.-._ |"Ohhh. Great warrior. Wars not make one great." -Yoda |
| '-._"7' |"Freedom is still the most radical idea of all" -N.Branden|
| /'.-c |Linux registered user #402901, http://counter.li.org/ |
| | /T |http://esambale.wikispaces.com|
| _)_/LI
|---------|----------------------------------------------------------|

On Mon, Jun 23, 2008 at 5:46 AM, maning sambale
<emmanuel.sambale@gmail.com> wrote:
...

What I need is to, limit raster to vector conversion to the desired
randomly selected locations only. So that r.to.vect could complete the
conversion.

Did you try to set a raster mask (r.mask)? It should be respected
by r.to.vect.

Markus

Maning wrote:

Here's the process I plan to do for my image classification

1. Create an unsupervised classification from TCAP images to get
clusters of pure pixel values.
2. Convert to vector.
3. Create a random location of vector points.
4. From the converted vector layer, select random polygons
(approximately 60 polys for each class).
5. Label training polygons for the desired classification classes
6. Run smap classification

I will be running this method for a series of LANDSAT
images (one tile at a time).

My problem is by converting the whole image from raster to vector
areas, the v.to.rast module reports "Killed" and could not complete
the conversion.
This maybe due to the whole image being large.

Yes, that's an out of memory error. The operating system kills the offending processes so that the rest of the computer can keep running.

| Data Type: CELL
| Rows: 7518
| Columns: 8504

probably for sanity's sake you may want to stay under about 4000x4000.
It is not a hard limit, the only thing that should limit you for bigger sizes is computer resources and your time.

What I need is to, limit raster to vector conversion to the
desired randomly selected locations only. So that r.to.vect could
complete the conversion.

Any ideas?

I've needed a similar thing a number of times, and so I've just added a new add-on script which may be helpful.

"g.region.point - g.region.point is a shell script which resets the computational region to a square box around a given coordinate. It is intended for use within GRASS scripts to speed up processing by focusing expensive raster calculations onto a small area of interest."

  http://grass.osgeo.org/wiki/GRASS_AddOns#General_add-ons
  http://trac.osgeo.org/grass/browser/grass-addons/general/g.region.point

also perhaps helpful is the v.random.cover add-on script.

Hamish

ps- If anyone who knows about the clustering modules would like to update the wiki page describing what's available, please go for it. I've no idea.
  http://grass.osgeo.org/wiki/Image_processing#Clustering

On Mon, 2008-06-23 at 10:25 +0200, Markus Neteler wrote:

On Mon, Jun 23, 2008 at 5:46 AM, maning sambale
<emmanuel.sambale@gmail.com> wrote:
...
> What I need is to, limit raster to vector conversion to the desired
> randomly selected locations only. So that r.to.vect could complete the
> conversion.

Did you try to set a raster mask (r.mask)? It should be respected
by r.to.vect.

Markus

Dear all,

I recently had to think about a similar problem. But the question
remain... how can raster areas be selected based on vector points that
fall inside them?

So one can build an optimal MASK.

Thank you,

Nikos

how can raster areas be selected based on vector points that >fall inside them?

What do you mean with this? Isn't Hamish's script useful to achieve it?

On Mon, 2008-06-23 at 12:10 +0200, G. Allegri wrote:

>how can raster areas be selected based on vector points that >fall inside them?

What do you mean with this? Isn't Hamish's script useful to achieve it?

Yes, it is very useful. But what I mean is something like...

point map >v.to.rast

create MASK only for areas in which a point falls inside.

I hope it's clear enough what I suggest.

Thank you,

Nikos

Assuming there is a raster map with areas (e.g. the result of a classification).

Ok, now it's clear. That's a good point... maybe one could write an
algorithm similar to r.grow or r.lake: add pixels starting from a
point until a pixel with the same category of the seed is found.
A good exercise :slight_smile:

Nikos:

> Assuming there is a raster map with areas (e.g. the
> result of a classification).

has the previous suggested (weeks/months?) method worked?

(r.what or v.what.rast) -> r.reclass -> MASK -> 'g.region zoom='

'g.region zoom=' may be a bit slow; I don't know if that can be improved.
ISTR that it starts at the current region, not the map bounds, which might help speed things up if you want to zoom in on just one patch. (??)

G. Allegri:

Ok, now it's clear. That's a good point... maybe one could write an
algorithm similar to r.grow or r.lake: add pixels starting from a
point until a pixel with the same category of the seed is found.

(r.what or v.what.rast) -> r.reclass -> r.grow -> 'g.region rast=' ?

or instead of r.reclass use r.mapcalc to create the isolated region before 'g.region zoom=' or r.grow.

Hamish

(r.what or v.what.rast) -> r.reclass -> MASK -> 'g.region zoom='

(r.what or v.what.rast) -> r.reclass -> r.grow -> 'g.region rast='

r.reclass would reclass all the areas having the same value as the one
from r.what, so it's not guaranteed that just the area around the
specified point is considered. Am I wrong?

Are you sure r.grow is useful? As far as I've unserstood it makes a
sort of r.buffer+r.patch, based on a buffer radii, not inspecting the
pixel values...

Yes r.mapcalc can do the work, but I was tinking to something like
r.lake... Maybe it's more performant. Ok, proabibly it should be
written with a C routine not bash.

Hamish:

> (r.what or v.what.rast) -> r.reclass -> MASK -> 'g.region zoom='

....

> (r.what or v.what.rast) -> r.reclass -> r.grow -> 'g.region rast='

G. Allegri wrote:

r.reclass would reclass all the areas having the same value
as the one from r.what, so it's not guaranteed that just the area
around the specified point is considered. Am I wrong?

that is correct; all of that value in the map.

Are you sure r.grow is useful? As far as I've unserstood it makes
a sort of r.buffer+r.patch, based on a buffer radii, not
inspecting the pixel values...

oops, I meant r.cost.

Yes r.mapcalc can do the work, but I was tinking to something like
r.lake... Maybe it's more performant. Ok, proabibly it should be
written with a C routine not bash.

well bash is nice for prototypes and proof of concept. You can worry about C later if you can't stand the slowness. Usually you can stand it.
I've never used r.lake much, so can't comment on if it could offer a solution.

random idea:
Maybe we could add a "module of the day" feed on the grass webpage with module name and label/description one-liner. I continue to find new modules many years after first using grass.

Hamish

Hamish:

random idea:
Maybe we could add a "module of the day" feed on the grass webpage with module name and label/description one-liner. I continue to find new modules many years after first using grass.

The same with me; not only am I discovering new modules, but also discovering flags present in old modules I've used for years that I wish I had known about years ago!

~ Eric.

About knowing new modules: I didn’t know about r.clump

a way to accomplish the subject task: r.to.vect for areas where certain locations fall.
It can be done with the following flow:

r.clump → loop over r.what (at locations places) and then r.reclass or r.mapcalc to MASK areas other then the ones around singol locations → r.to.vect

Giovanni