|
From: klo uo <kl...@gm...> - 2012-10-11 02:40:15
|
On Thu, Oct 11, 2012 at 3:31 AM, Jeff Whitaker wrote: > But warpimage assumes the image is of global extent - perhaps we could > make warpimage smart enough to get the georeferencing from the wms > instance but that would require some work. There must be some way to > let the WMS server do the image warping and convert the result to > something imshow can read - perhaps by writing to a png file (or > CStringIO instance) and then reading it back in with imread? Not sure, but as in example posted, 'img' is HTTPmessage pointing to server, and I can't see how we can deduce georeference as 'wms' object is named arbitrary, it could have been named to anything: ======================================== from owslib.wms import WebMapService server = ' http://motherlode.ucar.edu:8080/thredds/wms/fmrc/NCEP/NAM/CONUS_12km/NCEP-NAM-CONUS_12km-noaaport_best.ncd ' wms = WebMapService(server) ... ======================================== I don't know how to make WebMapService instance for Basemap class, so can't even tell if that's good idea or not, but we can add optional parameter to warpimage() function which could help georeferencing? boundingbox? Also as I think you mentioned that warpimage() is kind of resource hog, so we should find other way if possible? Anyhow, here is function that can read chunked response, so tell what you think: ======================================== def imshow_chunked(img): if img.headers['transfer-encoding'] == 'chunked': import cStringIO sio_img = cStringIO.StringIO() while True: chunk = img.read() if not chunk: break sio_img.write(chunk) sio_img.seek(0) wms_img = imread(sio_img) sio_img.close() else: wms_img = imread(img) img.close() return imshow(wms_img, origin='upper') ======================================== Where 'img' is as in my previous mail - img = wms.getmap(...) |