[GRASS-user] generate polygon from lines

I have a vector layer that contains lines which define a polygon.
I have attempted to build a polygon from the layer but have not had much luck.

I have used v.clean input=bnd output=bndc tool=snap thres=0.0001 to snap any small dangles together (my data is in lats/longs) which output the following;

±--------------------------------±--------------+
| Tool | Threshold |
±--------------------------------±--------------+
| Snap vertices | 1.000000e-04 |
±--------------------------------±--------------+
Copying vector lines …

Rebuilding parts of topology …
Building topology …
234 primitives registered
Topology was built.
Number of nodes : 238
Number of primitives: 234
Number of points : 0
Number of lines : 234
Number of boundaries: 0
Number of centroids : 0
Number of areas : -
Number of isles : -

Tool: Snap line to vertex in threshold
All vertices: 2140
Registered points (unique coordinates): 1910
Nodes marked as anchor : 1837
Nodes marked to be snapped : 79
Snapped vertices : 88
New vertices : 3

Rebuilding topology for output vector …
Building topology …
234 primitives registered
Building areas: 100%
0 areas built
0 isles built
Attaching islands:
Attaching centroids: 100%
Topology was built.
Number of nodes : 235
Number of primitives: 234
Number of points : 0
Number of lines : 234
Number of boundaries: 0
Number of centroids : 0
Number of areas : 0
Number of isles : 0

I then used v.build map=bndc error=err option=build --overwrite which output the following;

Building topology …
234 primitives registered
Building areas: 100%
0 areas built
0 isles built
Attaching islands:
Attaching centroids: 100%
Topology was built.
Number of nodes : 235
Number of primitives: 234
Number of points : 0
Number of lines : 234
Number of boundaries: 0
Number of centroids : 0
Number of areas : 0
Number of isles : 0
WARNING: The vector ‘err’ already exists and will be overwritten.
Building topology …
0 primitives registered
0 areas built
0 isles built
Attaching islands:
Attaching centroids: Topology was built.
Number of nodes : 0
Number of primitives: 0
Number of points : 0
Number of lines : 0
Number of boundaries: 0
Number of centroids : 0
Number of areas : 0
Number of isles : 0

Obviously there were no polygons created.
Regardless of the combinations I try (ie v.clean with the break option, followed by v.clean with the snap option) I am unable to create a polygon.
I have added the shapefile into QGIS and physically viewed the line to check if there are any gaps - which there aren’t.

What am I missing?

I am using grass 6.0.1 on gentoo.

Craig

Craig Feuerherdt wrote:

I have a vector layer that contains lines which define a polygon.
I have attempted to build a polygon from the layer but have not had
much luck.

...

Number of nodes : 238
Number of primitives: 234
Number of points : 0
Number of lines : 234
Number of boundaries: 0
Number of centroids : 0
Number of areas : -
Number of isles : -

In GRASS-land boundaries + centroids make polygons, so convert lines to
boundaries with v.type and add centroids with "v.category option=add".

If it still doesn't work check with v.digit that all your nodes are
snapped (green "x"s instead of red ones).

Hamish

I attempted what Hamish suggested ie

as per newly arrived message on the mailing list, try that step again (v.category) with type=area instead of type=centroid.

however I am still unable to generate a polygon. I have checked that all the intersections are broken and that there are no ‘undershoots’ using v.digit

Thanks in advance.

Craig

---------- Forwarded message ----------

Hamish,

thanks for the response.
I have tried what you suggested but without much luck :frowning: - no doubt due to my newbie grass status and my mind being tainted by arcinfo methodology!
I have attached the shapefile for you to look at and to make sure that you can get it to work (hope you don’t mind). The lines have been ‘selected’ from other layers (ie roads, rivers) hence the reason there are ‘dangles’.

My methodology thus far;

  • import shapefile using v.in.ogr
  • v.clean input=bnd output=bnd_break type=line tool=break (to break lines that intersect)
  • v.type input=bnd_break output=bnd_poly type=line,boundary
  • v.category input=bnd_poly output=bnd_poly2 type=centroid option=add (to add a centroid)
  • v.build map=bnd_poly2 error=err

My map is still a line :frowning:

Craig

On 8/28/06, Hamish <hamish_nospam@yahoo.com> wrote:

Craig Feuerherdt wrote:

I have a vector layer that contains lines which define a polygon.
I have attempted to build a polygon from the layer but have not had
much luck.

Number of nodes : 238
Number of primitives: 234
Number of points : 0
Number of lines : 234
Number of boundaries: 0
Number of centroids : 0
Number of areas : -
Number of isles : -

In GRASS-land boundaries + centroids make polygons, so convert lines to
boundaries with v.type and add centroids with “v.category option=add”.

If it still doesn’t work check with v.digit that all your nodes are
snapped (green "x"s instead of red ones).

Hamish

Craig Feuerherdt wrote:

I attempted what Hamish suggested ie

> as per newly arrived message on the mailing list, try that step
> again (v.category) with type=area instead of type=centroid.

however I am still unable to generate a polygon. I have checked that
all the intersections are broken and that there are no 'undershoots'
using v.digit

almost there; looking at the shape file you sent me in v.digit there are
dangling nodes inside the polygon. Those will have to be removed first.

# change dangles back to lines:
v.clean in=bnd_poly out=bnd_poly_clean tool=chdangle thresh=-1

so the full process looks like:

v.in.ogr in=bnd_test.shp out=bnd
v.clean input=bnd output=bnd_break type=line tool=break
v.type input=bnd_break output=bnd_poly type=line,boundary
v.clean in=bnd_poly out=bnd_poly_clean tool=chdangle thresh=-1
v.category input=bnd_poly_clean output=bnd_area option=add

d.vect bnd_area

done!

Hamish