File size: 3,465 Bytes
12c535f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import tensorflow as tf
from PIL import Image
import numpy as np
import cv2
import gradio as gr
from tensorflow import keras
from keras.models import load_model
import folium

import re
def convert_coordinates(coord_str):
    # Regular expression pattern to match the coordinate format
    pattern = r"(\d+)°(\d+)'(\d+(?:\.\d+)?)\"([NS])\s+(\d+)°(\d+)'(\d+(?:\.\d+)?)\"([EW])"

    match = re.match(pattern, coord_str)

    if match:
        lat_deg = int(match.group(1))
        lat_min = int(match.group(2))
        lat_sec = float(match.group(3))
        lat_dir = match.group(4)

        lon_deg = int(match.group(5))
        lon_min = int(match.group(6))
        lon_sec = float(match.group(7))
        lon_dir = match.group(8)

        # Convert coordinates to decimal format
        lat_decimal = lat_deg + (lat_min / 60) + (lat_sec / 3600)
        lon_decimal = lon_deg + (lon_min / 60) + (lon_sec / 3600)

        # Apply sign based on direction
        if lat_dir == 'S':
            lat_decimal *= -1
        if lon_dir == 'W':
            lon_decimal *= -1

        return (lat_decimal, lon_decimal)
    else:
        return None

# Example usage
coordinates = "30°01'48.7\"N 30°58'35.1\"E"
latitude, longitude = convert_coordinates(coordinates)
print(f"Latitude: {latitude}, Longitude: {longitude}")


mineral_locations = {
    'biotite': [
        convert_coordinates("45°26'54.0\"N 75°41'24.0\"W"),
        convert_coordinates("51°03'07.2\"N 114°04'28.8\"W"),
        convert_coordinates("37°47'24.0\"N 122°28'12.0\"W")
    ],
    'granite': [
        convert_coordinates("40°44'54.0\"N 73°59'08.0\"W"),
        convert_coordinates("34°03'08.0\"S 151°06'24.0\"E"),
        convert_coordinates("55°45'00.0\"N 37°37'00.0\"E")
    ],
    'olivine': [
        convert_coordinates("19°28'48.0\"N 155°36'00.0\"W"),
        convert_coordinates("38°41'24.0\"N 9°08'24.0\"W"),
        convert_coordinates("46°28'12.0\"N 7°57'36.0\"E")
    ],
    'plagioclase': [
        convert_coordinates("48°51'24.0\"N 2°21'05.0\"E"),
        convert_coordinates("35°40'48.0\"N 139°41'24.0\"E"),
        convert_coordinates("41°53'24.0\"N 12°29'24.0\"E")
    ],
    'staurolite': [
        convert_coordinates("43°04'12.0\"N 89°22'48.0\"W"),
        convert_coordinates("47°36'00.0\"N 7°36'00.0\"E"),
        convert_coordinates("51°30'00.0\"N 0°07'48.0\"W")
    ]
}



import folium

def plot_mineral_locations(mineral_locations):
    map = folium.Map(location=[0, 0], zoom_start=2)

    for mineral, locations in mineral_locations.items():
        for location in locations:
            lat, lon = location
            folium.Marker(
                location=[lat, lon],
                popup=mineral,
                icon=folium.Icon(color='green')
            ).add_to(map)

    return map


def generate_mineral_map(mineral_name):
    # Create a map object
    mineral_map = folium.Map(location=[0, 0], zoom_start=2)

    # Get the locations for the specified mineral
    locations = mineral_locations.get(mineral_name, [])

    # Add markers for the mineral locations
    for location in locations:
        lat, lon = location
        folium.Marker(
            location=[lat, lon],
            popup=mineral_name,
            icon=folium.Icon(color='green')
        ).add_to(mineral_map)

    return mineral_map