script to extract a subset of polygons for debugging
This commit is contained in:
37
extract-range.py
Normal file
37
extract-range.py
Normal 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())
|
||||
Reference in New Issue
Block a user