Created
September 19, 2010 23:25
-
-
Save timwaters/587215 to your computer and use it in GitHub Desktop.
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
<?xml version="1.0" ?><Map bgcolor="rgb(255,255,255)" srs="+init=epsg:4326"> | |
<Style name="NYC_Structures4326_style"> | |
<Rule> | |
<PolygonSymbolizer> | |
<CssParameter name="fill">rgb(78,110,187)</CssParameter> | |
<CssParameter name="gamma">0.7</CssParameter> | |
</PolygonSymbolizer> | |
<LineSymbolizer> | |
<CssParameter name="stroke-width">0.96</CssParameter> | |
</LineSymbolizer> | |
</Rule> | |
</Style> | |
<Layer name="NYC_Structures4326" srs="+init=epsg:4326"> | |
<StyleName>NYC_Structures4326_style</StyleName> | |
<Datasource> | |
<Parameter name="file">4326/NYC_Structures4326.shp</Parameter> | |
<Parameter name="type">shape</Parameter> | |
</Datasource> | |
</Layer> | |
</Map> | |
#!/usr/bin/python | |
# | |
# Generates a single large PNG image for a UK bounding box | |
# Tweak the lat/lon bounding box (ll) and image dimensions | |
# to get an image of arbitrary size. | |
# | |
# To use this script you must first have installed mapnik | |
# and imported a planet file into a Postgres DB using | |
# osm2pgsql. | |
# | |
# Note that mapnik renders data differently depending on | |
# the size of image. More detail appears as the image size | |
# increases but note that the text is rendered at a constant | |
# pixel size so will appear smaller on a large image. | |
import mapnik | |
import sys, os | |
if __name__ == "__main__": | |
mapfile = "mapnik.xml" | |
map_uri = "image.png" | |
#--------------------------------------------------- | |
# Change this to the bounding box you want | |
# | |
#ll = (40.65, -73.96, 40.70, -73.96) | |
ll = (-74.46, 40.47, -73.56, 40.906) | |
#ll = (-180, -90, 180, 90) | |
#--------------------------------------------------- | |
z = 9 | |
imgx = 600 * z | |
imgy = 600 * z | |
m = mapnik.Map(imgx,imgy) | |
mapnik.load_map(m,mapfile) | |
prj = 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") | |
c0 = prj.forward(mapnik.Coord(ll[0],ll[1])) | |
c1 = prj.forward(mapnik.Coord(ll[2],ll[3])) | |
#if hasattr(mapnik,'mapnik_version') and mapnik.mapnik_version() >= 800: | |
# bbox = mapnik.Box2d(c0.x,c0.y,c1.x,c1.y) | |
#else: | |
# bbox = mapnik.Envelope(c0.x,c0.y,c1.x,c1.y) | |
bbox = mapnik.Envelope(c0.x,c0.y,c1.x,c1.y) | |
m.zoom_to_box(bbox) | |
im = mapnik.Image(imgx,imgy) | |
mapnik.render(m, im) | |
view = im.view(0,0,imgx,imgy) # x,y,width,height | |
view.save(map_uri,'png') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment