7

I have a similar question to: How to join lines in QGIS for later using "lines to poly"?

I have a line shapefile that I wish to transform into a polygon shapefile. After making some cleaning and closing some gaps, the lines have this look: Original shapefile (lines)

After that I've made "Vector>Geometry Tools>Lines to Polygons" but I've got this: Transformed shapefile (polygons)

I've made a detection for dangles... and I found a few on the places that seems to have that kind of error. Also... the location of those points, seems to be on the places the "lines to poly" process fails. I've tried to edit some of the dangles, snapping them to the nearest point to make sure there were no gaps... but running again the dangles detection, they're still there. This is how all the shapefiles (plus the dangles) look like: Shapefiles (lines+polygons+dangle detection

Is this easy to fix without "going to the grass"? Why don't the dangles disappeared after snapping them to the correct place?

EDIT 1: I was able to clean all the dangles... I was not happy with the snapping... and I've retried once more. I guess I was trying the wrong ones... I tried a very simple one... and one by one I was able to solve the more complex dangles, some were overshoot lines that were behind other segments and other were the intersections. Well... after that, I was able to clean all the dangles!!!! :D

Now for the bad news... I got an error while making the Lines to Polygons:

An error has occured while executing Python code:

Traceback (most recent call last):
  File "C:\PROGRA~1\QGISCH~1\apps\qgis\python\plugins\fTools\tools\doGeometry.py", line 348, in run
    success = self.lines_to_polygons()
  File "C:\PROGRA~1\QGISCH~1\apps\qgis\python\plugins\fTools\tools\doGeometry.py", line 519, in lines_to_polygons
    if inFeat.geometry().isMultipart():
AttributeError: 'NoneType' object has no attribute 'isMultipart'

Python version:
2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]


QGIS version:
2.4.0-Chugiak Chugiak, 8fdd08a
(...)]

Does this ring any bells to you guys?

(by the way... the first question was about the dangles... now it's about the lines to polygons process, however... the question is "Can't transform lines to polygons" should I close this and start another or may I continue here?)

EDIT 2: user30184 asked for the Layer (no dangles at the moment): Lines shapefile

Fernando
  • 326
  • 2
  • 9
  • Possible duplicate of: http://gis.stackexchange.com/questions/93369/how-to-go-with-somewhat-complex-geological-maps-in-qgis There seems to be no easier way. – AndreJ Oct 17 '14 at 09:49
  • @AndreJ I've updated my question... I've get rid of the dangles... but, now I can't get the lines to polygons to work. :P – Fernando Oct 17 '14 at 10:18
  • 1
    Have you used the Polygonize Command from Processing, as mentioned in the linked answer? – AndreJ Oct 17 '14 at 10:20
  • Can you share you shapefile? – user30184 Oct 17 '14 at 10:28
  • @AndreJ I didn't, but after your question I've tried Polygonize instead of the "Lines to Polygons" and I also got an error:Algorithm Polygonize starting... Processing lines... 'NoneType' object has no attribute 'isMultipart' See log for more details – Fernando Oct 17 '14 at 10:30
  • @user30184 Yes, no problem in sharing... I've inserted it on the post (under EDIT 2). – Fernando Oct 17 '14 at 10:47
  • Is it really the same shapefile? What I downloaded has 85 line features, most of them unconnected. By looking at the attributes is comes from layer ZTIP_CORR and there are only two areas which could be closed. – user30184 Oct 17 '14 at 11:15
  • My last comment probably feels odd, but your shapefile is invalid for some other programs than QGIS. Apparently because of this QGIS bug http://hub.qgis.org/issues/11007. Even ogr2ogr finds 85 features but after conversion into another shapefile the count is only 12. – user30184 Oct 17 '14 at 13:21
  • @user30184 I only now am able to answer... I did something as simple as save as, and opened the new shapefile... I was able to use Polygonize without problem. With the old shapefile I keep having the same problem. Something is wrong... somewhere!! :) – Fernando Oct 17 '14 at 14:27
  • Ok, so even QGIS itself can cope with the shapefiles it creates after performing some processing task. Good to know that save as works as a workaround. – user30184 Oct 17 '14 at 14:44
  • @user30184 Hey there... I had the weekend in between and didn't tried anything until now.I found one other thing.It wasn't "my" Save as that solved the problem... it was a selection of attributes. Polygonize, probably works with the selected attributes. I've found that selecting all attributes with the "Select features by rectangle" was selecting everything but 2 attributes. It was like they were empty. With that selection I got the Polygonize to work, without it... I get the error I mentioned before. I did one more test... I deleted those two "empty" attributes... ran the Polygone and worked! – Fernando Oct 20 '14 at 08:45

3 Answers3

7

So... I'm answering my own question. I'm just selecting my answer because it's not using GRASS and, at the moment, I'm trying to stick to the QGIS environment (in the future, I'm almost sure I'll need to invest more in GRASS).

So... this is what I've did:

  1. I selected the select attributes by rectangle enter image description here
  2. selected my whole layer enter image description here
  3. Opened the layer attribute table, where I found this: enter image description here
  4. Then turned into edit mode, inverted the selection, deleted those 2 attributes (ID 104 and ID 106), saved and exited edit mode. The table became: enter image description here
  5. After that... just needed to run Poligonize: enter image description here
  6. And... here it is, the final result: enter image description here

Resuming... it was not the "save as" that corrected the layer. It was those 2 attributes (some kind of trash from previous handling of the shapefile) that were corrupting the file logic, after removing them Polygonize was able to run without any kind of trouble.

Fernando
  • 326
  • 2
  • 9
4

Cleaning the original shapefile using GRASS v.clean snap from the Processing Toolkit (using a Threshold of 10) produces a line shapefile that can be polygonised using 'Polygonize' also from the Processing Toolkit.

enter image description here

nhopton
  • 6,983
  • 1
  • 19
  • 36
  • I was trying to get away from GRASS... just because it's something I'm not very used to. I'll try to test your solution as soon as possible. However I was able to use the Polygonize after making a copy of the shapefile (Save As). Thanks for the help! – Fernando Oct 17 '14 at 14:29
  • GRASS and I don't get on either, but you can use these functions within QGIS: Processing -> Toolbox. – nhopton Oct 17 '14 at 18:00
  • I found a way to solve this... I'll post some pictures showing how I've done it in a while. – Fernando Oct 20 '14 at 08:47
  • Actually, what you did was very sensible. ogr2ogr (used in QGIS via "save as..") is good at repairing some sorts of broken shapefile. – nhopton Oct 20 '14 at 09:35
  • please check my answer... it was not the "Save As". I tried to recreate later the proceeding and it didn't work. It was the removal of 2 attributes. Many thanks for the help. – Fernando Oct 20 '14 at 10:28
3

I too faced similar problem when trying to polygonize lines using the "Lines to Polygons" tool. Obtained sliver polygons similar to the above images. But when I tried polygonization using "Polygonize" tool from the Processing Toolbox, got the exact desired polygons. Refer this link

Sjs
  • 997
  • 1
  • 11
  • 23