def _get_transformed_query(self, query): """ Handle FI requests for unsupported SRS. """ req_srs = query.srs req_bbox = query.bbox req_coord = make_lin_transf((0, 0, query.size[0], query.size[1]), req_bbox)(query.pos) info_srs = self.supported_srs.best_srs(req_srs) info_bbox = req_srs.transform_bbox_to(info_srs, req_bbox) # calculate new info_size to keep square pixels after transform_bbox_to info_aratio = (info_bbox[3] - info_bbox[1]) / (info_bbox[2] - info_bbox[0]) info_size = query.size[0], int(info_aratio * query.size[0]) info_coord = req_srs.transform_to(info_srs, req_coord) info_pos = make_lin_transf( (info_bbox), (0, 0, info_size[0], info_size[1]))(info_coord) info_pos = int(round(info_pos[0])), int(round(info_pos[1])) info_query = InfoQuery( bbox=info_bbox, size=info_size, srs=info_srs, pos=info_pos, info_format=query.info_format, feature_count=query.feature_count, ) return info_query
def test_transform_fi_request(self): req = WMS111FeatureInfoRequest(url=TESTSERVER_URL + '/service?map=foo', param={'layers':'foo', 'srs': 'EPSG:25832'}) http = MockHTTPClient() wms = WMSInfoClient(req, http_client=http) fi_req = InfoQuery((8, 50, 9, 51), (512, 512), SRS(4326), (128, 64), 'text/plain') wms.get_info(fi_req) assert wms_query_eq(http.requested[0], TESTSERVER_URL+'/service?map=foo&LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng' '&REQUEST=GetFeatureInfo&SRS=EPSG%3A25832&info_format=text/plain' '&query_layers=foo' '&VERSION=1.1.1&WIDTH=512&HEIGHT=797&STYLES=&x=135&y=101' '&BBOX=428333.552496,5538630.70275,500000.0,5650300.78652'), http.requested[0]
def test_transform_fi_request_supported_srs(self): req = ArcGISIdentifyRequest(url=TESTSERVER_URL + '/MapServer/export?map=foo', param={'layers':'foo'}) http = MockHTTPClient() wms = ArcGISInfoClient(req, http_client=http, supported_srs=[SRS(25832)]) fi_req = InfoQuery((8, 50, 9, 51), (512, 512), SRS(4326), (128, 64), 'text/plain') wms.get_info(fi_req) assert_query_eq(http.requested[0], TESTSERVER_URL+'/MapServer/identify?map=foo' '&imageDisplay=512,797,96&sr=25832&f=json' '&layers=foo&tolerance=5&returnGeometry=false' '&geometryType=esriGeometryPoint&geometry=447229.979084,5636149.370634' '&mapExtent=428333.552496,5538630.70275,500000.0,5650300.78652', fuzzy_number_compare=True)
def test_fi_request(self): req = ArcGISIdentifyRequest(url=TESTSERVER_URL + '/MapServer/export?map=foo', param={'layers':'foo'}) http = MockHTTPClient() wms = ArcGISInfoClient(req, http_client=http, supported_srs=[SRS(4326)]) fi_req = InfoQuery((8, 50, 9, 51), (512, 512), SRS(4326), (128, 64), 'text/plain') wms.get_info(fi_req) assert_query_eq(http.requested[0], TESTSERVER_URL+'/MapServer/identify?map=foo' '&imageDisplay=512,512,96&sr=4326&f=json' '&layers=foo&tolerance=5&returnGeometry=false' '&geometryType=esriGeometryPoint&geometry=8.250000,50.875000' '&mapExtent=8,50,9,51', fuzzy_number_compare=True)
def featureinfo(self, request): infos = [] self.check_request(request, self.info_formats) tile_layer = self.layers[request.layer][request.tilematrixset] if not request.format: request.format = tile_layer.format bbox = tile_layer.grid.tile_bbox(request.tile) query = InfoQuery( bbox, tile_layer.grid.tile_size, tile_layer.grid.srs, request.pos, request.infoformat, ) self.check_request_dimensions(tile_layer, request) coverage = self.authorize_tile_layer(tile_layer, request, featureinfo=True) if not tile_layer.info_sources: raise RequestError('layer %s not queryable' % str(request.layer), code='OperationNotSupported', request=request) if coverage and not coverage.contains(query.coord, query.srs): infos = [] else: for source in tile_layer.info_sources: info = source.get_info(query) if info is None: continue infos.append(info) mimetype = request.infoformat if not infos: return Response('', mimetype=mimetype) resp, _ = combine_docs(infos) return Response(resp, mimetype=mimetype)
def _get_transformed_query(self, query): """ Handle FI requests for unsupported SRS. """ req_srs = query.srs req_bbox = query.bbox info_srs = self._best_supported_srs(req_srs) info_bbox = req_srs.transform_bbox_to(info_srs, req_bbox) req_coord = make_lin_transf((0, query.size[1], query.size[0], 0), req_bbox)(query.pos) info_coord = req_srs.transform_to(info_srs, req_coord) info_pos = make_lin_transf( (info_bbox), (0, query.size[1], query.size[0], 0))(info_coord) info_query = InfoQuery(info_bbox, query.size, info_srs, info_pos, query.info_format) return info_query
def _get_transformed_query(self, query): """ Handle FI requests for unsupported SRS. """ req_srs = query.srs req_bbox = query.bbox info_srs = self._best_supported_srs(req_srs) info_bbox = req_srs.transform_bbox_to(info_srs, req_bbox) req_coord = make_lin_transf((0, query.size[1], query.size[0], 0), req_bbox)(query.pos) info_coord = req_srs.transform_to(info_srs, req_coord) info_pos = make_lin_transf((info_bbox), (0, query.size[1], query.size[0], 0))(info_coord) info_pos = int(round(info_pos[0])), int(round(info_pos[1])) info_query = InfoQuery( bbox=info_bbox, size=query.size, srs=info_srs, pos=info_pos, info_format=query.info_format, feature_count=query.feature_count, ) return info_query
def featureinfo(self, request): infos = [] self.check_featureinfo_request(request) p = request.params query = InfoQuery(p.bbox, p.size, SRS(p.srs), p.pos, p['info_format'], format=request.params.format or None, feature_count=p.get('feature_count')) actual_layers = odict() for layer_name in request.params.query_layers: layer = self.layers[layer_name] if not layer.queryable: raise RequestError('layer %s is not queryable' % layer_name, request=request) for layer_name, info_layers in layer.info_layers_for_query(query): actual_layers[layer_name] = info_layers authorized_layers, coverage = self.authorized_layers( 'featureinfo', actual_layers.keys(), request.http.environ, query_extent=(query.srs.srs_code, query.bbox)) self.filter_actual_layers(actual_layers, request.params.layers, authorized_layers) # outside of auth-coverage if coverage and not coverage.contains(query.coord, query.srs): infos = [] else: info_layers = [] for layers in actual_layers.values(): info_layers.extend(layers) for layer in info_layers: info = layer.get_info(query) if info is None: continue infos.append(info) mimetype = None if 'info_format' in request.params: mimetype = request.params.info_format if not infos: return Response('', mimetype=mimetype) if self.fi_transformers: doc = infos[0].combine(infos) if doc.info_type == 'text': resp = doc.as_string() mimetype = 'text/plain' else: if not mimetype: if 'xml' in self.fi_transformers: info_type = 'xml' elif 'html' in self.fi_transformers: info_type = 'html' else: info_type = 'text' mimetype = mimetype_from_infotype(request.version, info_type) else: info_type = infotype_from_mimetype(request.version, mimetype) resp = self.fi_transformers[info_type](doc).as_string() else: mimetype = mimetype_from_infotype(request.version, infos[0].info_type) if len(infos) > 1: resp = infos[0].combine(infos).as_string() else: resp = infos[0].as_string() return Response(resp, mimetype=mimetype)
def test_coord(self): query = InfoQuery((8, 50, 9, 51), (400, 1000), SRS(4326), (100, 600), 'text/plain') eq_(query.coord, (8.25, 50.4))
def test_coord(self): query = InfoQuery( (8, 50, 9, 51), (400, 1000), SRS(4326), (100, 600), "text/plain" ) assert query.coord == (8.25, 50.4)