Skip to content

Instantly share code, notes, and snippets.

@kuboris

kuboris/mapexport.py

Created Apr 13, 2018
Embed
What would you like to do?
Create PDF map with custom projection using Mapnik and TileMill
#used in jupyter notebook with Python 2
!apt-get install python-cairocffi
!pip install mapnik
import mapnik
import cairocffi as cairo
map = mapnik.Map (1750 ,1185)
mapnik.load_map ( map ,'wallmap.xml')
map.zoom_all ()
map.zoom (1)
mapnik.render_to_file(map,"output.pdf","pdf")
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map[]>
<Map srs="+proj=gall +lon_0=0 +x_0=0 +y_0=0 +a=6371000 +b=6371000 +units=m +no_defs">
<Parameters>
<Parameter name="bounds">-180,-85.05112877980659,-180,85.05112877980659</Parameter>
<Parameter name="center">0,0,2</Parameter>
<Parameter name="format">png</Parameter>
<Parameter name="minzoom">0</Parameter>
<Parameter name="maxzoom">22</Parameter>
</Parameters>
<Style name="oceanfloor" filter-mode="first" >
<Rule>
<LineSymbolizer stroke="#c0ecff" stroke-width="0" stroke-linejoin="round" stroke-opacity="1" />
<PolygonSymbolizer fill-opacity="1" fill="#ececec" comp-op="color-burn" />
</Rule>
</Style>
<Layer name="oceanfloor"
srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
<StyleName>oceanfloor</StyleName>
<Datasource>
<Parameter name="file"><![CDATA[f3784b4d-10m-bathymetry.shp]]></Parameter>
<Parameter name="type"><![CDATA[shape]]></Parameter>
</Datasource>
</Layer>
<Style name="countries" filter-mode="first" >
<Rule>
<LineSymbolizer stroke-width="3" stroke="#d4d4d4" stroke-linejoin="round" />
<PolygonSymbolizer fill="#ffffff" />
</Rule>
</Style>
<Layer name="countries"
srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0.0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs +over">
<StyleName>countries</StyleName>
<Datasource>
<Parameter name="file"><![CDATA[82945364-10m-admin-0-countries.shp]]></Parameter>
<Parameter name="type"><![CDATA[shape]]></Parameter>
</Datasource>
</Layer>
</Map>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.