2

I'm using owslib to download an aerial photograph. In the WMS GetMap request I specify a srs, so I assume (maybe wrongly?) that the response I get contains a crs.

When writing the result to a GeoTiff the file doesn't contain spatial information. Is there a way to do this or do I have to use GDAL to project the result, and if so, how?

This is the code I'm using so far:

from owslib.wms import WebMapService
import gdal
from osgeo import osr

wms_url = 'https://geodata.nationaalgeoregister.nl/luchtfoto/rgb/wms?'
wms = WebMapService(wms_url,version = '1.3.0')


img = wms.getmap(layers=['Actueel_ortho25'],
                 srs='EPSG:28992',
                 bbox=(97712,440638,98220,441091),
                 size=(1000,1000),
                 format='image/GeoTIFF',
                 transparent=False)

out = open('path\\to\\test.tiff','wb')
out.write(img.read())
out.close()

print('done')

2 Answers 2

2

As it currently stands, you will need to track the CRS information on the side or write it to the image yourself.

The documentation doesn't seem to mention it, but WMS layer objects have a .crs_list attribute, whose last member is seems to be the default EPSG system for that layer.

from owslib.wms import WebMapService
url = 'http://maps.geogratis.gc.ca/wms/hydro_network_en?service=wms'
wms = WebMapService(url, version='1.3.0')
wms['hydro_network'].crs_list

>>> [(-180.0, -90.0, 180.0, 90.0, 'EPSG:4269')]

Layers also have a .crsOptions attribute, which lists all the available CRSes for that layer.

wms['hydro_network'].crsOptions

>>> ['EPSG:26710',
     'EPSG:26909',
     'EPSG:32184',
     'EPSG:32196',
     'EPSG:3574',
     'EPSG:26915',
     etc.....
1

So let's separate your questions.

If a WMS specifies image/GeoTIFF then the expectation would be that if you request such an image through a GetMap request like below, then the image returned should have projection information embedded:

https://geodata.nationaalgeoregister.nl/luchtfoto/rgb/wms?service=WMS&request=GetMap&version=1.3.0&crs=EPSG:28992&layers=Actueel_ortho25&width=1000&height=1000&format=image/GeoTIFF&styles&transparent=FALSE&bbox=97712,440638,98220,441091&EXCEPTIONS=XML&BGCOLOR=0xFEFFFF&

But I see that, as you say, it doesn't:

hodor@Mini ~/REST/downloads $ gdalinfo -proj4 wms.tiff
Driver: GTiff/GeoTIFF
Files: wms.tiff
Size is 1000, 1000
Coordinate System is `'
PROJ.4 string is:
''
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0, 1000.0)
Upper Right ( 1000.0,    0.0)
Lower Right ( 1000.0, 1000.0)
Center      (  500.0,  500.0)
Band 1 Block=1000x2 Type=Byte, ColorInterp=Red
Band 2 Block=1000x2 Type=Byte, ColorInterp=Green
Band 3 Block=1000x2 Type=Byte, ColorInterp=Blue

So I would regard that as an error of the server software.

In the GetMap request I specify a srs, so I assume (maybe wrongly?) that the response I get contains a crs.

The assumption is wrong.

Generally, images (png, jpeg, gif, tiff...) requested by a client through a GetMap request are not georeferenced. The client requests an image for a location specified by a bounding box (in the coordinates of the projection the client is working with) and the server sends back the image; it doesn't need to be georeferenced because the client knows where to put it. So if you want a georeferenced image you will need to do the extra work based on the request parameters.

Is there a way to do this?

Not in owslib, because you can't make a request do do this through a WMS, other than a standard GetMap request where the image format is GeoTIFF, and the server sends a GeoTIFF.

or do I have to use GDAL to project the result, and if so, how?

You should probably ask another more focussed question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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