Changeset 3786 for TI05-delivery/ows_framework
- Timestamp:
- 16/04/08 16:44:07 (12 years ago)
- Location:
- TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/pylons/ows_controller.py
r3778 r3786 79 79 # All OWS parameter names are case insensitive. 80 80 self._owsParams = {} 81 #print request81 print request 82 82 #if request.has_key('REQUEST'): 83 83 #print request['REQUEST'] … … 89 89 else: 90 90 self._owsParams[k.lower()] = request.params[k] 91 if 'info_format' not in request.params: 92 self._owsParams['info_format'] = 'text/html' 91 93 #print [k, request.params[k]] 92 94 -
TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/pylons/wms_controller.py
r3778 r3786 63 63 print "loading layers" 64 64 #print self.layers 65 self.layers = self.layerMapper.map( **kwargs)65 self.layers = self.layerMapper.map() 66 66 67 67 #------------------------------------------------------------------------- … … 153 153 # This plays nicer with mapClient. 154 154 if ',' in layerName: 155 layerName = layerName.split(',')[0]156 #raise InvalidParameterValue(157 # 'Multi-layer GetMaprequests are not supported', 'layers')155 #layerName = layerName.split(',')[0] 156 raise InvalidParameterValue( 157 'Multi-layer GetLegend requests are not supported', 'layers') 158 158 try: 159 159 layerObj = self.layers[layerName] … … 239 239 240 240 # Dimension handling 241 finalImg = Image.new('RGBA', (width, height) )241 finalImg = Image.new('RGBA', (width, height), (0,0,0,0)) 242 242 # Multiple Layers handling.. 243 243 for layerName, layerObj in layers.iteritems(): … … 352 352 raise InvalidParameterValue('Version %s not supported' % version, 353 353 'version') 354 layerName, layerObj = self._getLayerParamInfo('query_layers') 355 format = self.getOwsParam('info_format') 356 if format not in layerObj.featureInfoFormats: 357 raise InvalidParameterValue( 358 'Layer %s does not support GetFeatureInfo in format %s' % 359 (layerName, format), 'info_format') 360 361 # Coordinate parameters 354 355 # Coordinate parameters 362 356 bbox = tuple(float(x) for x in self.getOwsParam('bbox').split(',')) 363 357 width = int(self.getOwsParam('width')) 364 358 height = int(self.getOwsParam('height')) 365 366 if version == '1.1.1': 367 srs = self.getOwsParam('srs') 368 else: 369 srs = self.getOwsParam('crs') 370 371 if srs not in layerObj.crss: 372 raise InvalidParameterValue('Layer %s does not support SRS %s' % 373 (layerName, srs)) 374 375 # Dimension handling 376 dimValues = {} 377 for dimName, dim in layerObj.dimensions.items(): 378 defaultValue = dim.extent[0] 379 dimValues[dimName] = self.getOwsParam(dimName, default=defaultValue) 380 # Get pixel location 359 360 # Get pixel location 381 361 i = int(self.getOwsParam('i')) 382 362 j = int(self.getOwsParam('j')) … … 384 364 # Translate to geo-coordinates 385 365 x, y = bbox_util.pixelToGeo(i, j, bbox, width, height) 386 387 # Call the layer 388 response.headers['Content-Type'] = format 389 response.write(layerObj.getFeatureInfo(format, srs, (x, y), dimValues)) 366 #start preparing GetFeatureInfo response. Assumes "HTML" output format 367 368 htmlResponse = "<html><body><p> <b>Feature Information about pixel position: "+self.getOwsParam('i')+","+self.getOwsParam('j')+"/geo position: "+str(x)+","+str(y) +"<b/></p>" 369 370 371 layers = self._getLayerParam('query_layers') 372 #Adjusts response for multiple layers 373 if len(layers) > 1: 374 htmlResponse = htmlResponse+" Multiple possible features found as follows:" 375 376 htmlResponse = htmlResponse+"<ul>" 377 378 format = self.getOwsParam('info_format') 379 for layerName, layerObj in layers.iteritems(): 380 if format not in layerObj.featureInfoFormats: 381 raise InvalidParameterValue('Layer %s does not support GetFeatureInfo in format %s' %(layerName, format), 'info_format') 382 383 384 385 if version == '1.1.1': 386 srs = self.getOwsParam('srs') 387 else: 388 srs = self.getOwsParam('crs') 389 390 if srs not in layerObj.crss: 391 raise InvalidParameterValue('Layer %s does not support SRS %s' % 392 (layerName, srs)) 393 394 # Dimension handling 395 dimValues = {} 396 for dimName, dim in layerObj.dimensions.items(): 397 defaultValue = dim.extent[0] 398 dimValues[dimName] = self.getOwsParam(dimName, default=defaultValue) 399 400 htmlResponse = htmlResponse+"<li> Layer Name: "+layerName+" <br />" 401 # Call the layer 402 htmlResponse =htmlResponse+layerObj.getFeatureInfo(format, srs, (x, y), dimValues)+"</li>" 403 404 htmlResponse = htmlResponse+"</ul></body></html>" 405 406 response.headers['Content-Type'] = format 407 response.write(htmlResponse) 390 408 391 409 def GetLegend(self): -
TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/service/imps/StationCollection.py
r3778 r3786 30 30 31 31 def getNearestStation(self,lat,lon): 32 ''' Determines the station nearest to the given geospatial point in the station collection ''' 33 32 34 curNearest=None 33 35 curDist = -1 … … 36 38 #calculate distance 37 39 tempDist = self.getDist(lat, lon, station.lat, station.lon) 38 # print [tempDist, lat, lon, station.lat, station.lon]40 #if distance is smaller than the current shortest distance 39 41 if curDist < 0 or tempDist < curDist: 40 42 curNearest = station … … 45 47 46 48 def getDist(self, srcLat, srcLon, destLat, destLon): 47 49 '''Calculates the distance between to geospatial points''' 48 50 dlon = destLon - srcLon 49 51 dlat = destLat - srcLat 50 a = (math.sin(dlat / 2))**2 + math.cos(srcLat) * math.cos(destLat) * (math.sin(dlon / 2))**2 51 c = 2 * math.asin(min(1, math.sqrt(a))) 52 dist = 3956 * c 52 #a = (math.sin(dlat / 2))**2 + math.cos(srcLat) * math.cos(destLat) * (math.sin(dlon / 2))**2 53 #c = 2 * math.asin(min(1, math.sqrt(a))) 54 #dist = 3956 * c 55 dist = math.sqrt(dlat**2 + dlon**2) 53 56 return dist 54 57 -
TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/service/imps/layers.py
r3778 r3786 1 # my first python program 1 ''' 2 This class reads the wms configuration XML document, extracts the layer elements specified in the xml file and stores them in a list. This list of layer elements is used by the WMSLayerMapper class to create a StationLayer object for each layer element in the list, using the information recorded under each layer element. 3 ''' 2 4 from xml.etree import cElementTree 3 5 … … 14 16 if elem.tag == "Layer": 15 17 curId = elem.findtext("Name") 18 # checks for duplicate layer name 16 19 if self.indexList.count(curId) < 1: 17 20 layerlist.append(elem) -
TI05-delivery/ows_framework/branches/ows_framework-refactor/ows_common/ows_common/service/imps/wms_layers.py
r3778 r3786 7 7 import Image 8 8 from copy import copy 9 from p ywms.render_impimport PointRenderer9 from pointrenderer import PointRenderer 10 10 from matplotlib import cm 11 11 import genutil … … 16 16 from xml.etree.ElementTree import ElementTree, Element, SubElement, XML 17 17 import urllib 18 from matplotlib import dates 19 18 20 19 21 class WMSLayerMapper(object): … … 25 27 26 28 """ 29 def __init__(self): 30 31 """ 32 Lists the names of all layers available as listed in the configuration file specified by the 'layer_config' parameter in the development.ini file. 33 34 @return: A mapping of layer names to ILayer implementations. 35 @raise ValueError: If no layers are available for these keywords. 36 """ 37 38 filename=config['layer_config'] 39 if not os.path.exists(filename): 40 raise Exception(str('Config File could not be found: %s')%filename) 41 print filename 42 43 #instantiate LayerParser class with the value of 'layer_config' as parameter to read layer infromation 44 layerparser = LayerParser(filename) 45 46 layermap={} 47 layers = layerparser.getLayers() 48 for feature in layers: 49 # read information necessary to create a StationLayer object 50 title, abstract, crss,formats, serverURL, icon, featureName, dataSet, bbox, dataSetURL =self._getInfo(feature) 51 # URL required to query the relevant WFS server to acquire a list of station for the current layer in the loop 52 geoServerUrl =serverURL+'/wfs?request=getfeature&service=wfs&version=1.1.0&typename='+featureName+'&maxfeatures=100' 53 print geoServerUrl 54 geoServerResponse = wget(geoServerUrl) 55 stationCollection=StationCollection(geoServerResponse) 56 # specify the filepath for the static image to be used for representing each station in the GetMap image 57 icon =config['csml_config']+'/img/'+icon 58 print icon 59 #instantiate a StationLayer object and store that in the layermap dictionary with the name of the layer as the key 60 layermap[feature.findtext("Name")]=StationLayer(title,abstract, crss, stationCollection,bbox, formats, icon, dataSet, dataSetURL) 61 if len(layermap) > 0: 62 self.layermap = layermap 63 else: 64 raise ValueError 65 27 66 28 67 def _getInfo(self, feature): 29 68 ''' given a Station feature, return info about the layer/feature 30 @return: title, abstract, dimensions, units, crss'''69 @return: title, abstract, crss, formats, serverURL, icon, featureName,dataSet, bbox, dataSetURL ''' 31 70 32 71 try: … … 43 82 print crss 44 83 formats = [] 45 ##read supported getFeatureInfo formats from the "SupportedFormats" element 84 85 #read supported getFeatureInfo formats from the "SupportedFormats" element 46 86 sFElem = feature.getchildren()[4] 47 87 for format in sFElem.getchildren(): … … 51 91 bboxElem = feature.getchildren()[5] 52 92 bbox=[int(bboxElem.getchildren()[0].text),int(bboxElem.getchildren()[1].text),int(bboxElem.getchildren()[2].text),int(bboxElem.getchildren()[3].text)] 53 #static image to be used for WMS93 #static image to be used for GetMap response 54 94 icon = feature.getchildren()[6].text 55 95 #read WFS server information … … 64 104 65 105 66 def map(self, **kwargs): 67 """ 68 Given Station.parser.Dataset object list the names of 69 all layers available. 70 71 @return: A mapping of layer names to ILayer implementations. 72 @raise ValueError: If no layers are available for these keywords. 73 """ 74 fileoruri=kwargs['fileoruri'] 75 76 #TODO - handle file paths/directories URIs in config 77 #.xml or .Station extensions are supported: 78 filename='%s/%s.Station'%(config['csml_config'],fileoruri) 79 if not os.path.exists(filename): 80 filename='%s/%s.xml'%(config['csml_config'],fileoruri) 81 if not os.path.exists(filename): 82 raise Exception(str('Config File could not be found: %s')%filename) 83 84 layerparser = LayerParser(filename) 85 86 layermap={} 87 layers = layerparser.getLayers() 88 for feature in layers: 89 title, abstract, crss,formats, serverURL, icon, featureName, dataSet, bbox, dataSetURL =self._getInfo(feature) 90 geoServerUrl =serverURL+'/wfs?request=getfeature&service=wfs&version=1.1.0&typename='+featureName+'&maxfeatures=14' 91 print geoServerUrl 92 geoServerResponse = wget(geoServerUrl) 93 stationCollection=StationCollection(geoServerResponse) 94 icon =config['csml_config']+'/img/'+icon 95 print icon 96 layermap[feature.findtext("Name")]=StationLayer(title,abstract, crss, stationCollection,bbox, formats, icon, dataSet, dataSetURL) 97 if len(layermap) > 0: 98 return layermap 99 else: 100 raise ValueError 106 def map(self): 107 '''this function is called by the wms_controller class to acquire information about all available layers''' 108 return self.layermap 101 109 102 110 103 111 class StationLayer(object): 104 112 """ 105 representing a WMS layer. Implements ILayer113 representing a WMS layer for MIDAS/ECN Stations. Implements ILayer 106 114 107 115 @ivar title: The layer title. As seen in the Capabilities document. 108 116 @ivar abstract: Abstract as seen in the Capabilities document. 109 @ivar dimensions: A dictionary of IDimension objects.110 @ivar units: A string describing the units.111 117 @ivar crss: A sequence of SRS/CRSs supported by this layer. 112 113 @todo: Do we need minValue/maxValue? 118 @ivar stationCollection: A list of NPStation objects to be rendered as part of GetMap response 119 @ivar formats: A list of output formats supported by the layer in question for GetFeatureInfo response 120 @ivar icon: A static image to be used for representing each station in the stationCollection in the GetMap response 121 @ivar dataSet: Name of the dataset to be used to construct an URL for the GetFeatureInfo response 122 @ivar dataSetURL: Server address part of the URL to be returned as a part of the GetFeatureInfo response 114 123 115 124 """ … … 119 128 self.abstract=abstract 120 129 self.crss=crss 121 self.legendSize=(30 ,100)130 self.legendSize=(300,60) 122 131 self.dimensions ={} 123 132 self.stationCollection = stationCollection … … 129 138 def getBBox(self, crs): 130 139 """ 131 @return: A 4-t yple of the bounding box in the given coordinate140 @return: A 4-tuple of the bounding box in the given coordinate 132 141 reference system. 133 142 """ … … 150 159 options 151 160 @return: An object implementing ILayerSlab 152 #create netcdf for whole lat/lon for given dimValues, use to init slab161 153 162 """ 154 163 bbox=self.getBBox(crs) … … 172 181 """ 173 182 Return a response string descibing the feature at a given 174 point in a given CRS. 183 point in a given CRS. 184 185 Currently only "html" is supported as output format 175 186 176 187 @param format: One of self.featureInfoFormats. Defines which … … 181 192 @param dimValues: A mapping of dimension names to dimansion values. 182 193 @return: A string containing the response. 183 194 184 195 """ 185 196 print point … … 187 198 188 199 print nearestStation.desc 189 fullURL = self.dataSetURL+'/list?dataset_id='+self.dataSet+'&station_name='+nearestStation.desc 190 fullURL = fullURL.replace(' ', '%20') 191 print fullURL 192 filehandle = urllib.urlopen(fullURL) 193 x = filehandle.read() 194 return x 195 200 201 202 responseURL = self.dataSetURL+'/list?dataset_id='+self.dataSet+'&station_name='+nearestStation.desc 203 # replace space characters in the URL with %20 to avoid any URL validation error on the client side 204 responseURL = responseURL.replace(' ', '%20') 205 print responseURL 206 #finally construct the response, in this case it is in HTML with the responseURL represented as a hyperlink in it 207 response = "Description: <em>"+nearestStation.desc+"</em><br /><a href='"+responseURL+"'>"+responseURL+"</a>" 208 return response 209 210 def getLegendImage(self, orientation='vertical', renderOpts={}): 211 """ 212 Create an image of the colourbar for this layer. 213 214 @param orientation: Either 'vertical' or 'horizontal' 215 @return: A PIL image 216 217 """ 218 width = self.legendSize[0] 219 height = self.legendSize[1] 220 # if width and height specified in the GetLegend request parameters 221 # then use them instead of the default values 222 if 'width' in renderOpts: 223 width = renderOpts['width'] 224 if 'height' in renderOpts: 225 height = renderOpts['height'] 226 renderer=PointRenderer() 227 legImage = Image.new('RGBA', (width, height), (0,0,0,0)) 228 # legend for stations without any associated dataset 229 withoutData = Image.open(self.icon) 230 # legend for stations that contain datasets 231 withData= Image.open(self.icon+'1') 232 legImage.paste(withoutData, (0,0)) 233 legImage.paste(renderer.txt2img(self.title+' without dataset', "helvB08.pil"),(30, 5) ) 234 legImage.paste(withData, (0, 30)) 235 legImage.paste(renderer.txt2img(self.title+' with dataset', "helvB08.pil"),(30, 35) ) 236 return legImage 196 237 197 238 class StationDimension(object): … … 247 288 print bbox 248 289 stationsInBbox = self.stationCollection.getStationsInBBox(bbox[1],bbox[0],bbox[3], bbox[2]) 249 print len(stationsInBbox)250 #print self.stationCollection.listAllLatLons()251 cmap=eval(config['colourmap']) # renderOpts is hook for colourmap, for now use config252 renderer=PointRenderer( 0.0, 3.0)290 291 292 cmap=eval(config['colourmap']) 293 renderer=PointRenderer() 253 294 return renderer.renderPoint(bbox, stationsInBbox, width, height, cmap,self.icon)
Note: See TracChangeset
for help on using the changeset viewer.