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')
data = f.read()
xml = etree.fromstring(data)
- gpx = pygpx.GPX()
+ gpx = GPX()
gpx.ReadTree(xml)
bbox = gpx.bound_box()
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()