[GRASS-user] r.to.vect and then v.clean using tool=rmarea creates polygons instead of holes.

Hello Grass-Users,

I’m having problems with this sequence of commands:
r.to.vect -s input=lszone output=lszone10 feature=area
v.clean input=lszone10 output=lszone10_clean tool=rmarea thresh=2800

Below is the output.

Overlaying lszone and lszone10_clean, I see that there are large holes that have been replaced with polygons. Is this a bug?

Btw, I’ve tried this with QGIS on Windows XP as well as GRASS 6.4.svn with the same results.

Bob

======================================================================
r.to.vect -s in=lszone out=lszone10 feature=area
Extracting areas…
100%
100%
Building topology for vector map …
Registering primitives…
50074 primitives registered
629002 vertices registered
Building areas…
100%
27613 areas built
17107 isles built
Attaching islands…
100%
Attaching centroids…
100%
Number of nodes: 39568
Number of primitives: 50074
Number of points: 0
Number of lines: 0
Number of boundaries: 33886
Number of centroids: 16188
Number of areas: 27613
Number of isles: 17107
Number of areas without centroid: 11425
r.to.vect complete.
v.clean in=lszone10 out=lszone10_clean tool=rmarea thresh=2800

Tool: Threshold
Remove small areas: 2.800000e+03

Copying vector lines…
Rebuilding parts of topology…
Building topology for vector map <lszone10_clean>…
Registering primitives…
50074 primitives registered
629002 vertices registered
Building areas…
100%
27613 areas built
17107 isles built
Attaching islands…
100%
Attaching centroids…
100%
Number of nodes: 39568
Number of primitives: 50074
Number of points: 0
Number of lines: 0
Number of boundaries: 33886
Number of centroids: 16188
Number of areas: 27613
Number of isles: 17107
Number of areas without centroid: 11425

Tool: Remove small areas
26251 areas of total size 9.34119e+06 removed

Rebuilding topology for output vector map…
Building topology for vector map <lszone10_clean>…
Registering primitives…
4913 primitives registered
222687 vertices registered
Building areas…
100%
1362 areas built
1127 isles built
Attaching islands…
100%
Attaching centroids…
100%
Number of nodes: 4678
Number of primitives: 4913
Number of points: 0
Number of lines: 0
Number of boundaries: 4185
Number of centroids: 728
Number of areas: 1362
Number of isles: 1127
Number of duplicate centroids: 3
Number of areas without centroid: 637

Bob Moskovitz
Research Analyst I
Seismic Hazard Zonation Project
California Geological Survey
http://www.conservation.ca.gov/cgs/shzp

CONFIDENTIALITY NOTICE: This communication is intended only for the use of the individual or entity to which it is addressed. This message contains information from the State of California, California Geological Survey, which may be privileged, confidential and exempt from disclosure under applicable law, including the Electronic Communications Privacy Act. If the reader of this communication is not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication is strictly prohibited.

Moskovitz, Bob wrote:

Hello Grass-Users,

I'm having problems with this sequence of commands:
    r.to.vect -s input=lszone output=lszone10 feature=area
    v.clean input=lszone10 output=lszone10_clean tool=rmarea thresh=2800

Below is the output.

Overlaying lszone and lszone10_clean, I see that there are large holes
that have been replaced with polygons. Is this a bug?

Btw, I've tried this with QGIS on Windows XP as well as GRASS 6.4.svn
with the same results.

Bob

Hmm, I'm wondering if there's a flaw in the topology built by r.to.vect

What happens if you run v.build before v.clean?

At second glance I see how if a small polygon gets removed and it shared
a border with the big polygon, that that border might not exist now.
maybe add the bpol to tool=rmarea,bpol

Alex

I followed your suggestion, but I'm still getting the same problem. It seems strange that v.to.rast would create a vector file that has flawed topology. Do you know of any alternative to v.clean with rmarea?

Btw, I also tried to use v.generalize with a very small threshold and then v.clean. This method works for me.

