当前位置: 首页>>代码示例>>Python>>正文


Python wms.WMSSource类代码示例

本文整理汇总了Python中mapproxy.source.wms.WMSSource的典型用法代码示例。如果您正苦于以下问题:Python WMSSource类的具体用法?Python WMSSource怎么用?Python WMSSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WMSSource类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestWMSSourceWithClient

class TestWMSSourceWithClient(object):
    def setup(self):
        self.req_template = WMS111MapRequest(
            url='http://%s:%d/service?' % TEST_SERVER_ADDRESS,
            param={'format': 'image/png', 'layers': 'foo'})
        self.client = WMSClient(self.req_template)
        self.source = WMSSource(self.client)
    
    def test_get_map(self):
        with tmp_image((512, 512)) as img:
            expected_req = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                                     '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326&styles='
                                     '&VERSION=1.1.1&BBOX=0.0,10.0,10.0,20.0&WIDTH=512'},
                           {'body': img.read(), 'headers': {'content-type': 'image/png'}})
            with mock_httpd(TEST_SERVER_ADDRESS, [expected_req]):
                q = MapQuery((0.0, 10.0, 10.0, 20.0), (512, 512), SRS(4326))
                result = self.source.get_map(q)
                assert isinstance(result, ImageSource)
                eq_(result.size, (512, 512))
                assert is_png(result.as_buffer(seekable=True))
                eq_(result.as_image().size, (512, 512))
    def test_get_map_non_image_content_type(self):
        with tmp_image((512, 512)) as img:
            expected_req = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                                     '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326&styles='
                                     '&VERSION=1.1.1&BBOX=0.0,10.0,10.0,20.0&WIDTH=512'},
                           {'body': img.read(), 'headers': {'content-type': 'text/plain'}})
            with mock_httpd(TEST_SERVER_ADDRESS, [expected_req]):
                q = MapQuery((0.0, 10.0, 10.0, 20.0), (512, 512), SRS(4326))
                try:
                    self.source.get_map(q)
                except SourceError, e:
                    assert 'no image returned' in e.args[0]
                else:
                    assert False, 'no SourceError raised'
开发者ID:atrawog,项目名称:mapproxy,代码行数:35,代码来源:test_cache.py

示例2: TestWMSSourceTransform

class TestWMSSourceTransform(object):
    def setup(self):
        self.http_client = MockHTTPClient()
        self.req_template = WMS111MapRequest(
            url="http://localhost/service?", param={"format": "image/png", "layers": "foo"}
        )
        self.client = WMSClient(self.req_template, http_client=self.http_client)
        self.source = WMSSource(self.client, supported_srs=[SRS(4326)], image_opts=ImageOptions(resampling="bilinear"))

    def test_get_map(self):
        self.source.get_map(MapQuery((-180, -90, 180, 90), (300, 150), SRS(4326)))
        assert query_eq(
            self.http_client.requested[0],
            "http://localhost/service?"
            "layers=foo&width=300&version=1.1.1&bbox=-180,-90,180,90&service=WMS"
            "&format=image%2Fpng&styles=&srs=EPSG%3A4326&request=GetMap&height=150",
        )

    def test_get_map_transformed(self):
        self.source.get_map(MapQuery((556597, 4865942, 1669792, 7361866), (300, 150), SRS(900913)))
        assert wms_query_eq(
            self.http_client.requested[0],
            "http://localhost/service?"
            "layers=foo&width=300&version=1.1.1"
            "&bbox=4.99999592195,39.9999980766,14.999996749,54.9999994175&service=WMS"
            "&format=image%2Fpng&styles=&srs=EPSG%3A4326&request=GetMap&height=450",
        )
开发者ID:olt,项目名称:mapproxy,代码行数:27,代码来源:test_cache.py

示例3: create_wms_source

def create_wms_source(raster_source, app_state):
    url = raster_source.url
    username = raster_source.username
    password = raster_source.password

    http_client = create_http_client(username, password)

    coverage = coverage_from_geojson(raster_source.download_coverage)
    if coverage:
        # wrap to prevent partial tiles
        coverage = AlwaysContainsCoverage(coverage)

    request = create_request({'url': url, 'layers': raster_source.layer}, {}, version='1.1.1')

    image_opts = ImageOptions(resampling='bicubic',
        transparent=True)

    supported_srs = None
    if raster_source.srs != 'EPSG:3857':
        supported_srs = [SRS(raster_source.srs)]

    client = WMSClient(request, http_client=http_client)
    source = WMSSource(client, coverage=coverage,
        supported_srs=supported_srs, image_opts=image_opts,
    )

    # wrap to prevent partial tiles
    source.extent = AlwaysContainsMapExtent(source.extent)
    return source
开发者ID:omniscale,项目名称:gbi-client,代码行数:29,代码来源:mapproxyseed.py

示例4: TestWMSSourceWithClient

class TestWMSSourceWithClient(object):
    def setup(self):
        self.req_template = WMS111MapRequest(
            url='http://%s:%d/service?' % TEST_SERVER_ADDRESS,
            param={'format': 'image/png', 'layers': 'foo'})
        self.client = WMSClient(self.req_template)
        self.source = WMSSource(self.client)

    def test_get_map(self):
        with tmp_image((512, 512)) as img:
            expected_req = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                                     '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326&styles='
                                     '&VERSION=1.1.1&BBOX=0.0,10.0,10.0,20.0&WIDTH=512'},
                           {'body': img.read(), 'headers': {'content-type': 'image/png'}})
            with mock_httpd(TEST_SERVER_ADDRESS, [expected_req]):
                q = MapQuery((0.0, 10.0, 10.0, 20.0), (512, 512), SRS(4326))
                result = self.source.get_map(q)
                assert isinstance(result, ImageSource)
                eq_(result.size, (512, 512))
                assert is_png(result.as_buffer(seekable=True))
                eq_(result.as_image().size, (512, 512))
    def test_get_map_non_image_content_type(self):
        with tmp_image((512, 512)) as img:
            expected_req = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                                     '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326&styles='
                                     '&VERSION=1.1.1&BBOX=0.0,10.0,10.0,20.0&WIDTH=512'},
                           {'body': img.read(), 'headers': {'content-type': 'text/plain'}})
            with mock_httpd(TEST_SERVER_ADDRESS, [expected_req]):
                q = MapQuery((0.0, 10.0, 10.0, 20.0), (512, 512), SRS(4326))
                try:
                    self.source.get_map(q)
                except SourceError as e:
                    assert 'no image returned' in e.args[0]
                else:
                    assert False, 'no SourceError raised'
    def test_basic_auth(self):
        http_client = HTTPClient(self.req_template.url, username='foo', password='[email protected]')
        self.client.http_client = http_client
        def assert_auth(req_handler):
            assert 'Authorization' in req_handler.headers
            auth_data = req_handler.headers['Authorization'].split()[1]
            auth_data = base64.b64decode(auth_data.encode('utf-8')).decode('utf-8')
            eq_(auth_data, 'foo:[email protected]')
            return True
        expected_req = ({'path': r'/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                                  '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326'
                                  '&VERSION=1.1.1&BBOX=0.0,10.0,10.0,20.0&WIDTH=512&STYLES=',
                         'require_basic_auth': True,
                         'req_assert_function': assert_auth},
                        {'body': b'no image', 'headers': {'content-type': 'image/png'}})
        with mock_httpd(TEST_SERVER_ADDRESS, [expected_req]):
            q = MapQuery((0.0, 10.0, 10.0, 20.0), (512, 512), SRS(4326))
            self.source.get_map(q)
开发者ID:GeoDodo,项目名称:mapproxy,代码行数:53,代码来源:test_cache.py

示例5: setup

 def setup(self):
     self.http_client = MockHTTPClient()
     self.req_template = WMS111MapRequest(
         url="http://localhost/service?", param={"format": "image/png", "layers": "foo"}
     )
     self.client = WMSClient(self.req_template, http_client=self.http_client)
     self.source = WMSSource(self.client, supported_srs=[SRS(4326)], image_opts=ImageOptions(resampling="bilinear"))
开发者ID:olt,项目名称:mapproxy,代码行数:7,代码来源:test_cache.py

示例6: setup

 def setup(self):
     self.http_client = MockHTTPClient()
     self.req_template = WMS111MapRequest(url='http://localhost/service?', param={
         'format': 'image/png', 'layers': 'foo'
     })
     self.client = WMSClient(self.req_template, http_client=self.http_client)
     self.source = WMSSource(self.client, supported_srs=[SRS(4326)],
         image_opts=ImageOptions(resampling='bilinear'))
开发者ID:atrawog,项目名称:mapproxy,代码行数:8,代码来源:test_cache.py

