1

This code works below fine when line(The Circle I mean) intersects more than two new lines but fails when both the intersection falls in the middle of the same line

polygon_path = iface.activeLayer()
        line_path = buffers_dir+"/bufferline"+ str(i.id()) +".shp"
        #Converting the buffer features to lines
        processing.runandload("qgis:polygonstolines",polygon_path,line_path)
        linebuffer=iface.activeLayer()
        selections=[]  # The id of he intersected path of the network layer
        for f in layer.getFeatures():
            for a in linebuffer.getFeatures():
                print(a,'This is A')
                if a.geometry().intersects(f.geometry()):
                    #Finds the intersection of line buffers with network layer
                    intersection = a.geometry().intersection(f.geometry())
                    #same result with .within() and even with a and f switched (the docs aren't that clear on that)
                    print(intersection.asPoint())
                    instersection_point = intersection.asPoint()
                    connecting_points.append(instersection_point) #Contains the (X,Y) co-ordinates of intersection points
                    selections.append( f['WVK_ID'] )

enter image description here

Expected result is something like this:

((114041,400590), ' This is intersection')
([228201037.0, 227201083.0, 228201038.0, 228200076.0, 228201026.0, 227200047.0, 227201082.0], ' This is Selections')

The result i got is:

((0,0), ' This is intersection')
([227200062.0], ' This is Selections')

Error Occured:

  File "<string>", line 186, in <module>
  File "C:\PROGRA~1\QGISWI~1\apps\Python27\lib\random.py", line 274, in choice
    return seq[int(self.random() * len(seq))]  # raises IndexError if seq is empty
IndexError: list index out of range

Your Answer

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

Browse other questions tagged or ask your own question.