Spaces:
Running
Running
feat: use DMS coordinate format (Degrees, Minutes, Seconds)
Browse files- create_map_poster.py +34 -7
create_map_poster.py
CHANGED
|
@@ -250,6 +250,34 @@ def has_chinese(text):
|
|
| 250 |
return False
|
| 251 |
|
| 252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
def get_coordinates(city, country, parent=None):
|
| 254 |
"""
|
| 255 |
Fetches coordinates for a given city and country.
|
|
@@ -603,13 +631,12 @@ def create_poster(
|
|
| 603 |
# Only show if there is at least a title or subtitle, or if specifically desired
|
| 604 |
if display_city or display_country:
|
| 605 |
lat, lon = point
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
coords_text = coords_text.replace("E", "W")
|
| 613 |
|
| 614 |
ax.text(
|
| 615 |
0.5,
|
|
|
|
| 250 |
return False
|
| 251 |
|
| 252 |
|
| 253 |
+
def decimal_to_dms(decimal_deg, is_lat=True, lang="cn"):
|
| 254 |
+
"""
|
| 255 |
+
Convert decimal degrees to Degrees, Minutes, Seconds format.
|
| 256 |
+
Example: 东经E:113°56′9.30″ 北纬N:22°28′48.07″
|
| 257 |
+
"""
|
| 258 |
+
abs_deg = abs(decimal_deg)
|
| 259 |
+
degrees = int(abs_deg)
|
| 260 |
+
minutes_float = (abs_deg - degrees) * 60
|
| 261 |
+
minutes = int(minutes_float)
|
| 262 |
+
seconds = (minutes_float - minutes) * 60
|
| 263 |
+
|
| 264 |
+
if is_lat:
|
| 265 |
+
suffix = "N" if decimal_deg >= 0 else "S"
|
| 266 |
+
label = "北纬" if decimal_deg >= 0 else "南纬"
|
| 267 |
+
if lang != "cn":
|
| 268 |
+
label = "Lat "
|
| 269 |
+
else:
|
| 270 |
+
suffix = "E" if decimal_deg >= 0 else "W"
|
| 271 |
+
label = "东经" if decimal_deg >= 0 else "西经"
|
| 272 |
+
if lang != "cn":
|
| 273 |
+
label = "Long "
|
| 274 |
+
|
| 275 |
+
if lang == "cn":
|
| 276 |
+
return f"{label}{suffix}:{degrees}°{minutes}′{seconds:.2f}″"
|
| 277 |
+
else:
|
| 278 |
+
return f"{label}{suffix}: {degrees}°{minutes}'{seconds:.2f}\""
|
| 279 |
+
|
| 280 |
+
|
| 281 |
def get_coordinates(city, country, parent=None):
|
| 282 |
"""
|
| 283 |
Fetches coordinates for a given city and country.
|
|
|
|
| 631 |
# Only show if there is at least a title or subtitle, or if specifically desired
|
| 632 |
if display_city or display_country:
|
| 633 |
lat, lon = point
|
| 634 |
+
lang_type = "cn" if is_chinese else "en"
|
| 635 |
+
|
| 636 |
+
dms_lon = decimal_to_dms(lon, is_lat=False, lang=lang_type)
|
| 637 |
+
dms_lat = decimal_to_dms(lat, is_lat=True, lang=lang_type)
|
| 638 |
+
|
| 639 |
+
coords_text = f"{dms_lon} {dms_lat}"
|
|
|
|
| 640 |
|
| 641 |
ax.text(
|
| 642 |
0.5,
|