Beispiel #1
0
#!/usr/bin/env python

from mapnik import Coord, Envelope, Projection, forward_, inverse_
import sys

if (len(sys.argv) < 2):
    print sys.argv[0] + " <epsg:code> <Coord or Envelope>"
    sys.exit(1)
else:
    epsg = sys.argv[1]
    p = Projection('+init=%s' % epsg)
    coord = map(float,sys.argv[2].split(','))
    if len(coord) == 2:
        long_lat = Coord(*coord)
        print 'Forwarded:',
        print p.forward(long_lat)
        print
        print 'Inversed:',
        print p.inverse(long_lat)      
    elif len(coord) == 4:
        extent = Envelope(*coord)
        print 'Forwarded:',
        print forward_(extent,p)
        print
        print 'Inversed:',
        print inverse_(extent,p)
Beispiel #2
0
    logging.info("range: bottomleft(%s, %s), topright(%s, %s)" % (west, lat - lat_half, east, lat + lat_half))
    return west, south, east, north

if __name__ == "__main__":
    mapfile = "my_styles/mapnik2normal.xml"

    map_uri = "map.png"

    lat = 49.25
    lon = 7.0
    if len(sys.argv) == 2:
        zoom = int(sys.argv[1])
    else:
        zoom = 13
    imgx = 500
    imgy = 400

    ll = center_to_bbox(lat, lon, zoom, imgx, imgy)
    m = Map(imgx, imgy)
    load_map(m, mapfile)
    prj = 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")
    c0 = prj.forward(Coord(ll[0], ll[1]))
    c1 = prj.forward(Coord(ll[2], ll[3]))
    bbox = Box2d(c0.x, c0.y, c1.x, c1.y)
    m.zoom_to_box(bbox)
    im = Image(imgx, imgy)
    render(m, im)
    view = im.view(0, 0, imgx, imgy)  # x,y,width,height
    view.save(map_uri, 'png')
Beispiel #3
0

if __name__ == "__main__":
    mapfile = "my_styles/mapnik2normal.xml"

    map_uri = "map.png"

    lat = 49.25
    lon = 7.0
    if len(sys.argv) == 2:
        zoom = int(sys.argv[1])
    else:
        zoom = 13
    imgx = 500
    imgy = 400

    ll = center_to_bbox(lat, lon, zoom, imgx, imgy)
    m = Map(imgx, imgy)
    load_map(m, mapfile)
    prj = 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")
    c0 = prj.forward(Coord(ll[0], ll[1]))
    c1 = prj.forward(Coord(ll[2], ll[3]))
    bbox = Box2d(c0.x, c0.y, c1.x, c1.y)
    m.zoom_to_box(bbox)
    im = Image(imgx, imgy)
    render(m, im)
    view = im.view(0, 0, imgx, imgy)  # x,y,width,height
    view.save(map_uri, 'png')
Beispiel #4
0
#!/usr/bin/env python

from mapnik import Coord, Envelope, Projection, forward_, inverse_
import sys

if (len(sys.argv) < 2):
    print sys.argv[0] + " <epsg:code> <Coord or Envelope>"
    sys.exit(1)
else:
    epsg = sys.argv[1]
    p = Projection('+init=%s' % epsg)
    coord = map(float, sys.argv[2].split(','))
    if len(coord) == 2:
        long_lat = Coord(*coord)
        print 'Forwarded:',
        print p.forward(long_lat)
        print
        print 'Inversed:',
        print p.inverse(long_lat)
    elif len(coord) == 4:
        extent = Envelope(*coord)
        print 'Forwarded:',
        print forward_(extent, p)
        print
        print 'Inversed:',
        print inverse_(extent, p)