modification en projection mercator pour la latitude

This commit is contained in:
2025-05-20 16:01:20 +00:00
parent 11b47b1549
commit c05ee25923
2 changed files with 39 additions and 17 deletions

View File

@@ -7,6 +7,7 @@ import os
import platform import platform
import subprocess import subprocess
import configparser import configparser
from math import log, tan, radians, pi, degrees, atan, sinh
from downloader import CopernicusDownloader from downloader import CopernicusDownloader
@@ -220,38 +221,57 @@ class MapSelector:
pass pass
def xy_from_latlon(self, lat, lon): def xy_from_latlon(self, lat, lon):
lat_min, lat_max = self.config.getfloat('map','map_lat_start'), self.config.getfloat('map','map_lat_end') lat_min = self.config.getfloat('map', 'map_lat_start')
lon_min, lon_max = self.config.getfloat('map','map_lon_start'), self.config.getfloat('map','map_lon_end') lat_max = self.config.getfloat('map', 'map_lat_end')
# print(f"xy_from_latlon dbg coord = {lat_min}-{lat_max}-{lon_min}-{lon_max}") lon_min = self.config.getfloat('map', 'map_lon_start')
lon_max = self.config.getfloat('map', 'map_lon_end')
canvas_w = self.canvas.winfo_width() canvas_w = self.canvas.winfo_width()
canvas_h = self.canvas.winfo_height() canvas_h = self.canvas.winfo_height()
print(f"canvas = {canvas_w} {canvas_h} scale = {self.scale} offset = {self.offset_x} {self.offset_y}") print(f"canvas = {canvas_w} {canvas_h} scale = {self.scale} offset = {self.offset_x} {self.offset_y}")
x = (lon - lon_min) / (lon_max - lon_min) * self.scale * self.original_img.width + self.offset_x # Longitude (linéaire)
y = (lat_max - lat) / (lat_max - lat_min) * self.scale * self.original_img.height + self.offset_y x_norm = (lon - lon_min) / (lon_max - lon_min)
x = x_norm * self.scale * self.original_img.width + self.offset_x
# Latitude (projection Mercator)
mercator_min = log(tan(pi / 4 + radians(lat_min) / 2)) # Mercator
mercator_max = log(tan(pi / 4 + radians(lat_max) / 2)) # Mercator
mercator_lat = log(tan(pi / 4 + radians(lat) / 2)) # Mercator
y_norm = (mercator_max - mercator_lat) / (mercator_max - mercator_min)
y = y_norm * self.scale * self.original_img.height + self.offset_y
print(f"xy_from_latlon : {x} - {y}") print(f"xy_from_latlon : {x} - {y}")
return x, y return x, y
def latlon_from_xy(self, x, y): def latlon_from_xy(self, x, y):
# Coordonnées géographiques de la carte # Coordonnées géographiques de la carte
lat_min, lat_max = self.config.getfloat('map','map_lat_start'), self.config.getfloat('map','map_lat_end') lat_min = self.config.getfloat('map', 'map_lat_start')
lon_min, lon_max = self.config.getfloat('map','map_lon_start'), self.config.getfloat('map','map_lon_end') lat_max = self.config.getfloat('map', 'map_lat_end')
lon_min = self.config.getfloat('map', 'map_lon_start')
lon_max = self.config.getfloat('map', 'map_lon_end')
print(f"latlon_from_xy dbg coord = {lat_min}-{lat_max}-{lon_min}-{lon_max}") print(f"latlon_from_xy dbg coord = {lat_min}-{lat_max}-{lon_min}-{lon_max}")
# Calculer la position relative dans limage (sans offset/zoom)
# Calculer la position relative sur l'image
img_x = (x - self.offset_x) / self.scale img_x = (x - self.offset_x) / self.scale
img_y = (y - self.offset_y) / self.scale img_y = (y - self.offset_y) / self.scale
# Vérifier si le clic est dans l'image affichée
if 0 <= img_x <= self.original_img.width and 0 <= img_y <= self.original_img.height: if 0 <= img_x <= self.original_img.width and 0 <= img_y <= self.original_img.height:
rel_x = img_x / self.original_img.width rel_x = img_x / self.original_img.width
rel_y = img_y / self.original_img.height rel_y = img_y / self.original_img.height
lat = lat_max - rel_y * (lat_max - lat_min)
# Longitude : linéaire
lon = lon_min + rel_x * (lon_max - lon_min) lon = lon_min + rel_x * (lon_max - lon_min)
# Latitude : projection inverse de Mercator
merc_min = log(tan(pi / 4 + radians(lat_min) / 2)) # Mercator
merc_max = log(tan(pi / 4 + radians(lat_max) / 2)) # Mercator
merc_y = merc_max - rel_y * (merc_max - merc_min)
lat = degrees(atan(sinh(merc_y))) # Mercator Inverse
print(f"latlon_from_xy : {lat} - {lon}") print(f"latlon_from_xy : {lat} - {lon}")
return lat, lon return lat, lon
else: else:

2
requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
pillow
copernicusmarine