-----Original Message-----
From: Alex Mandel [mailto:tech_dev@wildintellect.com]
Sent: Thursday, December 11, 2008 3:14 PM
To: Moskovitz, Bob
Cc: Grass-User (E-mail)
Subject: Re: [GRASS-user] r.to.vect and then v.clean using tool=rmarea
createspolygons instead of holes.

Moskovitz, Bob wrote:
> Hello Grass-Users,
>
> I'm having problems with this sequence of commands:
> r.to.vect -s input=lszone output=lszone10 feature=area
> v.clean input=lszone10 output=lszone10_clean
tool=rmarea thresh=2800
>
> Below is the output.
>
> Overlaying lszone and lszone10_clean, I see that there are
large holes
> that have been replaced with polygons. Is this a bug?
>
> Btw, I've tried this with QGIS on Windows XP as well as
GRASS 6.4.svn
> with the same results.
>
> Bob
>

Hmm, I'm wondering if there's a flaw in the topology built by
r.to.vect

What happens if you run v.build before v.clean?

At second glance I see how if a small polygon gets removed
and it shared
a border with the big polygon, that that border might not exist now.
maybe add the bpol to tool=rmarea,bpol

Alex

Bob Moskovitz wrote:

I followed your suggestion, but I'm still getting the
same problem. It seems strange that v.to.rast would create
a vector file that has flawed topology. Do you know of any
alternative to v.clean with rmarea?

v.db.addcol area
v.to.db option=area
v.extract where="area > 2800"
?

Btw, I also tried to use v.generalize with a very small
threshold and then v.clean. This method works for me.

Hamish

Hamish wrote:

Bob Moskovitz wrote:
  

I followed your suggestion, but I'm still getting the
same problem. It seems strange that v.to.rast would create
a vector file that has flawed topology. Do you know of any
alternative to v.clean with rmarea?
    
v.db.addcol area
v.to.db option=area
v.extract where="area > 2800"
?
  

That only deletes the centroids of these small areas, the boundaries remain.

From your original post:
vector <lszone10> has
27613 areas
17107 isles
Number of areas without centroid: 11425

vector <lszone10_clean> has
Number of areas: 1362
Number of isles: 1127
Number of duplicate centroids: 3
Number of areas without centroid: 637

Further on, 26251 areas have been removed.
v.clean tool=rmarea also removes areas without centroids, that's why
holes have been replaced by polygons, boundaries of small areas are
deleted. If you want to merge small areas with adjacent large areas,
v.clean would do the job, but for all areas, also areas without centroid.
If you want to keep only larger areas and these unchanged, the method of
Hamish with v.extract would do that.
Or you could do
v.db.addcol map=lszone10 columns="area DOUBLE"
v.to.db map=lszone10 option=area columns=area
and then use where="area > 2800" in further operations.

Markus

Thank you Hamish...your set of commands worked great!

It still bothers me that r.to.vect would produce invalid topology. Btw, I also tried to use v.generalize but my vectyor seem to lose its attribute table.

-----Original Message-----
From: Hamish [mailto:hamish_b@yahoo.com]
Sent: Friday, December 12, 2008 1:17 AM
To: Alex Mandel; Moskovitz, Bob
Cc: Grass-User (E-mail)
Subject: RE: [GRASS-user] r.to.vect and then v.clean using tool=rmarea
createspolygons instead of holes.

Bob Moskovitz wrote:
> I followed your suggestion, but I'm still getting the
> same problem. It seems strange that v.to.rast would create
> a vector file that has flawed topology. Do you know of any
> alternative to v.clean with rmarea?

v.db.addcol area
v.to.db option=area
v.extract where="area > 2800"
?

> Btw, I also tried to use v.generalize with a very small
> threshold and then v.clean. This method works for me.

Hamish

Upon closer inspection, I see what you are talking about. I do want to remove holes <= 2800 m, so this method won't work for me. So, what would cause r.to.vect to create areas without centroids? And why haven't v.clean rmarea filled all of my holes since they all don't have centroids?

-----Original Message-----
From: Markus Metz [mailto:markus.metz.giswork@googlemail.com]
Sent: Friday, December 12, 2008 5:31 AM
To: grass-user@lists.osgeo.org; Moskovitz, Bob
Subject: Re: [GRASS-user] r.to.vect and then v.clean using tool=rmarea
createspolygonsinstead of holes.

