pythontiffgeoserverwcs

How to download GeoTiff files from GeoServer using Python


I am trying to download GeoTiff files from GeoServer using Python. I have a found a few resources online about this type of thing, but I have been unable to accomplish this task.

For example, here: https://gis.stackexchange.com/questions/181560/download-geotiff-from-geoserver it seems that people have been able to do what I want to do, but they do not explain their process.

Likewise, the accepted answer here: How to grab a TIFF image from python works for downloading GeoTiffs like the one at http://imgsrc.hubblesite.org/hu/db/images/hs-2006-01-a-hires_tif.tif, but there is no download link for GeoTiffs on GeoServer.

Any help would be much appreciated!

EDIT: Here are some more details about what I have tried thus far. GeoServer has a rest API server, at http://localhost:8080/geoserver/rest locally, so I initially tried to access this url in python and then download the GeoTiff I want in "Layers". However, each of the files in "Layers" is an html file; what I would like to know is if there is a place where I can actually access the GeoTiff files programmatically. I think this is the root of the problem – although I am not really sure how to download GeoTiffs programmatically, I must first be able to actually access them in GeoServer.

As far as progress, though, I have not been able to make much. As I mentioned above, I was able to download a GeoTiff using the code at How to grab a TIFF image from python, but I have been unable to do this for a GeoTiff on GeoServer. I am new to both GeoServer and the GeoTiff format, so I am not quite sure how to approach this problem.


Solution

  • My coworker has found a solution for this problem. Using the example code below, we can download GeoTiff files from GeoServer.

    from owslib.csw import CatalogueServiceWeb
    import urllib
    
    def getLinkByIDCWS(url, id, user, pwd):
        csw = CatalogueServiceWeb(url, username=user, password=pwd)
    
        csw.getrecordbyid(id=[id])
        csw.records[id].references
    
        link = csw.records[id].references[2]['url']
    
        return link
    
    def downloadImage(url, fileName):
        urllib.request.urlretrieve(url, fileName)
    
    url = "http://localhost:8080/geoserver/csw?service=CSW&version=2.0.2&request=GetRecords&typeNames=gmd:MD_Metadata&resultType=results&elementSetName=full&outputSchema=http://www.isotc211.org/2005/gmd"
    record = "nurc:Arc_Sample"
    name = "<user>"
    pwd = "<pwd>"
    
    link = getLinkByIDCWS(url, record, name, pwd)
    print(link)
    
    downloadImage(link, "test.arc")