Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


#store is a GeoServer store
def get_raster_dimensions(store):                                           
    """ Get the size of the raster from the catalog. """                    
    #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                                                      
        dataset = gdal.Open(coverage_path)                                  
        return (dataset.RasterXSize, dataset.RasterYSize)                   
    except RuntimeError:                                                    
        return (None, None)                                                 
        #no close method in GDAL docs, this was referenced as the way       
        #to clean up the file after finished                                
        dataset = None 
share|improve this question
up vote 1 down vote accepted

Found an easier method using Python via OWSLib when the workspace name, layer name, and WCS service endpoint are specified

from owslib.wcs import WebCoverageService

def get_raster_dimensions(workspace, name, server_url):                                      
    """ Get the size of the raster using OWSLib                            
        Returns a list of strings """                                            
    wcs = WebCoverageService(server_url + 'wcs', '1.0.0') 
    grid = wcs.contents[workspace + ':' + name].grid                             
    return [str(int(h) - int(l) + 1) for                                         
            h, l in zip(grid.highlimits, grid.lowlimits)]  
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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