示例7: test_similar_srs

 def test_similar_srs(self):
     # request in 3857 and source supports only 900913
     # 3857 and 900913 are equal but the client requests must use 900913
     self.req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo',
                                 param={'layers':'foo', 'transparent': 'true'})
     self.wms = WMSClient(self.req, http_client=self.http)
     self.source = WMSSource(self.wms, supported_srs=[SRS(900913)],
         image_opts=ImageOptions(resampling='bilinear'))
     req = MapQuery((-200000, -200000, 200000, 200000), (512, 512), SRS(3857), 'png')
     self.source.get_map(req)
     eq_(len(self.http.requested), 1)
     
     assert_query_eq(self.http.requested[0],
         TESTSERVER_URL+'/service?map=foo&LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                        '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A900913'
                        '&VERSION=1.1.1&WIDTH=512&STYLES=&transparent=true'
                        '&BBOX=-200000,-200000,200000,200000')
开发者ID:atrawog,项目名称:mapproxy,代码行数:17,代码来源:test_cache.py

示例8: test_transformed_request_transparent

    def test_transformed_request_transparent(self):
        self.req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo',
                                    param={'layers':'foo', 'transparent': 'true'})
        self.wms = WMSClient(self.req, http_client=self.http)
        self.source = WMSSource(self.wms, supported_srs=[SRS(4326)],
            image_opts=ImageOptions(resampling='bilinear'))

        req = MapQuery((-200000, -200000, 200000, 200000), (512, 512), SRS(900913), 'png')
        resp = self.source.get_map(req)
        eq_(len(self.http.requested), 1)
        
        assert_query_eq(self.http.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')
        eq_(img.getpixel((5, 5))[3], 0)
开发者ID:atrawog,项目名称:mapproxy,代码行数:20,代码来源:test_cache.py

示例9: test_transformed_request_transparent

    def test_transformed_request_transparent(self):
        self.req = WMS111MapRequest(
            url=TESTSERVER_URL + "/service?map=foo", param={"layers": "foo", "transparent": "true"}
        )
        self.wms = WMSClient(self.req, http_client=self.http)
        self.source = WMSSource(self.wms, supported_srs=[SRS(4326)], image_opts=ImageOptions(resampling="bilinear"))

        req = MapQuery((-200000, -200000, 200000, 200000), (512, 512), SRS(900913), "png")
        resp = self.source.get_map(req)
        eq_(len(self.http.requested), 1)

        assert wms_query_eq(
            self.http.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")
        eq_(img.getpixel((5, 5))[3], 0)
开发者ID:olt,项目名称:mapproxy,代码行数:22,代码来源:test_cache.py

示例10: TestWMSSource

class TestWMSSource(object):
    def setup(self):
        self.req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo', param={'layers':'foo'})
        self.http = MockHTTPClient()
        self.wms = WMSClient(self.req, http_client=self.http)
        self.source = WMSSource(self.wms, supported_srs=[SRS(4326)],
            image_opts=ImageOptions(resampling='bilinear'))
    def test_request(self):
        req = MapQuery((-180.0, -90.0, 180.0, 90.0), (512, 256), SRS(4326), 'png')
        self.source.get_map(req)
        eq_(len(self.http.requested), 1)
        assert_query_eq(self.http.requested[0],
            TESTSERVER_URL+'/service?map=foo&LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                           '&REQUEST=GetMap&HEIGHT=256&SRS=EPSG%3A4326'
                           '&VERSION=1.1.1&BBOX=-180.0,-90.0,180.0,90.0&WIDTH=512&STYLES=')

    def test_transformed_request(self):
        req = MapQuery((-200000, -200000, 200000, 200000), (512, 512), SRS(900913), 'png')
        resp = self.source.get_map(req)
        eq_(len(self.http.requested), 1)
        
        assert_query_eq(self.http.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='
                           '&BBOX=-1.79663056824,-1.7963362121,1.79663056824,1.7963362121')
        img = resp.as_image()
        assert img.mode in ('P', 'RGB')

    def test_similar_srs(self):
        # request in 3857 and source supports only 900913
        # 3857 and 900913 are equal but the client requests must use 900913
        self.req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo',
                                    param={'layers':'foo', 'transparent': 'true'})
        self.wms = WMSClient(self.req, http_client=self.http)
        self.source = WMSSource(self.wms, supported_srs=[SRS(900913)],
            image_opts=ImageOptions(resampling='bilinear'))
        req = MapQuery((-200000, -200000, 200000, 200000), (512, 512), SRS(3857), 'png')
        self.source.get_map(req)
        eq_(len(self.http.requested), 1)
        
        assert_query_eq(self.http.requested[0],
            TESTSERVER_URL+'/service?map=foo&LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng'
                           '&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A900913'
                           '&VERSION=1.1.1&WIDTH=512&STYLES=&transparent=true'
                           '&BBOX=-200000,-200000,200000,200000')

    def test_transformed_request_transparent(self):
        self.req = WMS111MapRequest(url=TESTSERVER_URL + '/service?map=foo',
                                    param={'layers':'foo', 'transparent': 'true'})
        self.wms = WMSClient(self.req, http_client=self.http)
        self.source = WMSSource(self.wms, supported_srs=[SRS(4326)],
            image_opts=ImageOptions(resampling='bilinear'))

        req = MapQuery((-200000, -200000, 200000, 200000), (512, 512), SRS(900913), 'png')
        resp = self.source.get_map(req)
        eq_(len(self.http.requested), 1)
        
        assert_query_eq(self.http.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')
        eq_(img.getpixel((5, 5))[3], 0)
开发者ID:atrawog,项目名称:mapproxy,代码行数:67,代码来源:test_cache.py

示例11: __init__

 def __init__(self, client, image_opts=None, coverage=None,
              supported_srs=None, supported_formats=None):
     WMSSource.__init__(self, client, image_opts=image_opts, coverage=coverage,
                        supported_srs=supported_srs, supported_formats=supported_formats)
开发者ID:,项目名称:,代码行数:4,代码来源:

示例12: TestWMSSourceWithClient

class TestWMSSourceWithClient(object):
    def setup(self):
        self.req_template = WMS111MapRequest(
            url="http://%s:%d/service?" % TEST_SERVER_ADDRESS, param={"format": "image/png", "layers": "foo"}
        )
        self.client = WMSClient(self.req_template)
        self.source = WMSSource(self.client)

    def test_get_map(self):
        with tmp_image((512, 512)) as img:
            expected_req = (
                {
                    "path": r"/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng"
                    "&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326&styles="
                    "&VERSION=1.1.1&BBOX=0.0,10.0,10.0,20.0&WIDTH=512"
                },
                {"body": img.read(), "headers": {"content-type": "image/png"}},
            )
            with mock_httpd(TEST_SERVER_ADDRESS, [expected_req]):
                q = MapQuery((0.0, 10.0, 10.0, 20.0), (512, 512), SRS(4326))
                result = self.source.get_map(q)
                assert isinstance(result, ImageSource)
                eq_(result.size, (512, 512))
                assert is_png(result.as_buffer(seekable=True))
                eq_(result.as_image().size, (512, 512))

    def test_get_map_non_image_content_type(self):
        with tmp_image((512, 512)) as img:
            expected_req = (
                {
                    "path": r"/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng"
                    "&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326&styles="
                    "&VERSION=1.1.1&BBOX=0.0,10.0,10.0,20.0&WIDTH=512"
                },
                {"body": img.read(), "headers": {"content-type": "text/plain"}},
            )
            with mock_httpd(TEST_SERVER_ADDRESS, [expected_req]):
                q = MapQuery((0.0, 10.0, 10.0, 20.0), (512, 512), SRS(4326))
                try:
                    self.source.get_map(q)
                except SourceError as e:
                    assert "no image returned" in e.args[0]
                else:
                    assert False, "no SourceError raised"

    def test_basic_auth(self):
        http_client = HTTPClient(self.req_template.url, username="foo", password="[email protected]")
        self.client.http_client = http_client

        def assert_auth(req_handler):
            assert "Authorization" in req_handler.headers
            auth_data = req_handler.headers["Authorization"].split()[1]
            auth_data = base64.b64decode(auth_data.encode("utf-8")).decode("utf-8")
            eq_(auth_data, "foo:[email protected]")
            return True

        expected_req = (
            {
                "path": r"/service?LAYERS=foo&SERVICE=WMS&FORMAT=image%2Fpng"
                "&REQUEST=GetMap&HEIGHT=512&SRS=EPSG%3A4326"
                "&VERSION=1.1.1&BBOX=0.0,10.0,10.0,20.0&WIDTH=512&STYLES=",
                "require_basic_auth": True,
                "req_assert_function": assert_auth,
            },
            {"body": b"no image", "headers": {"content-type": "image/png"}},
        )
        with mock_httpd(TEST_SERVER_ADDRESS, [expected_req]):
            q = MapQuery((0.0, 10.0, 10.0, 20.0), (512, 512), SRS(4326))
            self.source.get_map(q)
开发者ID:olt,项目名称:mapproxy,代码行数:69,代码来源:test_cache.py


注:本文中的mapproxy.source.wms.WMSSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。