Changeset 2586
- Timestamp:
- 14/06/07 13:57:39 (14 years ago)
- Location:
- TI05-delivery/ows_framework/trunk/ows_server/ows_server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TI05-delivery/ows_framework/trunk/ows_server/ows_server/controllers/csml_wms.py
r2578 r2586 7 7 8 8 @author: Stephen Pascoe 9 9 10 """ 10 11 from ows_server.lib.base import * 11 12 from ows_server.controllers.csml_api import get_csml_doc 12 13 from ows_server.lib.decorators import * 14 from ows_server.lib import grid_util, render 15 from ows_server.lib.csml_util import get_csml_doc 13 16 import ows_server.lib.validators as V 14 17 … … 20 23 from ows_common.domain import ValuesUnit, PossibleValues 21 24 22 from ows_server.lib.csml_util import get_csml_doc 23 import ows_server.lib.validators as V 24 25 import cdms 26 import tempfile, os 27 from cStringIO import StringIO 28 import MA 25 29 26 30 class CsmlWmsController(OwsController): … … 38 42 39 43 44 def _iterDimensions(self, feature): 45 """ 46 Retrieve the non-geospatial dimensions of a feature. 47 48 @return: generator of dimension names 49 50 """ 51 # Waiting for this feature to be implemented 52 #lat = feature.getLatitude() 53 #lon = feature.getLongitude() 54 lat = 'latitude'; lon = 'longitude' 55 56 for axis_name in feature.getDomain(): 57 if axis_name not in [lat, lon]: 58 yield axis_name 59 40 60 def _loadFeatureDimensions(self, feature): 41 61 dims = {} 42 #!WARNING 43 # This bit is a hack until the CSML API implements a mechanism 44 # to determine which elements of a domain are longitude and latitude. 45 for axis_name, axis in feature.getDomain().iteritems(): 46 if axis_name in ['longitude', 'latitude']: 47 continue 62 domain = feature.getDomain() 63 for axis_name in self._iterDimensions(feature): 64 axis = domain[axis_name] 48 65 dims[axis_name] = Dimension(possibleValues=PossibleValues.fromAllowedValues(axis), 49 #!TODO: this is a fudge until we can deduce UOM.66 #!TODO: see ticket:770 for how to populate this 50 67 valuesUnit=ValuesUnit(uoms=[''], 51 68 referenceSystems=[''])) … … 115 132 transparent=False, bgcolor=None, exceptions=None): 116 133 134 # Retrieve dataset and selected feature 117 135 dataset = get_csml_doc(file) 136 feature = dataset.getFeature(layers) 137 if feature is None: 138 raise OWS_E.InvalidParameterValue('Layer not found', 'layers') 118 139 119 return Response('Operation done') 140 # Define the extraction selector 141 sel = dict(latitude=(bbox[1], bbox[3]), longitude=(bbox[0], bbox[2])) 142 143 # Parse dimensions. 144 for dim in self._iterDimensions(feature): 145 # For the moment hard-code time in. We don't support any other dimension yet. 146 if dim.lower() != 'time': 147 raise ValueError('Only lat, lon and time are supported domain axes') 148 149 try: 150 sel[dim] = request.params[dim] 151 except KeyError: 152 raise OWS_E.MissingParameterValue('%s dimension not specified' % dim, dim) 153 154 # Subset the feature 155 (fd, filename) = tempfile.mkstemp('.nc', 'csml_wms_'); os.close(fd) 156 feature.subsetToGridSeries(ncname=os.path.basename(filename), 157 outputdir=os.path.dirname(filename), 158 time=sel['time'] # workarround for CSML bug 159 #**sel 160 ) 161 d = cdms.open(filename) 162 #var = d(feature.name.CONTENT, squeeze=1) 163 var = d(feature.name.CONTENT, longitude=sel['longitude'], latitude=sel['latitude'], 164 squeeze=1) 120 165 166 # Deduce min and max 167 varmin = MA.minimum(var, None) 168 varmax = MA.maximum(var, None) 169 170 # Render variable to a PIL image 171 img = render.render_variable(var, bbox, width, height, varmin, varmax) 172 173 # Serialise it to PNG 174 buf = StringIO() 175 img.save(buf, 'PNG') 176 177 return Response(content=buf.getvalue(), mimetype='image/png') -
TI05-delivery/ows_framework/trunk/ows_server/ows_server/lib/render.py
r2582 r2586 94 94 95 95 96 def render_variable(var, bbox, width, height, cmap, varmin, varmax):96 def render_variable(var, bbox, width, height, varmin, varmax, cmap=None, ): 97 97 """ 98 98 Creates RGBA PIL images with a selectable matplotlib colour scale. 99 99 100 @todo: This should be class really, but it came out of my brain as a function. 101 @todo: Transparent missing_value mask not working. 102 100 103 """ 104 105 if cmap is None: 106 cmap = cm.get_cmap() 101 107 102 108 … … 118 124 norm = colors.normalize(varmin, varmax) 119 125 a = norm(var.getValue()) 120 126 order = var.getOrder() 127 121 128 # Render the normalised variable by converting it into a byte array then to a PIL image 122 129 img_buf = (cmap(a) * 255).astype('b') 123 130 (y, x, c) = img_buf.shape 124 img = Image.frombuffer("RGBA", (x, y), img_buf.tostring(), "raw", "RGBA", 0. 1) 131 132 img = Image.frombuffer("RGBA", (x, y), img_buf.tostring(), "raw", "RGBA", 0, 1) 125 133 126 134 # Ensure lat & lon increase from the bottom left … … 140 148 # It is assumed that grid can wrap around in the longitude and therefore only 141 149 # needs adjusting in the latitude. 142 if bbox != bbox Obj.crs84:150 if bbox != bbox_obj.crs84: 143 151 img = Image.new('RGBA', (width, height)) 144 (ox, oy) = bbox Obj.getCrs84OffsetInImage(width, height)145 nwidth, nheight = bbox Obj.getCrs84ImageSize(width, height)152 (ox, oy) = bbox_obj.getCrs84OffsetInImage(width, height) 153 nwidth, nheight = bbox_obj.getCrs84ImageSize(width, height) 146 154 # If the image is too small just send a blank image 147 if bbox Obj.crs84Width > abs(dlon) and bboxObj.crs84Height > abs(dlat):155 if bbox_obj.crs84Width > abs(dlon) and bbox_obj.crs84Height > abs(dlat): 148 156 img1 = render(var, width, nheight) 149 157 img.paste(img1, (0, oy))
Note: See TracChangeset
for help on using the changeset viewer.