From: Roman Bazalevskiy Date: Wed, 1 Nov 2023 08:14:19 +0000 (+0300) Subject: В Ubuntu 22.04 сломали проекции в Mapnik, приходится использовать альтернативный... X-Git-Url: https://git.rvb.name/pyrungps.git/commitdiff_plain В Ubuntu 22.04 сломали проекции в Mapnik, приходится использовать альтернативный вариант --- diff --git a/pyrungps/generate_image.py b/pyrungps/generate_image.py index 6e1fa3a..4a75e11 100644 --- a/pyrungps/generate_image.py +++ b/pyrungps/generate_image.py @@ -9,14 +9,16 @@ from optparse import OptionParser from pprint import pprint -import pyrungps.pygpx +from pyrungps.pygpx import GPX + +from pyproj import Transformer # Set up projections # spherical mercator (most common target map projection of osm data imported with osm2pgsql) -merc = 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') +#merc = 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') # long/lat in degrees, aka ESPG:4326 and "WGS 84" -longlat = mapnik.Projection('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs') +#longlat = mapnik.Projection('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs') # can also be constructed as: #longlat = mapnik.Projection('+init=epsg:4326') @@ -31,7 +33,7 @@ def render_map(mapfile,map_uri,gpx_file,imgx,imgy): data = f.read() xml = etree.fromstring(data) - gpx = pygpx.GPX() + gpx = GPX() gpx.ReadTree(xml) bbox = gpx.bound_box() @@ -51,14 +53,24 @@ def render_map(mapfile,map_uri,gpx_file,imgx,imgy): m.background = mapnik.Color('rgb(255,255,255)') # ensure the target map projection is mercator - m.srs = merc.params() + #m.srs = merc.params() bbox = mapnik.Box2d(*bounds) pprint(bbox) + + minlat = bbox.miny + maxlat = bbox.maxy + minlon = bbox.minx + maxlon = bbox.maxx - transform = mapnik.ProjTransform(longlat,merc) - merc_bbox = transform.forward(bbox) + print(minlat,maxlat,minlon,maxlon) + + transformer = Transformer.from_crs("EPSG:4326", "EPSG:3857", always_xy=True) + minP=transformer.transform(minlon,minlat) + maxP=transformer.transform(maxlon,maxlat) + + merc_bbox = mapnik.Box2d(minP[0],minP[1],maxP[0],maxP[1]) m.zoom_to_box(merc_bbox) style = mapnik.Style()