Last active
March 20, 2018 17:45
-
-
Save oberhamsi/86515a57261247fd53131f8cbfaf371f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# source: http://mapnik-users.berlios.narkive.com/pN0x8SPC/animation-examples#post3 | |
from mapnik import * | |
import math, sys, os | |
if __name__ == "__main__": | |
try: | |
mapfile = os.environ['MAPNIK_MAP_FILE'] | |
except KeyError: | |
mapfile = "osm.xml" | |
map_uri = "image.png" | |
#--------------------------------------------------- | |
# Change this to the bounding box you want | |
# | |
ll_start = (-6.5, 49.5, 2.1, 59) | |
ll_finish = (-1.227, 50.812, -1.222, 50.815) | |
ll = [-180.0, -90.0, 180.0, 90.0] | |
#--------------------------------------------------- | |
NumFrames = 600 | |
z = 15 | |
f = 1.0 | |
imgx = 1280 | |
imgy = 720 | |
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") | |
for i in range(1,NumFrames+1): | |
for j in range(0,4): | |
if i == 1: | |
ll[j] = ll_start[j] | |
else: | |
ll[j] = ll_finish[j]+((ll[j]-ll_finish[j])*f) | |
if f > 0.98: | |
f = f - 0.0001 | |
c0 = prj.forward(Coord(ll[0],ll[1])) | |
c1 = prj.forward(Coord(ll[2],ll[3])) | |
bbox = Envelope(c0.x,c0.y,c1.x,c1.y) | |
m.zoom_to_box(bbox) | |
print "About to render frame %d at %0.3f, %0.3f, %0.3f, %0.3f" | |
% (i, ll[0], ll[1], ll[2], ll[3]) | |
map_uri = "frames2/image%03d.png" % (i) | |
render_to_file(m, map_uri, 'png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment