1

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.

pierce.nasa
  • 11
  • 1
  • 4
  • Please post what you have tried to do and be more specific. – philoez98 Jun 21 '19 at 21:09
  • @philoez98 I added some more details – please let me know if you would still like more information and I can try to provide it. – pierce.nasa Jun 21 '19 at 21:29
  • You should be able to do what you want by querying the REST API that Geoserver exposes. Then it should be easy as making a GET request to a specific endpoint. More here: https://docs.geoserver.org/latest/en/user/rest/index.html#rest – philoez98 Jun 21 '19 at 21:37
  • Thank you very much for your responses. The problem I have had with a solution like that is using GET simply gathers xml data about the layer (in my case a GeoTiff) rather than actually accessing the layer itself. So, for example, if I were to GET a layer, I would receive xml data as opposed to a tif file. If I am misunderstanding or if there is another solution, please let me know. – pierce.nasa Jun 21 '19 at 21:43
  • You're totally right, but usually in xml or json files there are the links of the actual image they are referring to. In the url I linked I think there a couple of examples of endpoints that are actually the source of raster files. – philoez98 Jun 21 '19 at 21:46
  • For example: https://docs.geoserver.org/latest/en/api/#/latest/en/api/1.0.0/coveragestores.yaml. I don't know if are available specifically for Layers data though. – philoez98 Jun 21 '19 at 21:48
  • The REST API is for GeoServer **management** not data access. – Ian Turton Jun 22 '19 at 08:30

2 Answers2

0

As the answer to your linked question says you need to make a WCS request to GeoServer to fetch a GeoTiff.

The GeoServer manual provides a WCS reference that should help you get an understanding of how to proceed. You can also go to the demos page of your GeoServer installation and use the WCS Request builder to create an XML file that you can use as a template in your python program.

GeoServer WCS Request builder

Ian Turton
  • 10,018
  • 1
  • 28
  • 47
0

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")
pierce.nasa
  • 11
  • 1
  • 4