0

I had a layer, and I did one offset of it. But the problem is that now I have a offset but the lines are separated.

How can I join them in Python? Because I read about several function as snap, snapped line, snapped geometry, merge, etc.

I wanted to know how can join theses lines, but with Python code.

enter image description here

In the above image you can see the lines after offset, and the next was the code.

import processing

layer = iface.activeLayer()

parameters = { 'DISTANCE' : 5, #offset of 5 meters
               'INPUT' : layer, 
               'JOIN_STYLE' : 1, 
               'MITER_LIMIT' : 1, 
               'OUTPUT' : 'TEMPORARY_OUTPUT', 
               'SEGMENTS' : 8 }

processing.runAndLoadResults('qgis:offsetline',
               parameters)
  • 1
    You need a code attempt in your question or it will be put on hold. Why dont you test the functions you read about? – BERA Mar 08 '20 at 11:07
  • It is a bit unclear what happened - what did the layer look like before the offset? What exactly did you do? – MortenSickel Mar 08 '20 at 11:26
  • I put the code in the question. And the before question was that: https://gis.stackexchange.com/questions/353074/offset-line-with-python-in-qgis – ZacariasSatrustegui2 Mar 08 '20 at 12:54

1 Answers1

2

I digitized your lines for producing vector layer of following image:

enter image description here

After running following script in Python Console of QGIS:

import processing

layer = iface.activeLayer()

parameters = { 'BEHAVIOR' : 0, 
               'INPUT' : layer, 
               'OUTPUT' : 'TEMPORARY_OUTPUT', 
               'REFERENCE_LAYER' : layer, 
               'TOLERANCE' : 30 }

processing.runAndLoadResults('qgis:snapgeometries',
                             parameters)

I got following result with a tolerance of 30 meters (adapt tolerance distance for your particular case):

enter image description here

I hope that it helps.

xunilk
  • 29,891
  • 4
  • 41
  • 80
  • Yes!!! That was amazing. If I have more questions I will put the question here because you are a crack. Thank you so much. – ZacariasSatrustegui2 Mar 08 '20 at 15:56
  • One question, How did you digitize the lines? If you want, I can write a new question, however you want ;) – ZacariasSatrustegui2 Mar 08 '20 at 15:57
  • 1
    I downloaded your image and, arbitrarily, I used this command gdal_translate -a_srs EPSG:32612 -a_ullr 438819.2292659355 4457217.5520328125 439505.5584333043 4456912.752032501 AKrls.png lines.tif for assigning a projection. Then, I digitized all the lines where I already knew that the separation between them was only a few meters (by using this extension and projection). – xunilk Mar 09 '20 at 00:52
  • Thank you very much. I put another question about the length of the lines, maybe you can know how solve that. :https://gis.stackexchange.com/questions/353427/how-can-i-get-the-length-of-all-lines-in-python-qgis – ZacariasSatrustegui2 Mar 09 '20 at 09:37