7

In QGIS, I want to make polygons from a set of intersecting lines. Looking at the screenshot here, I want chop the purple line (it's a closed line, not a polygon) where it crosses the green and blue lines. The result hopefully would be a polygon where I have hatched in red. I have quite a few to do.

Polygonize problem

I have tried the QGIS tool previously called Polygonizer (see An Introduction to the Polygonizer Plug-in), but now called Polygonize. This is a tool that, given a layer containing a set of crossing lines arranged essentially like a # symbol, should create a polygon from the enclosed space in the middle.

(In QGIS 2.01, Polygonize is in the top menu bar: go to Processing -> Commander, then type "Polygonize" on the command line, select "Processing algorithm: Polygonize" from the list that appears, and press Enter.)

At the momemt Polygonize doesn't work properly. Is there another way to do what I want to do?

For example, wouldn't it be great if the QGIS 'Split Feature' command was able to work like MapInfo's 'Polyline Split', where you select the polygons to split, then select an already-drawn polyline to split by, and voila. But Split Feature seems not to work that way.


UPDATE: Detail of problems with running Polygonize.

I have 64-bit QGIS 2.01 installed to Windows 7 from the installer package, QGIS-OSGeo4W-2.0.1-3-Setup-x86_64.exe.

The routine processed an output from my shapefile, but did not create a polygon from the region enclosed by intersections between the blue, green and purple lines. (Note: in the actual input file, all these lines are on the same layer; the screenshot just colours them differently for illustrative purposes). What I got instead was a simple conversion of the purple outline to a polygon, as though the program completely ignored the blue and green lines.

When I node-edited the closed purple line, to open it so that I had a set of open crossing lines like in the # symbol, and then ran Polygonize again, nothing happened. No crash, but no visible polygon in the output file.

When I used Nick Hopton's own Laxton.kml data, I got a crash; see screenshot:

Laxton data crash

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
IanS
  • 1,373
  • 2
  • 16
  • 25
  • With things that appear to be missing, it often helps if you can tell us how you installed the tool (in this case, QGIS 2.0.1) and which operating system you installed it on. Perhaps you are hitting: http://gis.stackexchange.com/questions/72059/qgis-2-python-error-on-mac-osx but there is no way to be sure unless you provide more detail. – BradHards Feb 05 '14 at 10:54
  • Ok, yes, sure. Windows 7, installed 64 bit from the installer package, QGIS-OSGeo4W-2.0.1-3-Setup-x86_64.exe – IanS Feb 05 '14 at 11:09
  • Please edit the question, instead of putting key details in the comments. – BradHards Feb 05 '14 at 11:10
  • As you mention, the Polygonizer plug-in has been subsumed into the Processing Toolkit. Processing -> Toolbox and search on 'Polygonize'. I believe there are problems with this tool at present (under Ubuntu, at least) and would be interested in knowing if it works for you. – nhopton Feb 05 '14 at 12:38
  • Ok, I found it. Processing -> Toolbox -> Commander -> [type command line: Processing algorithm: Polygonize] [Enter] It worked as in didn't crash, but did not work in that it simply created polygons from the closed purple lines, without trimming them by the two long tranverse lines. NB all lines were on the same layer, not as illustrated above. – IanS Feb 05 '14 at 13:03
  • So now I tried opening some of the closed lines, to see if that would prompt the algorithm to ploygonise those areas now enclosed only by open lines, e.g. like the region in the middle of a hash symbol #. But it did not work, the open lines just stayed open, and no enclosed area was polygonised, unless, as noted in my comment above, it simply created a polygon from a self-closed line object. – IanS Feb 05 '14 at 13:16
  • Are your lines noded on intersections? Crossing lines must be noded before executing the Polygonize algorithm. Not sure, but think 'Line dissolve' in the Processing toolbox could do that. – César Argul García Feb 05 '14 at 14:03
  • From what you write it's difficult to work out whether or not the polygonize tool is working as it should. Working on a copy of your shapefile, add two new lines, one crossing the red line and the blue line at bottom left and another doing the same thing at top right. Then try using the polygonize tool on this. Close the open areas at each end, in other words. – nhopton Feb 05 '14 at 14:03
  • 1
    Okay, looking at your recently added image: "Float division by zero". This is what I'm getting at the moment, the tool is broken. I was sent a new version to test, which requires a more recent version of Shapely, which I'll try to install but I'm not sure how to do this on Ubuntu. N. – nhopton Feb 05 '14 at 14:23
  • I tried a new, simplified, version of the file, this time with nodes on all intersections. Again, no crash but no polygon. So, broken, huh? – IanS Feb 05 '14 at 22:44
  • It might just be worth looking at which version of Shapely you have installed. I've been told that Version 1.2.16 or higher is required. – nhopton Feb 06 '14 at 09:30
  • Sadly, I don't know where to look and I haven't found any instructions. Maybe I will try again when QGIS 2.2 is out. – IanS Feb 06 '14 at 12:03
  • 2.4 is now out. I just installed it and tried polygonize on a small test set. It still throws the divide by zero error. – Ian Goddard Jun 27 '14 at 21:28
  • For figure B, are you sure interior and exterior lines touch in one point or intersect? If not, no connection is made with polygonize, while lines to polygons will try to close shapes. – AndreJ Jun 11 '16 at 15:02

4 Answers4

1

The problems with 'Polygonize' appear to have gone away in recent builds of QGIS (in later builds of 2.4 and in 2.5).

Perhaps it's time for this topic to disappear too, rather than being bumped by 'Community' every so often.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
nhopton
  • 6,983
  • 1
  • 19
  • 36
  • 2.4 is now out. I just installed it and tried polygonize on a small test set. It still throws the divide by zero error. – Ian Goddard Jun 27 '14 at 21:28
  • In 2.4 installed using OSGeo4W, Polygonize (in the Processing toolbox) works fine. – underdark Sep 14 '14 at 10:41
  • @IanGoddard. Just checking Ian, you have installed Shapely? (python-shapely.) If not, you can install it using OSGeo4W. – nhopton Sep 14 '14 at 12:27
1

For getting correct results from the polygonize tool (which can be accessed via Processing > Commander) it is necessary that the lines intersect, this is also stated in the pdf file http://confound.me.uk/maps/ppv4.pdf

Polygonize extracts points where lines intersect and uses them, together with points from the original lines, to construct polygons

According to your errors using this tool I assume, that the lines of the triangle are not closed on every edge and the lines inside the square also do not intersect the square itself.

tallistroan
  • 2,351
  • 1
  • 13
  • 17
  • If indeed the lines have to intersect rather than just touch/meet, that would seem a slight deficiency in the tool, as I would argue that example B from @Eduardo should generate 4 polygons. I've come across a similar issue having just used the Polygonize tool for the first time and it's frustrating. – Gonja Sep 21 '16 at 10:34
1

According to this Topic: How to go with...somewhat complex geological maps in QGIS? the polygonizing in QGIS 2.0 and 2.2 fails due to some problems with the shapely library. It is fixed in current QGIS Master (2.3.0).

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.

AndreJ
  • 76,698
  • 5
  • 86
  • 162
0

In OPEN JUMP GIS there is a good running editing function which make polygons from a polyline network:

Polygonize... - all the enclosed areas inside crossed lines can be transformed in polygons. Optionally input data may be noded before polygonization (http://ojwiki.soldin.de/index.php?title=Tools)

You find a free Downloadlink here: http://openjump.org/