Exemple #1
0
 def test_best_srs_no_preferred(self, preferred):
     supported = SupportedSRS([SRS(4326), SRS(25832)], None)
     assert supported.best_srs(SRS(4326)) == SRS(4326)
     assert supported.best_srs(SRS(4258)) == SRS(4326)
     assert supported.best_srs(SRS(25832)) == SRS(25832)
     assert supported.best_srs(SRS(25831)) == SRS(25832)
     assert supported.best_srs(SRS(3857)) == SRS(25832)
Exemple #2
0
    def __init__(self, layers, extent, opacity=None, preferred_srs=None):
        MapLayer.__init__(self)
        self.srs_map = {}
        self.res_range = merge_layer_res_ranges([l[0] for l in layers])

        supported_srs = []
        for layer, srs in layers:
            supported_srs.append(srs)
            self.srs_map[srs] = layer
        self.supported_srs = SupportedSRS(supported_srs, preferred_srs)
        self.extent = extent
        self.opacity = opacity
Exemple #3
0
 def test_best_srs(self, preferred):
     supported = SupportedSRS([SRS(4326), SRS(25832)], preferred)
     assert supported.best_srs(SRS(4326)) == SRS(4326)
     assert supported.best_srs(SRS(4258)) == SRS(4326)
     assert supported.best_srs(SRS(25832)) == SRS(25832)
     assert supported.best_srs(SRS(25831)) == SRS(25832)
     assert supported.best_srs(SRS(3857)) == SRS(25832)
     supported = SupportedSRS(
         [SRS(4326), SRS(31467), SRS(25831)], preferred)
     assert supported.best_srs(SRS(3857)) == SRS(25831)
     assert supported.best_srs(SRS(25831)) == SRS(25831)
Exemple #4
0
 def __init__(self, request_template, supported_srs=None, http_client=None):
     self.request_template = request_template
     self.http_client = http_client or HTTPClient()
     if not supported_srs and self.request_template.params.srs is not None:
         supported_srs = SupportedSRS(
             [SRS(self.request_template.params.srs)])
     self.supported_srs = supported_srs
Exemple #5
0
 def source(self, mock_http_client):
     req_template = WMS111MapRequest(url='http://localhost/service?', param={
         'format': 'image/png', 'layers': 'foo'
     })
     client = WMSClient(req_template, http_client=mock_http_client)
     return WMSSource(client, supported_srs=SupportedSRS([SRS(4326)]),
         image_opts=ImageOptions(resampling='bilinear'))
    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=SupportedSRS([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=SupportedSRS([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)
Exemple #8
0
    def test_transformed_request_transparent(self, mock_http_client):
        req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo',
                                    param={'layers':'foo', 'transparent': 'true'})
        wms = WMSClient(req, http_client=mock_http_client)
        source = WMSSource(wms, supported_srs=SupportedSRS([SRS(4326)]),
            image_opts=ImageOptions(resampling='bilinear'))

        req = MapQuery((-200000, -200000, 200000, 200000), (512, 512), SRS(900913), 'png')
        resp = source.get_map(req)
        assert len(mock_http_client.requested) == 1

        assert wms_query_eq(mock_http_client.requested[0],
            TESTSERVER_URL+'/service?map=foo&LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                           '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326'
                           '&VERSION=1.1.1&WIDTH=512&STYLES=&transparent=true'
                           '&BBOX=-1.79663056824,-1.7963362121,1.79663056824,1.7963362121')
        img = resp.as_image()
        assert img.mode in ('P', 'RGBA')
        img = img.convert('RGBA')
        assert img.getpixel((5, 5))[3] == 0
Exemple #9
0
    def test_transform_fi_request_supported_srs(self):
        req = WMS111FeatureInfoRequest(url=TESTSERVER_URL + '/service?map=foo',
                                       param={'layers': 'foo'})
        http = MockHTTPClient()
        wms = WMSInfoClient(req,
                            http_client=http,
                            supported_srs=SupportedSRS([SRS(25832)]))
        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]
Exemple #10
0
class SRSConditional(MapLayer):
    supports_meta_tiles = True

    def __init__(self, layers, extent, opacity=None, preferred_srs=None):
        MapLayer.__init__(self)
        self.srs_map = {}
        self.res_range = merge_layer_res_ranges([l[0] for l in layers])

        supported_srs = []
        for layer, srs in layers:
            supported_srs.append(srs)
            self.srs_map[srs] = layer
        self.supported_srs = SupportedSRS(supported_srs, preferred_srs)
        self.extent = extent
        self.opacity = opacity

    def get_map(self, query):
        self.check_res_range(query)
        layer = self._select_layer(query.srs)
        return layer.get_map(query)

    def _select_layer(self, query_srs):
        srs = self.supported_srs.best_srs(query_srs)
        return self.srs_map[srs]
Exemple #11
0
 def source(self, mock_http_client):
     req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo', param={'layers':'foo'})
     wms = WMSClient(req, http_client=mock_http_client)
     return WMSSource(wms, supported_srs=SupportedSRS([SRS(4326)]),
         image_opts=ImageOptions(resampling='bilinear'))
Exemple #12
0
 def test_iter(self, preferred):
     supported = SupportedSRS([SRS(4326), SRS(25832)], preferred)
     assert [SRS(4326), SRS(25832)] == [srs for srs in supported]
Exemple #13
0
 def test_supported(self, preferred):
     supported = SupportedSRS([SRS(4326), SRS(25832)], preferred)
     assert SRS(4326) in supported
     assert SRS(4258) not in supported
     assert SRS(25832) in supported