Is it possible to retrieve the original width and height in pixels for a coverage in GeoServer using either the Python API or REST? I could not find anything in the documentation regarding how to retrieve height or width of a coverage in GeoServer.
Here is my current solution interfacing with GeoServer. It needs GDAL, and it will probably fail if the coverage is not a simple file readable by GDAL (i.e. a PostGIS raster)
import gdal import os from geoserver.catalog import Catalog #...code #store is a GeoServer store def get_raster_dimensions(store): """ Get the size of the raster from the catalog. """ gdal.UseExceptions() #this, of course will fail if the data isn't a regular file base_url = store.url.replace('file:', '', 1) #what if the GEOSERVER_DATA_DIR is unset? How to find it then? coverage_path = os.path.join(os.environ['GEOSERVER_DATA_DIR'], base_url) #if the coverage store is a raster readable by GDAL, #we can get the dimensions with GDAL try: dataset = gdal.Open(coverage_path) return (dataset.RasterXSize, dataset.RasterYSize) except RuntimeError: return (None, None) finally: #no close method in GDAL docs, this was referenced as the way #to clean up the file after finished dataset = None