1

I would like to create an animation from a set of PNG files and apply labels (time lapse values) on each of the PNG files. The PNG files were actually heat maps that were generated by interpolation.

I have created the heat maps in 2 steps:

  1. I Created a QGIS a vector layer that stores timestamp and temperature value pairs for several points on the map. I also added in the vector layer a time stamp for each data point. The header looks something like:

point1, lat, long, time1, temp11, time2, temp12, ......

point2, lat, long, time1, temp12, time2, temp22, ......

  1. I interpolated each vector layer point for each time stamp (time 1, time2 etc) in GRASS using v.surf.icw that resulted in creating one raster layer for each time stamp, that I exported as a PNG files.

I combined all the created images in a movie with the GRASS 7 GUI animator. Everything looks good except that I would like to have the time lapse label printed on each slide/frame.

In order to add the labels on the slides, I would like now to create a script that reads the time values from the vector layer that was detailed above and write/print the selected values then on the PNG images.

One way I found is to use d.text in grass as documented here. However, this example only shows how to create new slides but not how to write on existing ones. In addition, the time stamp information needs to be extracted/read from the vector layer. I assume with d.vect or something similar may work.

Therefore my question about how put a label on a animation slide has two aspects:

  1. Extract an attribute value from a vector layer?
  2. How to write the value of the attribute with d.text on an exiting PNG image?
5
  • Maybe an external tool would be the most flexible option. For example you can add text to images with the convert tool from ImageMagick – Micha Apr 9 '14 at 5:38
  • That can maybe done, but I also asked how can I extract the attribute value from the shapefile. If you can put these 2 answers together in a very small example I am going to give you credit for this. I suppose that I can use python's pyshp to do the later . Thanks – Bogdan Apr 9 '14 at 13:34
  • @PolyGeo Indeed the initial question was not clear. I reworded the question so that is clear what it was already done and what it was asked. As I offered already a solution 5 years ago, I think that it is worth keeping it in the system. – Bogdan Sep 26 '19 at 14:20
  • Whether a question remains on the site depends on the up/down votes it receives, and not on whether it is closed for new answers. – PolyGeo Sep 26 '19 at 20:26
  • I understand, although I don't see many people doing this type of animation with labeling. I wanted to understand what "put on hold" means and if my changes made the question comply with the guidelines and if "put on hold" is going to be removed. – Bogdan Sep 27 '19 at 21:05
0

Consider to look into GRASS GIS 7. It comes with an easy to use animation tool (with film export):

http://grass.osgeo.org/grass70/manuals/wxGUI.animation.html

Example video: http://www.youtube.com/watch?v=oTQ963mC9JE

... and more related videos: http://www.youtube.com/user/kratoan1

1
  • I already mentioned that I am using the animation tool to create the animation. The problem is putting the time stamp on the slide. I figured out a way and I will post it soon – Bogdan Apr 9 '14 at 22:14
0

Although the title does not reflect anymore the solution I solved the problem this way:

  1. I generated the PNG files with the GRASS animation tool as suggested by me in my question and by @markusN in his answer. That part I already had but I mention it for completeness of the answer.
  2. Instead getting the time stamps from the shapefile I exported the attributes to a CVS file and I read those strings from it and apply them to each PNG image with the ImageMagick tool "convert" as shown below in the sample code in Python.

        #read the tim stamp string from the 
    
    csv_name = "/home/bogdan/Documents/UofT/PhD/Data_Files/TorontoHarbour-bathymetry/tor_harb_instr_snap_dates.csv"
                ifile = open(csv_name, 'rb')
                reader = csv.reader(ifile, delimiter = ',', quotechar = '"')
                ts = []
                for row in reader:
                    for col in row:
                        ts.append(str(col))
                    # end for col
                # end for row
                ifile.close()
    
        imgdir = "/home/bogdan/Documents/UofT/PhD/Data_Files/TorontoHarbour-bathymetry/TorHarb_1h_HeatMaps_TS"
        imgdir_out = "/home/bogdan/Documents/UofT/PhD/Data_Files/TorontoHarbour-bathymetry/TorHarb_1h_HeatMaps_TS_OUT"
    
        #apply time stamp
        for j in range(0, len(ts)):
            text = "text 50,100 '" + ts[j] + "'"
            fn = imgdir + "/TH_1h_%03d.png" % (j + 1)
            fn_out = imgdir_out + "/TH_1h_%03d.png" % (j + 1)
            arg = fn + " -size 800x506 -font Bookman-DemiItalic -pointsize 16 -draw \"" + text + "\" " + fn_out
            cmd = "convert " + arg
            os.popen(cmd)
    
  3. Animate with mencoder

#!/bin/bash

if [ -z "$1" ] ; then
    echo "No argument supplied"
    IMGPATH=`pwd`
else 
    IMGPATH=${1}
fi



VIDOPTIONS="-mf fps=9 -ovc x264 -x264encopts pass=3 -x264encopts preset=veryslow -x264encopts tune=animation"

mencoder "mf:///$IMGPATH/*.png" -o $IMGPATH/movie.avi $VIDOPTIONS
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.