3

I have two questions :

I have some lines (eg: road network). I want to find coordinates of each junction.

  1. Should i use crosses or intersects function from python's Shapely module? They are giving different counts.

  2. Moreover these functions return boolean value. How to get the junction coordinates ?

    with open('./lines.geojson') as f:
        lines = json.load(f)
    
    line = []
    
    for feature in lines['features']:
        line.append(feature['geometry']['coordinates'])
    
    count = 0
    for i in range(len(line)-1): 
       j =i+1 
       while (j < len(line)):        
            l1 = LineString(line[i])
            l2 = LineString(line[j])
            if l1.crosses(l2)== True :
                count =count+1        
            j = j+1
    

1 Answer 1

12
  1. From Shapely's doc:

intersects() is equivalent to the OR-ing of contains(), crosses(), equals(), touches(), and within().

So there might be some cases where two lines intersect eachother without crossing, in particular when one line contains another or when two lines are equals.

More specifically:

crosses() returns True [...] if the dimension of the intersection is less than the dimension of the one or the other.

So if two lines overlap, they won't be considered as "crossing".

  1. intersection() will return a geometric object.
1
  • Thanks! just wanted to add that coordinates of the junction points can be extract using object.coords[0] .
    – Jio
    Feb 28, 2016 at 10:33

Your Answer

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

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