Skip to content

Commit

Permalink
works! (for now lol)
Browse files Browse the repository at this point in the history
  • Loading branch information
adenjonah committed May 20, 2024
1 parent 526a7ec commit a33af22
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 84 deletions.
12 changes: 6 additions & 6 deletions server/json_databases/geojson/geological_sites.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"type": "Feature",
"properties": {
"Name": "C",
"Name": "Geolocigal Site C",
"stroke": "#000000"
},
"geometry": {
Expand All @@ -19,7 +19,7 @@
{
"type": "Feature",
"properties": {
"Name": "A"
"Name": "Geolocigal Site A"
},
"geometry": {
"coordinates": [
Expand All @@ -33,7 +33,7 @@
{
"type": "Feature",
"properties": {
"Name": "B"
"Name": "Geolocigal Site B"
},
"geometry": {
"coordinates": [
Expand All @@ -47,7 +47,7 @@
{
"type": "Feature",
"properties": {
"Name": "D"
"Name": "Geolocigal Site D"
},
"geometry": {
"coordinates": [
Expand All @@ -61,7 +61,7 @@
{
"type": "Feature",
"properties": {
"Name": "E"
"Name": "Geolocigal Site E"
},
"geometry": {
"coordinates": [
Expand All @@ -75,7 +75,7 @@
{
"type": "Feature",
"properties": {
"Name": "F"
"Name": "Geolocigal Site F"
},
"geometry": {
"coordinates": [
Expand Down
2 changes: 1 addition & 1 deletion server/json_databases/geojson/nav_path.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "LineString", "coordinates": [[-95.08182400577368, 29.56461201871982], [-95.08182407855739, 29.564615595699582], [-95.0818241515221, 29.564619172688516], [-95.08182422464876, 29.564622749685668], [-95.08182429791822, 29.56462632669005], [-95.0818243713114, 29.564629903700705], [-95.08182444480917, 29.564633480716665], [-95.08182451839245, 29.564637057736952], [-95.08182459204211, 29.564640634760607], [-95.08182466573903, 29.564644211786657], [-95.08182473946414, 29.56464778881413], [-95.08182481319831, 29.564651365842064], [-95.08182488692243, 29.56465494286948], [-95.08182496061742, 29.564658519895424], [-95.08182503426414, 29.564662096918916], [-95.0818251078435, 29.564665673938983], [-95.08182518133637, 29.56466925095467], [-95.08182525472368, 29.564672827964994], [-95.08182532798627, 29.564676404968996], [-95.0818254011051, 29.564679981965703], [-95.081825474061, 29.564683558954144], [-95.0818255468349, 29.564687135933358], [-95.08182561942999, 29.564690712903495], [-95.0818256919255, 29.564694289868584], [-95.08182576441702, 29.56469786683347], [-95.08182583700005, 29.564701443802992], [-95.08182590977016, 29.564705020781993], [-95.08182598282288, 29.564708597775326], [-95.08182605625372, 29.564712174787832], [-95.08182613015825, 29.564715751824355], [-95.08182620463198, 29.56471932888973], [-95.08182627977047, 29.564722905988816], [-95.08182635565441, 29.5647264831257], [-95.08182643212297, 29.564730060292227], [-95.08182650881882, 29.56473363747028], [-95.08182658537893, 29.564737214641436], [-95.08182666144026, 29.564740791787305], [-95.08182673663974, 29.56474436888947], [-95.08182681061436, 29.56474794592952], [-95.08182688300107, 29.564751522889043], [-95.08182695343683, 29.56475509974964], [-95.08182702155857, 29.56475867649289], [-95.08182708700363, 29.56476225310042], [-95.08182714979492, 29.564765829573364], [-95.08182721108376, 29.564769405970132], [-95.0818272722268, 29.564772982359504], [-95.08182733458067, 29.564776558810266], [-95.08182739950198, 29.56478013539121], [-95.08182746834736, 29.564783712171142], [-95.08182754247345, 29.564787289218845], [-95.08182762323686, 29.5647908666031], [-95.08182771199424, 29.564794444392717], [-95.08182781010217, 29.56479802265648], [-95.08182791864775, 29.564801601449506], [-95.08182803514887, 29.56480518064594], [-95.08182815459554, 29.56480875999173], [-95.08182827192432, 29.56481233923013], [-95.08182838207175, 29.564815918104376], [-95.08182847997436, 29.564819496357707], [-95.08182856056868, 29.56482307373337], [-95.08182861879123, 29.56482664997461], [-95.08182864957858, 29.56483022482466], [-95.08182864786724, 29.564833798026772], [-95.08182860860946, 29.564837369324984], [-95.08182853289411, 29.564840938774505], [-95.08182843723364, 29.564844507212655], [-95.08182834052532, 29.56484807559766], [-95.08182826166633, 29.564851644887764], [-95.08182821955394, 29.564855216041213], [-95.08182823308537, 29.564858790016228], [-95.08182832115789, 29.564862367771063], [-95.08182850266867, 29.564865950263943], [-95.08182879651503, 29.564869538453117], [-95.08182922159412, 29.564873133296814], [-95.0818297920294, 29.56487673551121], [-95.08183046983862, 29.564880343170305], [-95.08183118496565, 29.564883952721697], [-95.08183186688501, 29.564887560589202], [-95.08183244507121, 29.56489116319662], [-95.0818328489988, 29.564894756967757], [-95.0818330081423, 29.564898338326422], [-95.0818328519762, 29.564901903696416], [-95.08183230997507, 29.564905449501545], [-95.08183131161343, 29.56490897216562], [-95.08182978658554, 29.564912468143458], [-95.08182770548606, 29.56491593966094], [-95.08182512751613, 29.564919401446417], [-95.08182212346608, 29.56492286986349], [-95.08181876412623, 29.56492636127575], [-95.08181512028693, 29.56492989204679], [-95.0818112627385, 29.564933478540212], [-95.08180726227125, 29.564937137119603], [-95.08180318967555, 29.56494088414856], [-95.08179911574169, 29.564944735990675], [-95.08179511126002, 29.564948709009542], [-95.08179124095251, 29.56495281415071], [-95.08178751433995, 29.564957013074043], [-95.0817839114771, 29.564961241131076], [-95.08178041214235, 29.56496543342652], [-95.08177699611404, 29.564969525065095], [-95.08177364317048, 29.564973451151527], [-95.08177033309005, 29.564977146790515], [-95.08176704565109, 29.564980547086797], [-95.08176376063197, 29.564983587145072], [-95.08176045781099, 29.564986202070067], [-95.08175711704644, 29.564988327308097], [-95.08175372671279, 29.56498993471747], [-95.0817502911387, 29.5649910643702], [-95.08174681640673, 29.564991763837142], [-95.08174330859943, 29.564992080689144], [-95.08173977379934, 29.56499206249707], [-95.08173621808902, 29.564991756831763], [-95.081732647551, 29.564991211264086], [-95.08172906826783, 29.564990473364887], [-95.08172548632209, 29.564989590705014], [-95.08172190779628, 29.56498861085533], [-95.08171833826641, 29.564987583247284], [-95.0817147794352, 29.56498657153774], [-95.08171123121762, 29.564985645949978], [-95.08170769351898, 29.56498487674253], [-95.08170416624462, 29.564984334173936], [-95.08170064929985, 29.564984088502747], [-95.08169714258999, 29.564984209987507], [-95.08169364602037, 29.564984768886756], [-95.08169015949633, 29.564985835459044], [-95.08168668292316, 29.56498747996291], [-95.08168321619787, 29.564989771590305], [-95.08167975864504, 29.56499270664391], [-95.08167630865965, 29.564996163014094], [-95.08167286455141, 29.56500000774252], [-95.08166942463008, 29.565004107870852], [-95.08166598720534, 29.565008330440747], [-95.08166255058701, 29.565012542493882], [-95.08165911308478, 29.565016611071904], [-95.08165567300843, 29.565020403216486], [-95.08165222866765, 29.565023785969288], [-95.0816487783722, 29.56502662637197], [-95.08164532048347, 29.56502881169437], [-95.08164185369672, 29.565030360032587], [-95.08163837684008, 29.565031341534706], [-95.081634888742, 29.56503182648216], [-95.08163138823097, 29.56503188515636], [-95.08162787413545, 29.56503158783873], [-95.08162434528391, 29.565031004810706], [-95.08162080050482, 29.565030206353697], [-95.08161723862665, 29.565029262749135], [-95.08161365847785, 29.56502824427844], [-95.08161005898327, 29.56502722103299], [-95.08160644361999, 29.56502625412606], [-95.08160282229261, 29.565025391994403], [-95.08159920539117, 29.565024682117354], [-95.08159560330571, 29.56502417197424], [-95.0815920264263, 29.565023909044402], [-95.08158848514297, 29.56502394080716], [-95.08158498984577, 29.565024314741848], [-95.08158155092472, 29.5650250783278], [-95.08157817876993, 29.565026279044346], [-95.08157488377138, 29.565027964370817], [-95.08157167073625, 29.565030168412143], [-95.08156851378574, 29.56503285176168], [-95.08156537655368, 29.565035949889168], [-95.08156222266479, 29.565039398242554], [-95.08155901574376, 29.5650431322698], [-95.08155571941538, 29.56504708741887], [-95.08155229730436, 29.565051199137706], [-95.08154871303539, 29.565055402874275], [-95.08154493023324, 29.565059634076537], [-95.08154091252261, 29.56506382819244], [-95.08153662561179, 29.565067921660678], [-95.08153210697323, 29.565071885044183], [-95.08152748228805, 29.565075730849575], [-95.08152288265374, 29.565079474159], [-95.08151843916787, 29.565083130054592], [-95.08151428292794, 29.56508671361851], [-95.08151054503149, 29.565090239932882], [-95.08150735657601, 29.565093724079862], [-95.08150484865905, 29.565097181141592], [-95.08150315237813, 29.565100626200223], [-95.08150239883076, 29.565104074337885], [-95.08150268591389, 29.56510753824295], [-95.08150395596772, 29.56511101938805], [-95.08150610581262, 29.56511451596381], [-95.08150903226328, 29.56511802616046], [-95.0815126321343, 29.565121548168204], [-95.08151680224037, 29.56512508017727], [-95.08152143939616, 29.56512862037787], [-95.08152644041627, 29.56513216696023], [-95.0815317021154, 29.56513571811455], [-95.0815371213082, 29.565139272031068], [-95.08154259480935, 29.565142826899983], [-95.08154801943347, 29.56514638091153], [-95.08155329199522, 29.56514993225591], [-95.08155830930929, 29.565153479123353], [-95.08156296819028, 29.56515701970407], [-95.08156716545291, 29.565160552188285], [-95.0815707979118, 29.56516407476621], [-95.0815737623816, 29.56516758562806], [-95.08157595567697, 29.565171082964063], [-95.0815772746126, 29.565174564964423], [-95.0815776160031, 29.56517802981937]]}, "properties": {"name": "Rover Path"}}]}
{"type": "FeatureCollection", "features": [{"type": "Feature", "geometry": {"type": "LineString", "coordinates": [[-95.08164208446321, 29.56472730070558], [-95.08161356493456, 29.56480359988391], [-95.08150795452629, 29.564804298595046], [-95.08140445834957, 29.56480707059295], [-95.08133804093758, 29.564846204597156], [-95.0813149165821, 29.564927794865536], [-95.08131329652393, 29.56496096200629]]}, "properties": {"name": "Rover Path"}}]}
2 changes: 1 addition & 1 deletion server/json_databases/geojson/user_pins.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"Name": "Jonah"}, "geometry": {"coordinates": [-95.08157400428185, 29.565196984797694], "type": "Point"}, "id": 222}]}
{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"Name": "3"}, "geometry": {"coordinates": [-95.081745665659, 29.565204566954293], "type": "Point"}, "id": 333}]}
81 changes: 54 additions & 27 deletions server/mapping.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from types import NoneType
import heapq
import utm
import json
Expand Down Expand Up @@ -38,19 +37,19 @@ def define_areas(grid, areas, weight):
for j in range(start_y, end_y + 1):
grid[i][j] = weight

grass_areas = [
# Increase grass weight more
define_areas(grid, [
('AA0', 'U16'), ('U0', 'T16'), ('T0', 'S13'), ('S0', 'R11'), ('R0', 'Q9'), ('Q0', 'P8'),
('O0', 'O7'), ('N0', 'M7'), ('M0', 'I3'), ('I0', 'G2'), ('G0', 'F2'), ('F0', 'A1'),
('C1', 'A5'), ('A5', 'A14'), ('AA16', 'AA28'), ('Z23', 'X28'), ('H15', 'D22'),
('D18', 'A22'), ('J19', 'H28'), ('L20', 'K24'), ('H25', 'A28'), ('I18', 'H18')
]
define_areas(grid, grass_areas, 3)
], 5)

mound_areas = [
# Avoid mounds
define_areas(grid, [
('M9', 'L17'), ('Q9', 'M18'), ('P8', 'M9'), ('R10', 'Q19'),
('S12', 'R19'), ('T13', 'S19')
]
define_areas(grid, mound_areas, 0)
], 0)

# Graph setup
graph = {}
Expand All @@ -68,7 +67,7 @@ def initialize_graph():
for col in range(grid_width):
coord = index_to_letter(row) + str(col)
distances[coord] = float('inf')
predecessors[coord] = None # Initialize predecessor to None
predecessors[coord] = None

neighbors = {}
if row > 0:
Expand All @@ -80,22 +79,32 @@ def initialize_graph():
if col < grid_width - 1:
neighbors[index_to_letter(row) + str(col + 1)] = grid[row][col]

# Add diagonal neighbors with a length of sqrt(2)
if row > 0 and col > 0:
neighbors[index_to_letter(row - 1) + str(col - 1)] = grid[row][col] * math.sqrt(2)
if row > 0 and col < grid_width - 1:
neighbors[index_to_letter(row - 1) + str(col + 1)] = grid[row][col] * math.sqrt(2)
if row < grid_height - 1 and col > 0:
neighbors[index_to_letter(row + 1) + str(col - 1)] = grid[row][col] * math.sqrt(2)
if row < grid_height - 1 and col < grid_width - 1:
neighbors[index_to_letter(row + 1) + str(col + 1)] = grid[row][col] * math.sqrt(2)
# Add more direct diagonals in the east/west direction
diagonals = [
(row - 1, col - 1), (row - 1, col + 1),
(row + 1, col - 1), (row + 1, col + 1),
(row - 1, col - 2), (row - 1, col + 2),
(row + 1, col - 2), (row + 1, col + 2),
(row - 2, col - 1), (row - 2, col + 1),
(row + 2, col - 1), (row + 2, col + 1),
(row - 2, col), (row + 2, col)
]
for r, c in diagonals:
if 0 <= r < grid_height and 0 <= c < grid_width and grid[row][col] > 0 and grid[r][c] > 0:
distance = math.sqrt((r - row) ** 2 + (c - col) ** 2)
neighbors[index_to_letter(r) + str(c)] = grid[row][col] * distance

graph[coord] = neighbors

initialize_graph()

# Dijkstra's algorithm
def dijkstra(graph, startLat, startLong, endLat, endLong):
# Reset distances and predecessors
for key in distances.keys():
distances[key] = float('inf')
predecessors[key] = None

Start_east, Start_north, _, _ = latlon_to_utm(startLat, startLong)
start = indices_to_grid_coord(Start_east, Start_north)

Expand All @@ -105,18 +114,18 @@ def dijkstra(graph, startLat, startLong, endLat, endLong):
pq = [(0, start)]
visited = set()
distances[start] = 0

while pq:
dist, node = heapq.heappop(pq)

if node == end:
break

if node in visited:
continue

visited.add(node)

for neighbor, weight in graph[node].items():
if distances[node] + weight < distances[neighbor]:
distances[neighbor] = distances[node] + weight
Expand All @@ -133,11 +142,11 @@ def reconstruct_path(startLat, startLong, endLat, endLong):
path = []
node = end

coord_path = []
while node is not None:
path.append(node)
node = predecessors[node]

coord_path = []
for item in path[::-1]:
east, north = grid_coord_to_indices(item)
coord_path.append(utm_to_latlon(east, north))
Expand Down Expand Up @@ -177,7 +186,7 @@ def index_to_letter(index):
return "AA"
else:
return chr(ord('A') + 26 - index - 1)

width_per_box = 100 / 28
height_per_box = 108 / 26

Expand All @@ -199,6 +208,7 @@ def get_shortest_path_geojson(start_lat, start_long, end_lat, end_long):

def convert_to_geojson_feature_collection(coordinates):
smooth_path = smooth_coordinates(coordinates)
reduced_path = reduce_coordinates(smooth_path)
geojson_feature_collection = {
"type": "FeatureCollection",
"features": [
Expand All @@ -207,7 +217,7 @@ def convert_to_geojson_feature_collection(coordinates):
"geometry": {
"type": "LineString",
"coordinates": [
[longitude, latitude] for latitude, longitude in smooth_path
[longitude, latitude] for latitude, longitude in reduced_path
]
},
"properties": {
Expand All @@ -225,11 +235,28 @@ def smooth_coordinates(coordinates):
latitudes = [coord[0] for coord in coordinates]
longitudes = [coord[1] for coord in coordinates]

# Create cubic splines for latitude and longitude
cs_lat = CubicSpline(range(len(latitudes)), latitudes)
cs_lon = CubicSpline(range(len(longitudes)), longitudes)

xs = np.linspace(0, len(latitudes) - 1, len(latitudes) * 10)
# Generate a denser set of points for smoothing
xs = np.linspace(0, len(latitudes) - 1, len(latitudes) * 10) # Adjust factor as needed for smoothing
smoothed_lats = cs_lat(xs)
smoothed_lons = cs_lon(xs)

return list(zip(smoothed_lats, smoothed_lons))
# Downsample the smoothed points to the original number of points
step = len(xs) // len(latitudes)
smoothed_coordinates = [(smoothed_lats[i], smoothed_lons[i]) for i in range(0, len(xs), step)]

return smoothed_coordinates

def reduce_coordinates(coordinates):
if len(coordinates) < 3:
return coordinates # Not enough points to reduce

# Select every third coordinate, but make sure to include the first and last
reduced_path = coordinates[::3]
if reduced_path[-1] != coordinates[-1]:
reduced_path.append(coordinates[-1])
return reduced_path

Loading

0 comments on commit a33af22

Please sign in to comment.