1

I am unsure if this is the fastest way to test if LineStrings cross each other. Is there a better method.

for line_1, line_2, in itertools.combinations(lines, 2):
    crosses = line_1.crosses(line_2)
    if crosses is True:
         print(line_1, line_2)

Obviously this gets pretty slow with large files, I have found maybe loading it into an rtree index may speed this up.

1 Answer 1

0

I have improved this now using shapely prep

import shapely
line_lo = [line for line in lines]   
for line in lines:
    line_lo.remove(line)
    line_prep = shapely.prepared.prep(line)
    hits = list(filter(line_prep.intersects, line_lo))
    if len(hits) > 0:
          for line1, line2 in combinations(hits, 2):
              crosses = line_1.crosses(line_2)
              if crosses is True:
                  print(line_1, line_2)

This has significantly improved the processing time on larger datasets, small increases in processing time on small datasets.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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