I have a shapefile with city areas but unfortunately the shapefile only contains single lines. The shapefile looks like this:

enter image description here

I want to convert those lines to an area-polygon shapefile in QGIS. I tried it with the "Lines to polygons" tool (Vector > Geometry Tools > Lines to polygons), but it didn't work correctly. After using this tool the shapefile looks like this:

enter image description here

Is there any other way to convert the line shapefile to an area polygon shapefile in QGIS?

By the way, I am using QGIS 2.14.3 Essen.

  • 2
    I got something similar the last time I used that tool. I was able to get polygons by using the polygonize tool. – johns Aug 18 '16 at 16:47
  • Thnaks for your answer, where can I find the polygonize tool? – Mark White Aug 18 '16 at 17:18
  • Polygonize can be found here - Processing Toolbox, QGIS geoalgorithms, Vector geometry tools. – klewis Aug 18 '16 at 17:27
  • I tried it, but when I run the polygonizer I get an empty shape file :-( – Mark White Aug 18 '16 at 18:04
  • Can you upload the shapefile to dropbox or similar? – AndreJ Aug 19 '16 at 6:48

The Polygonize tool from the Processing toolbox still works fine for me on simple lines:

enter image description here

It is however necessary that the lines intersect, or share common vertices. And lines should have no self-intersection.

You might need to snap the corner vertices to get it working. I usually set the snapping tolerance to 10 pixels to the vertex.

| improve this answer | |

Just a hint if you can't find the Polygonize tool. In my QGIS 2.18.3 installation (Windows) I could not find the Polygonize tool at Vector geometry tools within the Toolbox. It took me some time to realize that I needed to install the python-shapely library with OSGeo4W (thanks Nick Hopton : Perfect Polygons in QGIS).

| improve this answer | |
  • Thank you! I was confused for a long time because out of the box QGIS on Windows has a polygonize tool that's only for rasters. Another step that may or may not be necessary is to enable QGIS Geoalgorithms under "Processing >> Options >> Providers" – matt wilkie Jun 26 '17 at 0:54
  • Thanks for this answer. I thought I was going crazy not finding it anymore... – gisnside Jan 12 '18 at 16:30

Looking at your image I would assume that each line does not fully encompass an area, the lines are just acting as fences and not reconnecting back at the beginning. Your polygons are being created from the ends of the lines so the 'lines to polygons' tool is working fine, its the data thats the issue.

I'm afraid the only you can do that I can think of is to digitise a new layer of polygons. Thankfully QGIS has made that really easy with the trace digitising tool (a magnet icon) which is available in 2.14

| improve this answer | |

If the polylines overlap each other, Polygonize tool cannot handle it as follows:

enter image description here

However Lines to polygons tool works as expected as follows:

enter image description here

| improve this answer | |

If there are no holes, I would create a scratch layer with a single polygon big enough to cover your whole area. Then I would intersect it with your lines-to-polygons result and split it further as necessary.

| improve this answer | |

Tested on QGIS 2.18 and QGIS 3.4

I can suggest using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer....

Let's assume we have five line features in "lines", see image below.


With the following Query, it is possible to achieve the result.

SELECT l.id, l.NAME, MakePolygon(AddPoint(l.geometry,StartPoint(l.geometry)))
FROM lines AS l

The output Virtual Layer will look like


As was already mentioned by @AndreJ the lines shall intersect or share common vertices. And lines should have no self-intersection. In terms of cleaning the layer's topology, I can suggest exploring the v.clean GRASS toolset.

In case lines have self-intersection you can use a ConvexHull with the following Query

SELECT l.id, l.NAME, ConvexHull(AddPoint(l.geometry,StartPoint(l.geometry)))
FROM lines AS l




| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.