[OSM-dev] Mapnik scaling and shieldsymbolizer
Artem Pavlenko
artem at mapnik.org
Wed Jul 11 00:33:22 BST 2007
On 10 Jul 2007, at 21:52, Andy Allan wrote:
> Hi All,
>
> Does anyone have a conversion scale for google zoom <=> mapnik
> maxScaleDenominator? I'm making a slippy map, and when I want to make
> something appear on e.g. zoom 7 I'm hunting around looking for the
> correct values.
>
I guess you're after these numbers (zoom level - scale denominator)
1 279541132.014
2 139770566.007
3 69885283.0036
4 34942641.5018
5 17471320.7509
6 8735660.37545
7 4367830.18772
8 2183915.09386
9 1091957.54693
10 545978.773466
11 272989.386733
12 136494.693366
13 68247.3466832
14 34123.6733416
15 17061.8366708
16 8530.91833539
17 4265.4591677
18 2132.72958385
Here is modified generate_tiles.py to generate_scales instead.
from math import pi,cos,sin,log,exp,atan
import sys, os
DEG_TO_RAD = pi/180
RAD_TO_DEG = 180/pi
def minmax (a,b,c):
a = max(a,b)
a = min(a,c)
return a
class GoogleProjection:
def __init__(self,levels=18):
self.Bc = []
self.Cc = []
self.zc = []
self.Ac = []
c = 256
for d in range(0,levels):
e = c/2;
self.Bc.append(c/360.0)
self.Cc.append(c/(2 * pi))
self.zc.append((e,e))
self.Ac.append(c)
c *= 2
def fromLLtoPixel(self,ll,zoom):
d = self.zc[zoom]
e = round(d[0] + ll[0] * self.Bc[zoom])
f = minmax(sin(DEG_TO_RAD * ll[1]),-0.9999,0.9999)
g = round(d[1] + 0.5*log((1+f)/(1-f))*-self.Cc[zoom])
return (e,g)
def fromPixelToLL(self,px,zoom):
e = self.zc[zoom]
f = (px[0] - e[0])/self.Bc[zoom]
g = (px[1] - e[1])/-self.Cc[zoom]
h = RAD_TO_DEG * ( 2 * atan(exp(g)) - 0.5 * pi)
return (f,h)
from mapnik import *
def generate_scales(minZoom=1,maxZoom=18):
gprj = GoogleProjection(maxZoom+1)
m = Map(256,256)
prj = Projection("+proj=merc +datum=WGS84")
for z in range(minZoom,maxZoom + 1):
p0 = gprj.fromPixelToLL( (0,0),z)
p1 = gprj.fromPixelToLL( (256,256),z)
c0 = prj.forward(Coord(p0[0],p0[1]))
c1 = prj.forward(Coord(p1[0],p1[1]))
bbox = Envelope(c0.x,c0.y,c1.x,c1.y)
m.zoom_to_box(bbox)
print z,scale_denominator(m,False)
if __name__ == "__main__":
generate_scales(1, 18)
> Also, has anyone got experience of the shieldsymbolizer (used for road
> references)? I'm trying to space out the shields so that you can see
> the road below them - when the ways are short and the zoom is low,
> there's practically no gap between the shields. I'd ideally like to
> control the spacing between shields with equal values, but increasing
> the gap between all shields would otherwise be nice.
>
There is 'minimum_distance' property in the latest trunk which I
haven't tried, yet : http://trac.mapnik.org/changeset/490
It should do the trick. Let me know if it works for you.
> Cheers,
> Andy
>
Cheers,
Artem
> _______________________________________________
> dev mailing list
> dev at openstreetmap.org
> http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/dev
>
Artem Pavlenko
http://mapnik.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/dev/attachments/20070711/45cdc66b/attachment.html>
More information about the dev
mailing list