From 69331b34dff92d2544e71327c319c1ff9e9b9b5e Mon Sep 17 00:00:00 2001 From: Roman Bazalevskiy Date: Wed, 1 Nov 2023 11:14:19 +0300 Subject: [PATCH 1/1] =?utf8?q?=D0=92=20Ubuntu=2022.04=20=D1=81=D0=BB=D0=BE?= =?utf8?q?=D0=BC=D0=B0=D0=BB=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=86?= =?utf8?q?=D0=B8=D0=B8=20=D0=B2=20Mapnik,=20=D0=BF=D1=80=D0=B8=D1=85=D0=BE?= =?utf8?q?=D0=B4=D0=B8=D1=82=D1=81=D1=8F=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB?= =?utf8?q?=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D0=B0=D0=BB=D1=8C?= =?utf8?q?=D1=82=D0=B5=D1=80=D0=BD=D0=B0=D1=82=D0=B8=D0=B2=D0=BD=D1=8B?= =?utf8?q?=D0=B9=20=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- pyrungps/generate_image.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) 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() -- 2.34.1