From 558691451db4f029698b996d7df8c8cf272b3b8b Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 14 Jul 2022 09:41:38 +0100 Subject: [PATCH] Use pyproj to project coordinates Ubuntu 22.04 builds mapnik without proj support. --- cookbooks/tile/recipes/default.rb | 1 + cookbooks/tile/templates/default/export.erb | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cookbooks/tile/recipes/default.rb b/cookbooks/tile/recipes/default.rb index 40039b314..b49223225 100644 --- a/cookbooks/tile/recipes/default.rb +++ b/cookbooks/tile/recipes/default.rb @@ -157,6 +157,7 @@ end package %w[ python3-cairo python3-mapnik + python3-pyproj python3-setuptools ] diff --git a/cookbooks/tile/templates/default/export.erb b/cookbooks/tile/templates/default/export.erb index b8075a17a..8fa4672b9 100644 --- a/cookbooks/tile/templates/default/export.erb +++ b/cookbooks/tile/templates/default/export.erb @@ -7,6 +7,7 @@ import http.cookies import mapnik import os import pyotp +import pyproj import resource import shutil import signal @@ -108,7 +109,7 @@ elif "format" not in form: output_error("No format specified") else: # Create projection object - prj = mapnik.Projection("+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over"); + transformer = pyproj.Transformer.from_crs("EPSG:4326", "EPSG:3857", always_xy=True) # Get the bounds of the area to render bbox = [float(x) for x in form.getvalue("bbox").split(",")] @@ -118,7 +119,8 @@ else: output_error("Invalid bounding box") else: # Project the bounds to the map projection - bbox = mapnik.forward_(mapnik.Box2d(*bbox), prj) + bbox = mapnik.Box2d(*transformer.transform(bbox[0], bbox[1]), + *transformer.transform(bbox[2], bbox[3])) # Get the style to use style = form.getvalue("style", "default") -- 2.39.5