projects
/
pyrungps.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
45d99b6
)
В Ubuntu 22.04 сломали проекции в Mapnik, приходится использовать альтернативный...
master
author
Roman Bazalevskiy
<rvb@rvb.name>
Wed, 1 Nov 2023 08:14:19 +0000
(11:14 +0300)
committer
Roman Bazalevskiy
<rvb@rvb.name>
Wed, 1 Nov 2023 08:14:19 +0000
(11:14 +0300)
pyrungps/generate_image.py
patch
|
blob
|
history
diff --git
a/pyrungps/generate_image.py
b/pyrungps/generate_image.py
index 6e1fa3a3883b47dce8a7534239c0d60ae53717e1..4a75e114324cea7f0897bf799bb3c91042f73f83 100644
(file)
--- a/
pyrungps/generate_image.py
+++ b/
pyrungps/generate_image.py
@@
-9,14
+9,16
@@
from optparse import OptionParser
from pprint import pprint
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)
# 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"
# 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')
# 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)
data = f.read()
xml = etree.fromstring(data)
- gpx =
pygpx.
GPX()
+ gpx = GPX()
gpx.ReadTree(xml)
bbox = gpx.bound_box()
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.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)
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()
m.zoom_to_box(merc_bbox)
style = mapnik.Style()