def _CheckParameters(self, parameters, required_param_names): self._EnsureRequiredParameters(parameters, required_param_names) # presence is established - now we're looking in more detail. lite_checkers = { # version already checked by this point # request already checked by this point # layers 'styles': self._CheckStyles, 'crs': self._CheckCrs, 'srs': self._CheckSrs, 'bbox': self._CheckBbox, 'width': self._CheckWidth, 'height': self._CheckHeight, # format } for name, checker in lite_checkers.iteritems(): parameter_value = utils.GetValue(parameters, name) checker(parameter_value) layers_text = utils.GetValue(parameters, 'layers') self._CheckLayers(layers_text) # format depends on layer too much to be standalone, ie 'lite'. server_layers_by_name = self.parameters['server-obj'].getLayers() layer_name = WmsGetMapRequest._ExtractLayerName(layers_text) requested_layer_obj = server_layers_by_name[layer_name] self._CheckFormat(utils.GetValue(parameters, 'format'), requested_layer_obj)
def ExtGetHandler(self, handler): """Service a GET request to the /ext/... pathway.""" parameters = dict([(k, v[0]) for k, v in handler.request.arguments.iteritems()]) print 'wms params:', parameters request = handler.request print 'TIDY REQUEST:', (request.protocol, request.host, request.path, request.uri) # endpoint is: # http://localhost/cgi-bin/ogc/service.py # ie everything before the '?' print 'joined:', os.path.join(request.host, request.path) parameters['this-endpoint'] = (request.protocol + '://' + os.path.join(request.host, 'maps')) print 'get url?' url = utils.GetValue(parameters, 'url') or parameters['this-endpoint'] print 'url:[%s]' % url parameters['server-obj'] = gee.PortableServer(url) print 'made server - gen response?' status, header_pairs, output = wms.GenerateResponse(parameters) print 'supposedly generated the response' handler.set_status(status) for header_pair in header_pairs: handler.add_header(header_pair[0], header_pair[1]) handler.write(output) # not sure whether needed. handler.flush()
def _ProcessCommon(self): """Processes the GetMapRequest parameters and prepares the GEE tile URL. Returns: Nothing, but might raise a ServiceException of the right version. """ utils.logger.debug('wms.GetMapRequest._processCommon') self._CheckParameters(self.parameters, self.required_param_names) server_layers_by_name = self.parameters['server-obj'].getLayers() utils.logger.debug('find the target layer') # We only handle a single layer at a time (jeffdonner is not sure # what handling multiple ones would mean - compositing them per # STYLES perhaps? Sending them in sequence, somehow?) # Here we don't balk or warn at a list, we just silently send the # first item. layer_name = WmsGetMapRequest._ExtractLayerName( utils.GetValue(self.parameters, 'layers')) # By this point we know it's there. self.requested_layer_obj = server_layers_by_name[layer_name] utils.logger.debug('target layer: ' + layer_name) bbox_text = utils.GetValue(self.parameters, 'bbox') coords = bbox_text.split(',') self.user_log_rect = geom.Rect(float(coords[0]), float(coords[1]), float(coords[2]), float(coords[3])) # We should by rights check that CRS/SRS matches the layer's, but # we don't because (at least in jeffdonner's experience with # 'uppermidwest.map') we have to let MapServer feed us ones we # don't support in order to work with it. Luckily MapServer # produces the right result despite this confusion. # TODO: nice-to-have: add format flexibility (raster -> # png, vectorrastermap -> jpg) since PIL can transform them. At # least, ImageMaps could be png. self.user_width = int(utils.GetValue(self.parameters, 'width')) self.user_height = int(utils.GetValue(self.parameters, 'height')) utils.logger.debug('done')
def _EnsureRequiredParameters(self, parameters, required_param_names): """Mechanically produces a ServiceException if a required parm. is missing. Args: parameters: the (enhanced) parameters passed in via the url. required_param_names: list or set of required parameter names. """ for reqd in required_param_names: if utils.GetValue(parameters, reqd) is None: error_message = 'Missing required parameter: \'%s\'' % reqd utils.logger.debug(error_message) self._ServiceException(None, error_message)