Last active
September 29, 2015 17:38
-
-
Save sunng87/1639915 to your computer and use it in GitHub Desktop.
OSM Nanjing: Year of Edits
This file contains hidden or 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
<Map background-color="#232323" minimum-version="0.7.2" srs="+proj=latlong +datum=WGS84"> | |
<Style name="style-by-timestamp"> | |
<Rule> | |
<Filter>[timestamp] = '2012'</Filter> | |
<LineSymbolizer stroke="#95a7ed" stroke-width="1" /></Rule> | |
<Rule> | |
<ElseFilter /> | |
<LineSymbolizer stroke="#9090A0" stroke-width="1" /></Rule> | |
</Style> | |
<Layer name="all" srs="+proj=latlong +datum=WGS84" status="on"> | |
<StyleName>style-by-timestamp</StyleName> | |
<Datasource> | |
<Parameter name="type">osm</Parameter> | |
<Parameter name="file">map-nanjing-t.osm</Parameter> | |
</Datasource> | |
</Layer> | |
</Map> |
This file contains hidden or 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/env python2 | |
from mapnik import * | |
mapfile = 'mapnik-nanjing-edits.xml' | |
map_output = 'map-nanjing-edits.png' | |
m = Map(480, 480) | |
load_map(m, mapfile) | |
bbox=(Envelope(118.595,31.872,118.982,32.26)) | |
m.zoom_to_box(bbox) | |
print "Scale = " , m.scale() | |
render_to_file(m, map_output) | |
This file contains hidden or 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/env python2 | |
# -*- coding: utf-8 -*- | |
from xml.dom.minidom import parse | |
import codecs | |
dom1 = parse('map-nanjing.osm') | |
ways = dom1.getElementsByTagName('way') | |
for w in ways: | |
t = w.getAttribute('timestamp')[:4] | |
nt = dom1.createElement('tag') | |
nt.setAttribute('k','timestamp') | |
nt.setAttribute('v',t) | |
w.appendChild(nt) | |
with codecs.open('map-nanjing-t.osm','w', 'utf-8') as out: | |
dom1.writexml(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment