I have a directory full of GeoTiff files which cover the same geographical extent but differ in time (satellite photos). I would like to set up a WMS service with MapServer to serve those with the time dimension. To serve the time dimension, I need to create a SHP/DBF file as tile index which contains the time for each tile. How would I go about to do that? gdaltindex doesn't seem to be able to do that.

  • Just add a new attribute into your tileindex file and populate the times with your favorite method. I prefer to use SpatiaLite or GeoPackage as tile index and update the times with SQL. I guess some others use QGIS.
    – user30184
    Oct 14, 2022 at 14:46
  • That "just adding the attribute" is my problem. I don't know how or with which tool I modify SHP/DBF files. Oct 14, 2022 at 17:22
  • For example freegistutorial.com/…
    – user30184
    Oct 14, 2022 at 21:10

2 Answers 2


Here is the solution I came up with last night:

1.) Add a time index metadatum to the created files (gdaltranslate/gdal_edit -mo TIMEINDEX="yyyy-mm-ddThhmmZ" 2.) Hack together a Python script:


import os, sys
from osgeo import gdal
import geopandas as gpd
from shapely.geometry import box

import warnings

StartDir = str(sys.argv[1])

def getBounds(path):
    raster = gdal.Open(path)
    ulx, xres, xskew, uly, yskew, yres = raster.GetGeoTransform()
    lrx = ulx + (raster.RasterXSize * xres)
    lry = uly + (raster.RasterYSize * yres)
    return box(lrx, lry, ulx, uly)

df = gpd.GeoDataFrame(columns=['location', 'geometry','timestamp'])
for dir, subdir, files in os.walk(StartDir):
    for fname in files:
        if fname.endswith(".tif"):
            fullname = os.path.join(dir+"/", fname)
            print (fullname)
            df = df.append({'location': fname, 'geometry': getBounds(fullname),'timestamp': metadata['TIMESTAMP']}, ignore_index=True)
#            df = gpd.pd.concat(df,{'location': fname, 'geometry': getBounds(os.path.join(dir+"/", fname))}, ignore_index=True)


NOTE: suppressing all warnings is temporary until I figured out how to move from df.append to pd.concat.


You can ingest time data by using 'gdaltindex and ogr2ogr'. At first, you should create tile-index file by gdaltindex and you can get shp file. (But this shp file doesn't have time column in its record.)

Next, please convert shp to geojson by ogr2ogr and you can put time data in geojson by editor or cli tool(sed, echo and so on).

Finally you need to convert geojson to shp file by ogr2ogr again. However you can't get collect shp file because time(hour/minute/second) data might be eliminated by shp file format/Date type. Please use "--mapFieldByType" to keep your time metadata.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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