Skip to content

Commit

Permalink
Sort lines with identical vertical position by horizontal position in…
Browse files Browse the repository at this point in the history
… DataExtractor
  • Loading branch information
stijnvermeeren-swisstopo committed Jan 27, 2025
1 parent b5ef183 commit d385aaf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/stratigraphy/data_extractor/data_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,12 @@ def get_lines_near_key(self, lines, key_line: TextLine) -> list[TextLine]:
feature_lines.insert(0, key_line)
feature_lines = list(dict.fromkeys(feature_lines))

# Sort by vertical distance between the top of the feature line and the top of key_line
feature_lines_sorted = sorted(feature_lines, key=lambda line: abs(line.rect.y0 - key_line.rect.y0))
# Sort by
# - vertical distance between the top of the feature line and the top of key_line
# - horizontal position (left-first) for lines with identical vertical position
feature_lines_sorted = sorted(
feature_lines, key=lambda line: (abs(line.rect.y0 - key_line.rect.y0), line.rect.x0)
)

return feature_lines_sorted

Expand Down

0 comments on commit d385aaf

Please sign in to comment.