Last active
August 18, 2023 15:00
-
-
Save maxcollombin/174054bd407104830247c9d99845db34 to your computer and use it in GitHub Desktop.
This script allows to convert a bounding box from WGS84 to EPSG:2056.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
BBOX converter | |
This script allows to convert a bounding box from WGS84 to EPSG:2056. | |
Author: [Maxime Collombin] | |
Date: [14/08/2023] | |
""" | |
# -*- coding: utf-8 -*- | |
import pyproj | |
def convert_bbox_wgs84_to_epsg2056(min_lon, min_lat, max_lon, max_lat): | |
# Define the source and target projections | |
src_proj = pyproj.Proj(init='EPSG:4326') | |
target_proj = pyproj.Proj(init='EPSG:2056') | |
# Convert bounding box corners | |
min_x, min_y = pyproj.transform(src_proj, target_proj, min_lon, min_lat) | |
max_x, max_y = pyproj.transform(src_proj, target_proj, max_lon, max_lat) | |
# Return the converted bounding box coordinates | |
return min_x, min_y, max_x, max_y | |
# Define the WGS84 bounding box coordinates (min_lon, min_lat, max_lon, max_lat) | |
wgs84_bbox = (5.140242, 45.398181, 11.47757, 48.230651) | |
# Convert the bounding box to EPSG:2056 | |
epsg2056_bbox = convert_bbox_wgs84_to_epsg2056(*wgs84_bbox) | |
print("EPSG:2056 Bounding Box:", epsg2056_bbox) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment