[GRASSLIST:965] Re: Planning swath bathymetry surveys

Hamish hamish_nospam at yahoo.com
Mon May 1 06:44:43 EDT 2006


> Thanks for your help Hamish.

No worries, this is something I will use.
 
> I'm still learning the ins and outs of vectors and it doesn't always
> make sense to read the man pages. I couldn't find a way to dissolve
> the areas into a single unit. v.extract -d did the trick!
> 
> There was quite a bit of magic in that script you built, though you've
> been so deep in GRASS (I suspect) I doubt that you see it.
> 
> For the rest of us:
> 
> 1. v.buffer left us with a borked vector file. Huge, criss-crossing
> boundary lines which only defined a few actual areas (that is, only a
> few of the enclosed spaces had centroids).

note debug= was used to stop the module before cleaning. The v.clean
step might be avoided if this is omitted or set to something else. ?
 
> 2. You used v.clean tool=break to break the criss-crossing boundary
> lines at intersections. There were still no centroids in most of the
> enclosed spaces.

Yes, that tool does just what it says.
 
> 3. This is confusing: You then used v.category to add centroids to all
> of the potential areas?  How did v.category know where the new areas
> were?? What happened here? Why is a command called v.category adding
> centroids? (Magic #1)

Yes.. Markus just reminded me where this one lived about two weeks ago.
"you can't add cat numbers without centroids?" (thin logic...)

What really does the magic is the Vect_get_point_in_area() library
function, in lib/vector/Vlib/poly.c

/*!
 \fn int Vect_get_point_in_area( struct Map_info *Map, int area, double
*X, double *Y)
 \brief get point inside area and outside all islands
        Take a line and intersect it with the polygon and any islands.
        sort the list of X values from these intersections.  This will
        be a list of segments alternating  IN/OUT/IN/OUT of the polygon.
        Pick the largest IN segment and take the midpoint. 
 \return 0 on success, -1 on error
 \param Map_info structure, area number, x, y
*/

If v.category doesn't find a centroid it uses that fn to find out where
to put it and then goes ahead and adds it. I suppose this could be added
as a v.clean tool or somewhere else more appropriate..?
 

> 4. Once you've got closed boundaries and a centroid for each enclosed
> space, presto these are now areas!?

*YES*. area=centroid+boundary. An area is defined as a boundary (usually
without attributes or even category number) containing a centroid. If
the area does not contain a centroid it is considered to be a hole/
island, and most modules will treat it as such (ie ignore it). The same
goes for any feature without a category number. Besides holding the cat
number, the centroid is where attributes about the area are held.

it is touched upon in:
 http://grass.ibiblio.org/grass61/manuals/html61_user/vectorintro.html

note how "v.to.db type=" won't let you pull from "area".


> Was this also a bit of v.category magic?  Now v.category turns
> boundaries + centroid into areas. Maybe v.category is a bad name for
> this module (suggest: v.makearea)? (Magic #2)

as soon as there is a centroid inside a boundary you have an area.
experiment with v.digit a bit and watch the lines change color.

v.category is still for doing things to categories, the question is if
this "feature" should be promoted to its own v.clean tool. Code
replication is bad, as if a bug is found it usually only gets fixed in
one of the occurances.

 
> 5. Now you extract all of the areas with a category = 0

No, I set all categories to "1" to have all areas with common cat
number. Starting point was 1 and step was 0 so result is 1,1,1,1,1,..
instead of normal 1,2,3,4,5,6,7,...


> and dissolve them into a single area using v.extract -d. This is
> documented, but I never thought to look at extract to do a dissolve.
> (Hidden Gem #1)

Ok, this one's my fault. I don't exactly remember why, but think of it
as "extract the outer boundary" and it makes more sense. Everything was
already in place in that module which is why it was so easy to add there
using only a flag.

 
> 6. End result: a vector with a single area that represents the total
> area of the buffered line above.
> 
> Cool, but weird.

With time features may migrate to more obvious homes.. be they the same
libary fns called from new tools or from script frontends like
v.what.vect.



Hamish




More information about the grass-user mailing list