Last active
November 28, 2017 22:54
-
-
Save prl900/dca34a1cb4b7d03be8324a7aeb96b61c to your computer and use it in GitHub Desktop.
Sample script using owslib to perform a WCS request using logging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from owslib.wcs import WebCoverageService | |
import logging | |
def GetCapabilities(path): | |
if not path.startswith('http'): | |
print "Malformed path, should start with http" | |
return | |
wcs = WebCoverageService(url, version='1.0.0') | |
print wcs.contents | |
for i,varname in enumerate(wcs.contents): | |
cov = wcs[varname] | |
print varname | |
print vars(cov) | |
print vars(wcs.contents["global:totalcover"]) | |
def GetCoverage(path): | |
if not path.startswith('http'): | |
print "Malformed path, should start with http" | |
return | |
wcs = WebCoverageService(url, version='1.0.0') | |
# Take a look at the contents (coverages) of the wcs. | |
print(wcs.contents) | |
tc = wcs['global:totalcover'] | |
# Take a look at the attributes of the coverage | |
dir(tc) | |
print(tc.boundingBoxWGS84) | |
print(tc.timepositions) | |
print(tc.supportedFormats) | |
print(wcs.url) | |
# mock up a simple GetCoverage request. | |
#output = wcs.getCoverage(identifier='red', time=['2003-01-01T00:00:00Z'], | |
output = wcs.getCoverage(identifier='global:totalcover', time=['2003-01-01T00:00:00Z'], | |
bbox=(-90,40,-89,41), crs='EPSG:4326', width=400, height=400, | |
format='GeoTIFF') | |
print output.read() | |
# Write the file out to disk. | |
f = open('foo.tif','wb') | |
f.write(output.read()) | |
f.close() | |
if __name__ == "__main__": | |
owslib_log = logging.getLogger('owslib') | |
ch = logging.StreamHandler() | |
# Add formatting and handlers as needed | |
owslib_log.setLevel(logging.DEBUG) | |
owslib_log.addHandler(ch) | |
url = "http://gsky-dev.nci.org.au/ows" | |
GetCapabilities(url) | |
GetCoverage(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment