4

When I used QGIS 1.8, I was able to transform polyline layers to polygon layers with the Polygonizer plugin. In QGIS 2.2, this function has been subsumed into the Processing toolbox. Unfortunately, it doesn't seem to work. I see that this problem has come up before (Making polygon from intersecting lines in QGIS using Polygonize or similar?) but hasn't been resolved.

Here's my polyline layer:

input

And here's what I get when I run the polygonizer function:

output

Only a fraction of the closed shapes have been successfully closed by the polygonize function.

Can anyone advise on how I might get this to work correctly? As I said, I was able to do this sort of thing with the old Polygonizer plugin, using the slow/old methodology. That doesn't seem to be implemented in the new function in QGIS 2.2. Is there somewhere else I could find it?

Thanks in advance!

ETA: Running on Windows 7. Installed via the standalone installer on the main QGIS webpage.

ETA2: I installed QGIS 1.8 again and was able to produce this with the old Polygonizer plugin (with the output from the QGIS 2.2 processing function on top). This was produced using the "Old method" in the Polygonizer plugin. It took a long time but it worked much better. The "New method" in the Polygonizer plugin produced the same polygons as QGIS 2.2. So it appears that only the old plugin "New method" has been carried forward into QGIS 2.2?

old polygonizer output

2
  • The fact that some of the lines in your shapefile are being converted to polygons suggests that 'Polygonize' is working as it should. In which case it's most likely the problem is with your line shapefile. Would you try polygonizing this test shapefile? dl.dropboxusercontent.com/u/45121071/laxlines.zip
    – nhopton
    Commented May 9, 2014 at 7:58
  • Hi Nick, I get the "float division by zero" error mentioned in the other thread. I've added a couple of system details to my question above.
    – blackthorn
    Commented May 9, 2014 at 8:50

2 Answers 2

3

It is not a problem of the old Polygonizer plugin vs Processing:Polygonize (script /plugins/processing/algs/qgis/Polygonize.py).

Both use the Python module shapely and the function polygonize

Sequences of touching lines can be merged into MultiLineStrings or Polygons using functions in the shapely.ops module (shapely.ops.polygonize(lines), shapely.ops.polygonize_full(lines), etc.)

The important here is the touching lines. The final result depends on the precision of the nodes (are the lines really touching ?) and the order of the lines in the layers

Example of results with shapely:

The lines

enter image description here

some results of polygonize according to the criteria mentioned:

enter image description hereenter image description here

1
  • Gene, as far as I can tell, the lines are really touching - meeting at common nodes. Can you elaborate on your "order of the lines in the layers" comment? That sounds alarming, as I have no control over the original datasets and how they were created. However, I have been able to get a better polygonize result with the old Plugin method, as I've added in edit to my original question.
    – blackthorn
    Commented May 9, 2014 at 9:33
2

According to this Topic: How to go with...somewhat complex geological maps in QGIS? the polygonizing in QGIS 2.2 fails due to some problems with the shapely library. It is fixed in current Master QGIS 2.3.0 using pythons-shapely 1.2.18-1.

Unfortunately, it does not work with QGIS 2.2.0 from the same OSGEO4W setup. So we have to wait for the stable QGIS 2.4. According to http://qgis.org/en/site/getinvolved/development/index#road-map this should be in June. So not far away.

4
  • Hi Andre, Thanks very much for the advice. I reinstalled QGIS 2.2 with the OSGEO4W setup and advanced install. That wasn't successful. However, QGIS 2.3 (qgis-dev) installed the same way was successful. It replicated the results I got with the Polygonizer plugin, "old method", but much, much faster. Thanks again.
    – blackthorn
    Commented May 9, 2014 at 13:18
  • You are right, it does not work with 2.2.0, even using the same shapely. Same for Ubuntu.
    – AndreJ
    Commented May 9, 2014 at 15:41
  • I use Qgis 2.14 and it's doesn't work...
    – Geo-x
    Commented Oct 10, 2016 at 9:33
  • @Geo-x Polygonizer is now part of Processing, and works for me. You might have to check geometry validity before. Also make sure that the lines intersect, see gis.stackexchange.com/questions/197987/…
    – AndreJ
    Commented Oct 10, 2016 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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