Is there a way to save the image as PDF or PNG?
I am hoping to batch a set of datasets to create a set of image sequence for creating a video.
Maybe try CutyCapt of the output path from the final create_map step.
path='my_map.html'
map.create_map(path)
Let me know of your solution! I'll be doing similar soon.
So, I just did similar for my minecraft map, but it'll be the same process for you.
Install CutyCapt, see the install instructions for building, and there are instructions for running it headless online. Simplest is apt-get install cutycapt.
It is as simple as cutycapt --url=file:///home/user/project/goes/here/index.html --out=myoutput.png.
See cutycapt --help for zooming and turning javascript on or off, etc.
There's no easy way to do this outside of just doing a screen capture (right now).
I've just come up with a recipe for doing this using selenium. For a folium map, m:
import os
import time
from selenium import webdriver
delay=5
fn='testmap.html'
tmpurl='file://{path}/{mapfile}'.format(path=os.getcwd(),mapfile=fn)
m.save(fn)
browser = webdriver.Firefox()
browser.get(tmpurl)
#Give the map tiles some time to load
time.sleep(delay)
browser.save_screenshot('map.png')
browser.quit()
@psychemedia that is very cool! It is also giving me some crazy ideas about continuous integration testing of maps. Thanks for sharing.
This is how I did it within python (ie calling subprocess):
import os
import subprocess
outdir = "screenshots" # this directory has to exist..
map.save("tmp.html")
url = "file://{}/tmp.html".format(os.getcwd())
outfn = os.path.join(outdir,"outfig.png")
subprocess.check_call(["cutycapt","--url={}".format(url), "--out={}".format(outfn)])
To save anybody else reading this some time:
*It wouldn't work if I passed the url as 'tmp.html', it needs to be a full path with file in front.
*Also, the filename where it's saved needs to end with .html
In my experience cutycapt will render the map, but not any markers you have placed on it. Folium really needs a PDF or PNG output option.
I am using folium to generate a series of maps that need to end up in a PDF
or Word file. Find myself having to launch selenium to simulate a browser,
then save a screenshot. Works well but it's a cumbersome solution.
On Thu, Apr 13, 2017 at 10:10 AM, Lucas Sinclair notifications@github.com
wrote:
In my experience cutycapt will render the map, but not any markers you
have placed on it. Folium really needs a PDF or PNG output option.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/python-visualization/folium/issues/35#issuecomment-293890652,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGzdubv0wQ8sRBVNr5zX90YQ3Jr0HYTXks5rvh6qgaJpZM4CBKNh
.
@sergiolucero do you fancy sending a PR to add that functionality to folium?
@sergiolucero @ocefpaf Did a PR come from this? Trying to make comparable maps as subfigures, via an elegant solution for exporting to PDF or PNG.
@oscarechobravo no PR yet. Do you want to try it?
Finally done in #634
It is still experimental and feedback is welcome. Note that you'll need phantomjs installed to make it work.
This looks like it could be handy for screenshotting, though again it uses a (Chrome) browser to grab the map image: https://github.com/wbkd/leaflet-mapshot
Could you please provide an example of usage instead of pointing to the raw PR? You're asking all of your users to read your work-in-progress code from 2 years ago and links to notebooks that don't exist when there should just be documentation provided for a feature like this.
Most helpful comment
I've just come up with a recipe for doing this using selenium. For a folium map,
m: