Skip to content

WMS time - create tileindex with time - example #771

@sgofferj

Description

@sgofferj

I am working to set up mapserver to replace my daily download-and-process-satellite-images-of-my-living-area-and-post-them-to-telegram workflow with a nice website which not only displays the sat images but also allows going back and forward in time.
The mapserver documentation does explain how to setup mapserver for WMS time which requires a tileindex but unlike the tileindex section of the docs, there is no hint or help on how to create a tile index. I have been hacking together a quick and dirty way create a tile index with times in Python. The code has some flaws, namely, df.append needs to be replaced with pd.concat but it works and could serve as an example. I hacked the code together from various examples from the net and through trial and error, so I put it under a CC0 license. Use as you see fit.

Apologies for not submitting a pull request but I don't have the time to set up the GIT workflow for the MapServer documentation and read myself in on policies, style, etc.

The code expects a metadatum "TIMESTAMP" in the GeoTiff which I set in my processing pipeline.

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

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)
            ds=gdal.Open(fullname)
            metadata=ds.GetMetadata()
            print (fullname,metadata['TIMESTAMP'])
            ds=None
            df = df.append({'location': fname, 'geometry': getBounds(fullname),'timestamp': metadata['TIMESTAMP']}, ignore_index=True)

df.to_file("tile-index.shp")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions