Hello Dom, El mar, 19-05-2009 a las 10:24 +0100, Dominic Lowe escribió: > Hi Goyo, > > However I'm a bit confused - the url you sent [1] *does* have a question > mark in it. > Have I misunderstood something?
Mmh, now I can see that my intention was not obvious. The url points to the Capability section of GetCapabilities, if you look at the XML you can see the urls for GET and POST methods, which do not end in a question mark. They should. Using owslib: >>> from owslib.wcs import WebCoverageService >>> serviceURL = 'http://www.idee.es/wcs/IDEE-WCS-UTM30N/wcsServlet' >>> wcs = WebCoverageService(serviceURL, version='1.0.0') >>> wcs.getOperationByName('GetCoverage').methods['Get']['url'] 'http://www.idee.es/wcs/IDEE-WCS-UTM30N/wcsServlet' > I've modified the code in the owslib trunk now to better handle url encodings > and the returned error. > > However it is only a quick fix and I need to review it more thoroughly (this > aspect needs reviewing throughout owslib). I don't think the urlopen(url, data) approach can work (see below). I suggest something like this --not tested: url_base.strip() # You never know... lastchar = url_base[-1] if lastchar not in ['?', '&']: if url_base.find('?') == -1: url_base = url_base + '?' else: url_base = url_base + '&' try: u = urlopen(base_url + data) except: # Don' try to open the url again, just deal with the exception. # Re-raise any exception which is not properly handled. Explanation: The last character of url_base should be '?' or '&' (in case it contains vendor specific parameters). If not, let's try to fix it. If url_base does not contain any '?' let's assume there are no vendor specific parameters in it so just add '?'. If url_base does contain a '?' let's assume there are vendor specific parameters so add '&'. I think this should work in most cases, at least for WCS 1.0.0. > I had some success accessing your server, until the final getcoverage request > which returns an error I don't understand: > > <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?><!DOCTYPE > ServiceExceptionReport > SYSTEM > "http://www.idee.es/wcs/dtd/exception_1_1_0.dtd"><ServiceExceptionReport > version="1.1.0"><ServiceException code="InvalidFormat">Error al parsear la > peticion XML: Start of root element > expected.</ServiceException></ServiceExceptionReport> > > > The code I used to test it (and the responses) was this: > > >>> from owslib.wcs import WebCoverageService > >>> > wcs=WebCoverageService('http://www.idee.es/wcs/IDEE-WCS-UTM30N/wcsServlet', > version='1.0.0') > >>> wcs.url > 'http://www.idee.es/wcs/IDEE-WCS-UTM30N/wcsServlet' > >>> wcs.version > '1.0.0' > >>> wcs.identification.service > 'IDEE-WCS-UTM30N' > >>> > 'IAAA Laboratory, University of Zaragoza' > >>> wcs.provider.contact.organization > 'IAAA Laboratory, University of Zaragoza' > >>> > > ['MDT25_peninsula_pendientes', 'MDT_peninsula_baleares_aspecto', > 'MDT1000_peninsula_baleares', 'MDT500_peninsula_baleares', > 'MDT_peninsula_baleares', 'MDT500_peninsula_baleares_pendientes', > 'MDT1000_peninsula_baleares_pendientes', 'MDT_peninsula_baleares_pendientes', > 'MDT25_peninsula_ZIP', 'MDT25_peninsula_aspecto', > 'MDT500_peninsula_baleares_aspecto', 'MDT1000_peninsula_baleares_aspecto'] > >>> cvg=wcs['MDT25_peninsula_pendientes'] > >>> cvg.title > 'MDT25 Pendientes Peninsula' > >>> cvg.boundingBoxWGS84 > (-8.7527311628, 35.8849011171, 3.6409641687000001, 43.7511638541) > >>> cvg.timelimits > [] > >>> cvg.supportedFormats > ['GeoTIFF', 'AsciiGrid', 'FloatGrid_Zip'] > >>> cvg.supportedCRS > > ['EPSG:4326', 'EPSG:4230', 'EPSG:23028', 'EPSG:23029', 'EPSG:23030', > 'EPSG:23031', 'EPSG:23030'] > >>> > output=wcs.getCoverage(identifier='MDT25_peninsula_pendientes',bbox=(-8,37,2,40), > > crs='EPSG:4326', format='GeoTIFF', resX=1, resY=1) > >>> f=open('test.tif', 'wb') > >>> f.write(output.read()) > >>> f.close() > > If you look in the test.tif file you see the error. > Does it mean anything to you? Translation: "Error parsing the XML request: Start of root element expected." When data is provided to urlopen the request will be a POST instead of a GET. WCS services (at least 1.0.0) expects data for a POST request in XML format, not as key=value pairs. That's why I don't think urlopen(url, data) is a good idea. Thanks for taking the time for this. Goyo _______________________________________________ Community mailing list [email protected] http://lists.gispython.org/mailman/listinfo/community
