[GIS] Convert shapefile lines to a polygon in GRASS

convertgeometry-conversiongrasspolygon

I have a shapefile of a map that is the outline of a number of islands. I would like to convert the lines into polygons (ie all islands filled in) using GRASS. I searched on how to do this with GRASS but just got some very brief and vague suggestions … but I gave it a go anyway ….

use v.in.ogr to import the shapefile into grass
And view the result (I'm using QGIS to do this): Looks good.

v.clean input=g_hwp_p1 output=g_hwp_p1_clean tool=break,snap thresh=10,10
v.type input=g_hwp_p1_clean output=g_hwp_p1_clean_type type=line,boundary
v.centroids input=g_hwp_p1_clean_type output=g_hwp_p1_clean_type_centroids 

This didn't work which is not surprising as I don't really understand what I'm doing.

V.info says that…

g_hwp_p1 has 892 lines
g_hwp_p1_clean has 892 lines
g_hwp_p1_clean_type has 892 boundaries
g_hwp_p1_clean_type_centroids has 892 boundaries (0 centroids, 0 areas, 0 islands)

Also v.type reports:

892 incorrect boundaries.

And v.centroids reports:

0 features modified.

The final output looks much like the input (just an outline).

Can anyone spot what I'm doing wrong? Does anyone know what the correct parameters should be?

I also tried this in QGIS using the lines-to-polygon fTool but this didn't do a very good job of it (it didn't fill in the whole islands but just seemed to add little polygons round the edge).

Shapefile is here…
https://docs.google.com/leaf?id=0B93lksnTC7_cYWIxNTlmNzEtYTcwYi00YmZlLTlhZmEtZDViYmE1MmYxNDk2&hl=en_US

Screenshoy of hwp_p1 ….
https://docs.google.com/leaf?id=0B93lksnTC7_cN2Q5YTNiMjEtZjY4OS00ZTYwLWIxMDAtYzBlNmY1M2U1MGRl&hl=en_US

And a close-up of a small Island – it forms a closed loop..
https://docs.google.com/leaf?id=0B93lksnTC7_cZjQ1ZDU4ZGQtMWNmMC00ZjNiLWFiZmEtM2MyMDE0MmYzODQ5&hl=en_US

Thanks.

Best Answer

This is an old question, but I ran into a similar problem today and found a way to do it. I have a shp of city blocks, but each "block" is actually a set of 4 street lines. This is the way to convert them into areas:

  1. v.build.polylines will convert connected lines to a polyline.

  2. v.type to convert the polylines to boundaries.

  3. Finally v.centroids to add centroids to the closed boundaries and thus create areas

Related Question