-
Notifications
You must be signed in to change notification settings - Fork 0
/
rockHunter.py
146 lines (114 loc) · 5.51 KB
/
rockHunter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import os
import geopy.distance
from pathlib import Path
from dted import LatLon, Tile
# Represents the step increments that in feet
# Example: 100 = 100 feet, the program will check lat long every 50 feet
step = 100
# Represents the minimum distance in feet between cliffs for it to be counted as a new cliff
# setting to 0 will record all lat long points with slope no matter distance
min_distance = 1000
# Target heigh is the vertical change in meters required for a elevation change to be considered a cliff
# slope = step / target_height
target_height = 40
# Turns a dted file into a lat long corner point
def parse_dted_name(file_title):
parts = file_title.split("_")
lat = int(parts[0].replace("n", ""))
long = int(parts[1].replace("w", "")) * -1
return lat, long
# Checks the neighbor cords to detect a cliff
def check_neighbor_cords(lat, long):
# gets target elevation
target_ele = tile.get_elevation(LatLon(latitude=lat, longitude=long))
neighbors = []
# tries to detect upper right neighbor
if not (lat + cal_step_lat >= y_range[1] or long + cal_step_long >= x_range[1]):
cord = lat + cal_step_lat, long + cal_step_long
neighbors.append((cord, tile.get_elevation(LatLon(latitude=cord[0], longitude=cord[1]))))
# tries to detect upper left neighbor
if not (lat + cal_step_lat >= y_range[1] or long - cal_step_long <= x_range[0]):
cord = lat + cal_step_lat, long - cal_step_long
neighbors.append((cord, tile.get_elevation(LatLon(latitude=cord[0], longitude=cord[1]))))
# tries to detect upper neighbor
if not (lat + cal_step_lat >= y_range[1]):
cord = lat + cal_step_lat, long
neighbors.append((cord, tile.get_elevation(LatLon(latitude=cord[0], longitude=cord[1]))))
# tries to detect right neighbor
if not (long + cal_step_long >= x_range[1]):
cord = lat, long + cal_step_long
neighbors.append((cord, tile.get_elevation(LatLon(latitude=cord[0], longitude=cord[1]))))
# tries to detect lower right neighbor
if not (lat - cal_step_lat <= y_range[0] or long + cal_step_long >= x_range[1]):
cord = lat - cal_step_lat, long + cal_step_long
neighbors.append((cord, tile.get_elevation(LatLon(latitude=cord[0], longitude=cord[1]))))
# tries to detect lower neighbor
if not (lat - cal_step_lat <= y_range[0]):
cord = lat - cal_step_lat, long
neighbors.append((cord, tile.get_elevation(LatLon(latitude=cord[0], longitude=cord[1]))))
# tries to detect lower left neighbor
if not (lat - cal_step_lat <= y_range[0] or long - cal_step_long <= x_range[0]):
cord = lat - cal_step_lat, long - cal_step_long
neighbors.append((cord, tile.get_elevation(LatLon(latitude=cord[0], longitude=cord[1]))))
cliff = False
drop = 0
# goes through the neighbors that were detected to see if any can be considerd a cliff
for neighbor in neighbors:
change = abs(neighbor[1] - target_ele)
if change >= target_height:
cliff = True
if (drop < change):
drop = change
return cliff, drop
files = os.listdir("dted")
# loops through if there are multiple files
for file_name in files:
lat, long = parse_dted_name(file_name)
# sets up x and y range and converts step to step degree increments
x_range = [long, long + 1]
y_range = [lat, lat + 1]
distance_long = geopy.distance.geodesic((y_range[0], x_range[0]), (y_range[0], x_range[1])).feet
distance_lat = geopy.distance.geodesic((y_range[0], x_range[0]), (y_range[1], x_range[0])).feet
cal_step_lat = 1 / (distance_lat / step)
cal_step_long = 1 / (distance_long / step)
# opens the first dted file as a tile
dted_file = Path(f"dted/{file_name}")
tile = Tile(dted_file, in_memory=True)
tile.load_data(perform_checksum=False)
current_lat_step = 0
current_long_step = 0
in_lat_range = True
in_long_range = True
targets = []
tot_rows = distance_lat / (step * 2)
current_row = 0
# loops through lat and long range and checks neighbors for cliffs
while (in_lat_range):
current_row += 1
current_long_step = 0
in_long_range = True
print(f"On row {current_row} / {tot_rows} for file {file_name}")
while (in_long_range):
if not (current_long_step >= 1):
this_lat, this_long = lat + current_lat_step, long + current_long_step
cliff, drop = check_neighbor_cords(this_lat, this_long)
# adds cliff to target if meets requirements
if cliff:
add_cliff = True
for cliff_found in targets:
# checks if cliff found is within 1000 feet of another cliff
if (geopy.distance.geodesic((cliff_found[0][0], cliff_found[0][1]),
(this_lat, this_long)).feet < 1000):
add_cliff = False
break
if add_cliff:
targets.append(([this_lat, this_long], drop))
with open("results.txt", "a") as file:
file.write(f"{this_lat, this_long} | {drop} meters\n")
print(f"Found a cliff! {this_lat, this_long} with drop {drop}")
current_long_step += cal_step_long
else:
in_long_range = False
current_lat_step += cal_step_lat * 2
in_lat_range = not (current_lat_step >= 1)
print(targets)