Web API for printing high resolution PDF maps.
Lascaux works by passing in a link to a set of map tiles (similar to how Leaflet loads in TileLayers) and returning a high resolution PDF for printing. You can also set the map center, zoom level and size of your desired PDF.
Parameters:
center
- Latitude,longitude of map centerdimensions
- Height,width of desired map in pixels. Defaults to 1275,1650 (8.5" x 11" letter size). Another useful size is 2550,3300 (11" x 17" tabloid size)zoom
- Number indicating the zoom level from 1 (the whole world) to 20 (a city block). Defaults to 17.
Optional parameters:
overlay_tiles
- Your map data tile layer in this format:http://{s}.somedomain.com/blabla/{z}/{x}/{y}.png
. these tiles should support transparencybase_tiles
By default, we use tiles from Open Street Map. If you want to provide your own, however, you can do so by providing an encoded URL to your own tile layer. Expects the same format asoverlay_tiles
We use Open Street Map tiles because they show building addresses for zoom 17 and above. Here's what they look like:
Here's some other base_tiles
that are good for printing:
https://{s}.tiles.mapbox.com/v3/datamade.hn83a654/{z}/{x}/{y}.png
http://d.tile.stamen.com/toner/{z}/{x}/{y}.png
http://c.tile.stamen.com/terrain/{z}/{x}/{y}.jpg
http://a.tiles.mapbox.com/v3/datamade.k92mcmc8/{z}/{x}/{y}.png
Here's an 11" x 17" map of vacant properties around S 55th and W California on Chicago's South Side provided by LocalData and Southwest Organizing Project:
You can pass in your own base_tiles
if you don't like ours. Here's the same LocalData map with Stamen's Toner base tiles:
>>> import requests
>>> params = {
'center': [-87.69358, 41.786456],
'dimensions': [2550, 3300], # tabloid size
'zoom': 17,
'overlay_tiles': 'http://localdata-tiles.herokuapp.com/06a311f0-4b1a-11e3-aca4-1bb74719513f/filter/Is-property-vacant/Yes/tiles/{z}/{x}/{y}.png'
}
>>> r = requests.get('http://lascaux.datamade.us', params=params)
>>> with open('my_map.pdf', 'wb') as f:
f.write(r.content)
That should give you a file called my_map.pdf
in your current working directory
Setting up Python and OpenCV
This is by far the biggest hassle. Once it is done, however, it never needs to be done again. These instructions work on Ubuntu 12.04. You’ll probably need to modify them to suit your particular environment. These directions also assume you have virtualenvwrapper setup as well.
$ mkvirtualenv printmatic
$ pip install numpy
$ sudo apt-get install cmake libgtk2.0-dev pkg-config libavcodec-dev \
libavformat-dev libswscale-dev libamd2.2.0 libblas3gf libc6 libgcc1 \
libgfortran3 liblapack3gf libumfpack5.4.0 libstdc++6 build-essential \
gfortran libatlas-dev libatlas-base-dev libblas-dev liblapack-dev libjpeg-dev \
libpng-dev libtiff-dev libjasper-dev
$ wget -O opencv-2.4.9.zip http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.9/opencv-2.4.9.zip?r=http%3A%2F%2Fopencv.org%2Fdownloads.html&ts=1403558615&use_mirror=softlayer-dal
$ mkdir src && mv opencv-2.4.9.zip src && cd src
$ unzip opencv-2.4.9.zip
$ cd opencv-2.4.5/
$ mkdir release
$ cd release
$ cmake -DMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=$VIRTUAL_ENV/local/ \
-DPYTHON_EXECUTABLE=$VIRTUAL_ENV/bin/python \
-DPYTHON_PACKAGES_PATH=$VIRTUAL_ENV/lib/python2.7/site-packages \
-DINSTALL_PYTHON_EXAMPLES=ON ..
$ make -j8 # Set the number here to the number of processing cores you have
$ make install
$ mkvirtualenv printmatic
$ pip install -r requirements.txt
This is a hassle. Maybe use brew?
I already had OpenCV installed, and had to copy cv2.so
to my virtualenv's
site-packages
. This probably can be dealt with better by some PATH
manuvering.
Getting Cairo set up has been a major pain. The most common problems are caused by it simply not being found. Try:
export PKG_CONFIG_PATH=/usr/X11/lib/pkgconfig
(or just add it right to your PATH
)
On Ubuntu you should be able to get libcairo and the appropriate header files thusly:
$ sudo apt-get install libcairo2-dev
$ python app.py