script to extract a subset of polygons for debugging

This commit is contained in:
Radovan Bast
2025-03-06 10:20:13 +01:00
parent debb82cae3
commit 0b58edbcda

37
extract-range.py Normal file
View File

@@ -0,0 +1,37 @@
"""
This works like the convert.py script but accepts a range of polygons to extract.
This is useful for debugging the meshing code.
Example usage:
$ python extract-range.py Norgeskyst.txt 2 4 > coast.txt
This will extract polygons 2, 3, and 4 from the file Norgeskyst.txt and write
them to coast.txt. First polygon is 1, not 0.
"""
import sys
file_name = sys.argv[-3]
start_polygon = int(sys.argv[-2])
end_polygon = int(sys.argv[-1])
current_polygon = 0
with open(file_name, "r") as f:
_ = next(f)
_ = next(f)
while True:
try:
line = next(f)
except StopIteration:
break
n = int(line.split()[0])
current_polygon += 1
if current_polygon > end_polygon:
break
if start_polygon <= current_polygon <= end_polygon:
print(f"polygon {n}")
for _ in range(n):
line = next(f)
if start_polygon <= current_polygon <= end_polygon:
print(line.strip())