Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WMS time - create tileindex with time - example #771

Open
sgofferj opened this issue Oct 15, 2022 · 0 comments
Open

WMS time - create tileindex with time - example #771

sgofferj opened this issue Oct 15, 2022 · 0 comments

Comments

@sgofferj
Copy link

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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant