Skip to content

Commit

Permalink
Always write coords in tiles.geojson in EPSG:4326 for legacy reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
dmannarino committed Dec 3, 2024
1 parent a4f5124 commit a487993
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions batch/python/tiles_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@
import math
import subprocess
from concurrent.futures import ProcessPoolExecutor, as_completed
from typing import List, Dict, Any, Optional
from typing import List, Dict, Any, Tuple

import pyproj
from geojson import Feature, FeatureCollection
from pyproj import CRS, Transformer
from shapely.geometry import Polygon
from shapely.ops import unary_union


def to_wgs84(crs: CRS, x: float, y: float) -> Tuple[float, float]:
transformer = Transformer.from_crs(
crs, CRS.from_epsg(4326), always_xy=True
)
return transformer.transform(x, y)


def run_gdalinfo(file_path: str) -> Dict[str, Any]:
"""Run gdalinfo and parse the output as JSON."""
try:
Expand Down Expand Up @@ -93,14 +103,14 @@ def generate_geojson_parallel(geo_tiffs: List[str], tiles_output: str, extent_ou
try:
metadata = future.result()
extent = metadata["extent"]

crs = CRS.from_string(metadata["crs"])
# Create a Polygon from the extent
polygon_coords = [
[extent[0], extent[1]],
[extent[0], extent[3]],
[extent[2], extent[3]],
[extent[2], extent[1]],
[extent[0], extent[1]],
[*to_wgs84(crs, extent[0], extent[1])],
[*to_wgs84(crs, extent[0], extent[3])],
[*to_wgs84(crs, extent[2], extent[3])],
[*to_wgs84(crs, extent[2], extent[1])],
[*to_wgs84(crs, extent[0], extent[1])],
]
polygon = Polygon(polygon_coords)

Expand Down

0 comments on commit a487993

Please sign in to comment.