I wish to download Weekly NDVI rasters from the USDA Vegscape portal. It is possible to access the data using WMS and WCS methods. The USDA dev guide only contains example URLs on how to access the data, see below:
I found the below section of code on gis.se but am unsure how to adapt it for my own purpose:
import os
from owslib.wcs import WebCoverageService as w #owslib ->https://github.com/geopython/OWSLib
#easy_install owslib
folder = 'c:\\path\\to\\folder\\'
wcs = w(url="http://dmcsee.org/cgi-bin/mapserv?map=/var/www/tmp/dmcsee_wms/dmcsee_wcs.map",version="1.0.0")
spi6 = w['SPI6'] #The layer I am interested in
for timep in spi6.timepositions:
output = wcs.getCoverage('SPI6',time=[timep],bbox=(10.0,31.995,48.005,50),format='GTiff',CRS='EPSG:4326', WIDTH=380, HEIGHT=120)
f = open(os.path.join(folder,'spi6_'+str(timep)+'.tiff'),'wb')
f.write(output.read())
f.close()
Best Answer
You didn't say what you tried, or where you got stuck, but hopefully this answer will provide you enough hints to get further.
First off the original answer you referenced and included in your question had a syntax error; so as mentioned in comments:
Now looking at the service you want to access (https://nassgeodata.gmu.edu/VegScapeService/weekly_ndvi_2012.cgi?) when I try to call this using OWSLib I get the following error:
Which means that there is a problem with the certificate used by the site. However, before we panic, if we look at the GetCapabilities response we can see that this service is proxying another:
And we can use this URL in our Python like:
Gives us:
Gives:
Gives:
Gives:
So we can see there are no timepositions and therefore following an example where we loop over timepositions isn't going to be very useful.
except:
I realised that the https://service is actually proxying the daily service, but there is also also an accompanying weekly service we can call:
However, the GetCapabilities response for this weekly service is also pointing at the daily service (like the https://service), so we have a problem because, as far as I know, it is not possible to get OWSLib to use the URL provided for
wcs.WebCoverageService
in the subsequent GetCoverage request, and instead the URLs from the GetCapabilites/DescribeCoverage responses are used...I should add that generally this is the desired behaviour, but in this situation it is not helpful.
finally:
So if we want to get coverages from the weekly service, then we must write our own GetCoverage requests and in the end you'll need something like: