methestrikerx100 commited on
Commit
12c535f
·
verified ·
1 Parent(s): 9f7a8df

Upload Map.py

Browse files
Files changed (1) hide show
  1. Map.py +115 -0
Map.py ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ from PIL import Image
3
+ import numpy as np
4
+ import cv2
5
+ import gradio as gr
6
+ from tensorflow import keras
7
+ from keras.models import load_model
8
+ import folium
9
+
10
+ import re
11
+ def convert_coordinates(coord_str):
12
+ # Regular expression pattern to match the coordinate format
13
+ pattern = r"(\d+)°(\d+)'(\d+(?:\.\d+)?)\"([NS])\s+(\d+)°(\d+)'(\d+(?:\.\d+)?)\"([EW])"
14
+
15
+ match = re.match(pattern, coord_str)
16
+
17
+ if match:
18
+ lat_deg = int(match.group(1))
19
+ lat_min = int(match.group(2))
20
+ lat_sec = float(match.group(3))
21
+ lat_dir = match.group(4)
22
+
23
+ lon_deg = int(match.group(5))
24
+ lon_min = int(match.group(6))
25
+ lon_sec = float(match.group(7))
26
+ lon_dir = match.group(8)
27
+
28
+ # Convert coordinates to decimal format
29
+ lat_decimal = lat_deg + (lat_min / 60) + (lat_sec / 3600)
30
+ lon_decimal = lon_deg + (lon_min / 60) + (lon_sec / 3600)
31
+
32
+ # Apply sign based on direction
33
+ if lat_dir == 'S':
34
+ lat_decimal *= -1
35
+ if lon_dir == 'W':
36
+ lon_decimal *= -1
37
+
38
+ return (lat_decimal, lon_decimal)
39
+ else:
40
+ return None
41
+
42
+ # Example usage
43
+ coordinates = "30°01'48.7\"N 30°58'35.1\"E"
44
+ latitude, longitude = convert_coordinates(coordinates)
45
+ print(f"Latitude: {latitude}, Longitude: {longitude}")
46
+
47
+
48
+ mineral_locations = {
49
+ 'biotite': [
50
+ convert_coordinates("45°26'54.0\"N 75°41'24.0\"W"),
51
+ convert_coordinates("51°03'07.2\"N 114°04'28.8\"W"),
52
+ convert_coordinates("37°47'24.0\"N 122°28'12.0\"W")
53
+ ],
54
+ 'granite': [
55
+ convert_coordinates("40°44'54.0\"N 73°59'08.0\"W"),
56
+ convert_coordinates("34°03'08.0\"S 151°06'24.0\"E"),
57
+ convert_coordinates("55°45'00.0\"N 37°37'00.0\"E")
58
+ ],
59
+ 'olivine': [
60
+ convert_coordinates("19°28'48.0\"N 155°36'00.0\"W"),
61
+ convert_coordinates("38°41'24.0\"N 9°08'24.0\"W"),
62
+ convert_coordinates("46°28'12.0\"N 7°57'36.0\"E")
63
+ ],
64
+ 'plagioclase': [
65
+ convert_coordinates("48°51'24.0\"N 2°21'05.0\"E"),
66
+ convert_coordinates("35°40'48.0\"N 139°41'24.0\"E"),
67
+ convert_coordinates("41°53'24.0\"N 12°29'24.0\"E")
68
+ ],
69
+ 'staurolite': [
70
+ convert_coordinates("43°04'12.0\"N 89°22'48.0\"W"),
71
+ convert_coordinates("47°36'00.0\"N 7°36'00.0\"E"),
72
+ convert_coordinates("51°30'00.0\"N 0°07'48.0\"W")
73
+ ]
74
+ }
75
+
76
+
77
+
78
+ import folium
79
+
80
+ def plot_mineral_locations(mineral_locations):
81
+ map = folium.Map(location=[0, 0], zoom_start=2)
82
+
83
+ for mineral, locations in mineral_locations.items():
84
+ for location in locations:
85
+ lat, lon = location
86
+ folium.Marker(
87
+ location=[lat, lon],
88
+ popup=mineral,
89
+ icon=folium.Icon(color='green')
90
+ ).add_to(map)
91
+
92
+ return map
93
+
94
+
95
+ def generate_mineral_map(mineral_name):
96
+ # Create a map object
97
+ mineral_map = folium.Map(location=[0, 0], zoom_start=2)
98
+
99
+ # Get the locations for the specified mineral
100
+ locations = mineral_locations.get(mineral_name, [])
101
+
102
+ # Add markers for the mineral locations
103
+ for location in locations:
104
+ lat, lon = location
105
+ folium.Marker(
106
+ location=[lat, lon],
107
+ popup=mineral_name,
108
+ icon=folium.Icon(color='green')
109
+ ).add_to(mineral_map)
110
+
111
+ return mineral_map
112
+
113
+
114
+
115
+