Saving PNG

8 views
Skip to first unread message

DB

unread,
Sep 30, 2009, 3:46:40 PM9/30/09
to gheat
Hi,

Is there any way (using gheat or the Google Maps API) to save the heat
map to a PNG locally on the disk?

Also, is there a way to have a perm-link of the heat map that could be
used to link directly?


Thanks,

David

Chad Whitacre

unread,
Oct 9, 2009, 4:10:04 PM10/9/09
to gh...@googlegroups.com
David,

Sorry I didn't release your message sooner. I believe you may have found gen-tile.py (did you post issue 17?).

Anyway, I've taken Bob K's version and checked it in on trunk. Thanks Bob! :-)



chad

DB

unread,
Oct 20, 2009, 8:52:17 AM10/20/09
to gheat
Hi again,

That's not really what I'm trying to do.

I want to be able to create one PNG file with the google map overlayed
with the heat tiles. (all as one PNG file)

Any ideas?

Thanks,

David




On Oct 9, 4:10 pm, Chad Whitacre <c...@zetaweb.com> wrote:
> David,
> Sorry I didn't release your message sooner. I believe you may have found
> gen-tile.py (did you post issue 17?).
>
> Anyway, I've taken Bob K's version and checked it in on trunk. Thanks Bob!
> :-)
>
> chad
>

Bob K

unread,
Oct 21, 2009, 9:05:41 AM10/21/09
to gheat
David - I'm pretty sure that the Google Maps API terms of use forbid
saving maps to a file - you may want to check out the google maps API
discussion group for similar threads.

If all you want is to save the heatmaps but not the other map tiles
(Street view, satellite imagery, etc) then that should not be a
problem since the heatmaps are all yours. In that case I'd look to
either stitch together individual heatmap PNGs into the image you
want, or hack gheat to generate a single PNG for your map window.

Chad Whitacre

unread,
Oct 21, 2009, 9:25:15 AM10/21/09
to gh...@googlegroups.com, David Lo Pan
hack gheat to generate a single PNG for your map window.

David Z was working on that. DZ: are you listening?


chad 

David Zielezna

unread,
Oct 21, 2009, 5:29:23 PM10/21/09
to gh...@googlegroups.com
hi guys,

i am listening and i have done work on this. i will try and commit it
this weekend. it needs a bit of a tidy and i'm a bit busy at the moment.

effectively this is how i was generating each frame in the animated
heatmaps.

Chad Whitacre

unread,
Oct 22, 2009, 10:50:59 AM10/22/09
to gh...@googlegroups.com
i am listening and i have done work on this.  i will try and commit it
this weekend.  it needs a bit of a tidy and i'm a bit busy at the moment.

Thanks Dave.

Pascal

unread,
Oct 20, 2009, 4:43:47 PM10/20/09
to gheat
I modified gheat and wrote a set of wrapper scripts that do this.

The trickiest part is to get the actual map from google maps where the
bounds actually match tile locations so you can just start inserting
tiles at 0,0 and then go on with 0, 256, etc.
You can see mine here: http://groups.google.com/group/gheat/web/master.png
. I used gMapMaker to get it, and then added the Google logo and
copyright info manually. It is actually bigger but my script crops it.
It's for zoom level 5. So basically you will need to create
points.txt, run db.py clear, db.py sync, and then run tile-gen.py
(edit it to only include the zoom level you are going to work with)
After that you will just need to create a new png file, put that
master map in it, then start laying tiles (use their file names to
determine their position knowing that 0,0.png would be at 0,0 (not lat/
lng but pixels) and 1,1.png would be at 256,256 etc. There is a post
on this forum that has a snippet that makes gheat faster at generating
the tiles, but they are not transparent PNGs. I found that this works
best in this case and I use the imagecopymerge PHP function which
allows you to set an opacity. If the tile is not in the /classic/X
directory (where X is the zoom level) then you will lay an empty tile
instead with the same opacity settings, etc.
After that, you can also overlay some pretty logos, text to describe
the data being presented and timestamps, etc.

Don't forget to optimize your PNG file before you output it. I can
actually generate .gif files that look amazing and they are only 100kb
for 1050x540 file with lots of data and pretty logos and colors - the
PNG file that was returned by default was over 1MB originally. Let me
know if you need help with that (if you go the PHP route) - I have
some of the functions I used to do this. I would show you my maps and
send you the code but I cannot release any of it yet. Basically I
generate 2 images per hour: one medium res, one low res and one high
res (for archives only) and make only the medium res, most current one
available to visitors. Then, at the end of the day, a cron job picks
them up and makes a nice .gif animation out of them.

If you need more info let me know. I also rewrote the functions to
convert lat/long into pixels and vice versa in PHP for the google
coordinate model. Let me know if you need them depending on how
complex your need is.

Pascal

unread,
Oct 23, 2009, 12:10:54 AM10/23/09
to gheat
@ Bob K concerning saving maps to files:

I'm not entirely sure and you may be right, however a way to get
around this and be safe would be to use the Static Maps API. Then
AFAIK there is nothing wrong with caching the results to lower the
overhead on google's servers. Only downside is that the static maps
API is limited to a size of 640x640 and that each map will contain the
google logo, etc.
I had this working when I first wrote the tools I use to generate
these heatmap videos but because we need 2000x1000 pixels or so the
static maps API didn't do the job due to these logos and copyright
info being repeated every 640px.

Pascal
Reply all
Reply to author
Forward
0 new messages