Hamish wrote:
> Bob Moskovitz wrote:
>
>> I followed your suggestion, but I'm still getting the
>> same problem. It seems strange that v.to.rast would create
>> a vector file that has flawed topology. Do you know of any
>> alternative to v.clean with rmarea?
>>
>
> v.db.addcol area
> v.to.db option=area
> v.extract where="area > 2800"
> ?
>
That only deletes the centroids of these small areas, the
boundaries remain.

From your original post:
vector <lszone10> has
27613 areas
17107 isles
Number of areas without centroid: 11425

vector <lszone10_clean> has
Number of areas: 1362
Number of isles: 1127
Number of duplicate centroids: 3
Number of areas without centroid: 637

Further on, 26251 areas have been removed.
v.clean tool=rmarea also removes areas without centroids, that's why
holes have been replaced by polygons, boundaries of small areas are
deleted. If you want to merge small areas with adjacent large areas,
v.clean would do the job, but for all areas, also areas
without centroid.
If you want to keep only larger areas and these unchanged,
the method of
Hamish with v.extract would do that.
Or you could do
v.db.addcol map=lszone10 columns="area DOUBLE"
v.to.db map=lszone10 option=area columns=area
and then use where="area > 2800" in further operations.

Markus

On Fri, Dec 12, 2008 at 9:01 PM, Moskovitz, Bob
<Bob.Moskovitz@conservation.ca.gov> wrote:

So, what would cause r.to.vect to create areas without centroids?

I have tried r.to.vect with a Spearfish map and it looks ok:

g.region rast=trn.sites
d.mon x0
d.rast trn.sites

r.to.vect trn.sites out=trn feature=area
Extracting areas...
100%
100%
Building topology for vector map <trn>...
Registering primitives...
74 primitives registered
903 vertices registered
Building areas...
100%
20 areas built
2 isles built
Attaching islands...
100%
Attaching centroids...
100%
Number of nodes: 56
Number of primitives: 74
Number of points: 0
Number of lines: 0
Number of boundaries: 54
Number of centroids: 20
Number of areas: 20
Number of isles: 2
r.to.vect complete.

d.vect trn

d.vect trn disp=topo

v.out.ascii trn format=standard
-> boundaries and centroids

May a potential problem in r.to.vect depend on the shape or the
boundary lengths? Obviously, a reproducible example is desired.

Markus

How do I pack up my raster so I can let you see what is happening? I'd like to send it to you or any other dev if possible.

-----Original Message-----
From: neteler.osgeo@gmail.com
[mailto:neteler.osgeo@gmail.com]On Behalf
Of Markus Neteler
Sent: Friday, December 12, 2008 1:17 PM
To: Moskovitz, Bob
Cc: Markus Metz; grass-user@lists.osgeo.org
Subject: Re: [GRASS-user] r.to.vect and then v.clean using tool=rmarea
createspolygonsinstead of holes.

On Fri, Dec 12, 2008 at 9:01 PM, Moskovitz, Bob
<Bob.Moskovitz@conservation.ca.gov> wrote:
> So, what would cause r.to.vect to create areas without centroids?

I have tried r.to.vect with a Spearfish map and it looks ok:

g.region rast=trn.sites
d.mon x0
d.rast trn.sites

r.to.vect trn.sites out=trn feature=area
Extracting areas...
100%
100%
Building topology for vector map <trn>...
Registering primitives...
74 primitives registered
903 vertices registered
Building areas...
100%
20 areas built
2 isles built
Attaching islands...
100%
Attaching centroids...
100%
Number of nodes: 56
Number of primitives: 74
Number of points: 0
Number of lines: 0
Number of boundaries: 54
Number of centroids: 20
Number of areas: 20
Number of isles: 2
r.to.vect complete.

d.vect trn

d.vect trn disp=topo

v.out.ascii trn format=standard
-> boundaries and centroids

May a potential problem in r.to.vect depend on the shape or the
boundary lengths? Obviously, a reproducible example is desired.

Markus