Untitled diff

बनाया गया Diff कभी समाप्त नहीं होता
0 हटाए गए
168 लाइनें
20 जोड़े गए
186 लाइनें
# This file is part of the MapProxy project.
# This file is part of the MapProxy project.
# Copyright (C) 2010 Omniscale <http://omniscale.de>
# Copyright (C) 2010 Omniscale <http://omniscale.de>
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
import math
from mapproxy.client.http import retrieve_image
from mapproxy.client.http import retrieve_image
class TMSClient(object):
class TMSClient(object):
def __init__(self, url, format='png', http_client=None):
def __init__(self, url, format='png', http_client=None):
self.url = url
self.url = url
self.http_client = http_client
self.http_client = http_client
self.format = format
self.format = format
def get_tile(self, tile_coord, format=None):
def get_tile(self, tile_coord, format=None):
x, y, z = tile_coord
x, y, z = tile_coord
url = '%s/%d/%d/%d.%s' % (self.url, z, x, y, format or self.format)
url = '%s/%d/%d/%d.%s' % (self.url, z, x, y, format or self.format)
if self.http_client:
if self.http_client:
return self.http_client.open_image(url)
return self.http_client.open_image(url)
else:
else:
return retrieve_image(url)
return retrieve_image(url)
def __repr__(self):
def __repr__(self):
return '%s(%r, %r)' % (self.__class__.__name__, self.url, self.format)
return '%s(%r, %r)' % (self.__class__.__name__, self.url, self.format)
class TileClient(object):
class TileClient(object):
def __init__(self, url_template, http_client=None, grid=None):
def __init__(self, url_template, http_client=None, grid=None):
self.url_template = url_template
self.url_template = url_template
self.http_client = http_client
self.http_client = http_client
self.grid = grid
self.grid = grid
def get_tile(self, tile_coord, format=None):
def get_tile(self, tile_coord, format=None):
url = self.url_template.substitute(tile_coord, format, self.grid)
url = self.url_template.substitute(tile_coord, format, self.grid)
if self.http_client:
if self.http_client:
return self.http_client.open_image(url)
return self.http_client.open_image(url)
else:
else:
return retrieve_image(url)
return retrieve_image(url)
def __repr__(self):
def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.url_template)
return '%s(%r)' % (self.__class__.__name__, self.url_template)
class TileURLTemplate(object):
class TileURLTemplate(object):
"""
"""
>>> t = TileURLTemplate('http://foo/tiles/%(z)s/%(x)d/%(y)s.png')
>>> t = TileURLTemplate('http://foo/tiles/%(z)s/%(x)d/%(y)s.png')
>>> t.substitute((7, 4, 3))
>>> t.substitute((7, 4, 3))
'http://foo/tiles/3/7/4.png'
'http://foo/tiles/3/7/4.png'
>>> t = TileURLTemplate('http://foo/tiles/%(z)s/%(x)d/%(y)s.png')
>>> t = TileURLTemplate('http://foo/tiles/%(z)s/%(x)d/%(y)s.png')
>>> t.substitute((7, 4, 3))
>>> t.substitute((7, 4, 3))
'http://foo/tiles/3/7/4.png'
'http://foo/tiles/3/7/4.png'
>>> t = TileURLTemplate('http://foo/tiles/%(tc_path)s.png')
>>> t = TileURLTemplate('http://foo/tiles/%(tc_path)s.png')
>>> t.substitute((7, 4, 3))
>>> t.substitute((7, 4, 3))
'http://foo/tiles/03/000/000/007/000/000/004.png'
'http://foo/tiles/03/000/000/007/000/000/004.png'
>>> t = TileURLTemplate('http://foo/tms/1.0.0/%(tms_path)s.%(format)s')
>>> t = TileURLTemplate('http://foo/tms/1.0.0/%(tms_path)s.%(format)s')
>>> t.substitute((7, 4, 3))
>>> t.substitute((7, 4, 3))
'http://foo/tms/1.0.0/3/7/4.png'
'http://foo/tms/1.0.0/3/7/4.png'
>>> t = TileURLTemplate('http://foo/tms/1.0.0/lyr/%(tms_path)s.%(format)s')
>>> t = TileURLTemplate('http://foo/tms/1.0.0/lyr/%(tms_path)s.%(format)s')
>>> t.substitute((7, 4, 3), 'jpeg')
>>> t.substitute((7, 4, 3), 'jpeg')
'http://foo/tms/1.0.0/lyr/3/7/4.jpeg'
'http://foo/tms/1.0.0/lyr/3/7/4.jpeg'
"""
"""
def __init__(self, template, format='png'):
def __init__(self, template, format='png'):
self.template= template
self.template= template
self.format = format
self.format = format
self.with_quadkey = True if '%(quadkey)' in template else False
self.with_quadkey = True if '%(quadkey)' in template else False
self.with_tc_path = True if '%(tc_path)' in template else False
self.with_tc_path = True if '%(tc_path)' in template else False
self.with_tms_path = True if '%(tms_path)' in template else False
self.with_tms_path = True if '%(tms_path)' in template else False
self.with_arcgiscache_path = True if '%(arcgiscache_path)' in template else False
self.with_arcgiscache_path = True if '%(arcgiscache_path)' in template else False
self.with_google_static = True if '%(google_static_params)' in template else False
self.with_bbox = True if '%(bbox)' in template else False
self.with_bbox = True if '%(bbox)' in template else False
def substitute(self, tile_coord, format=None, grid=None):
def substitute(self, tile_coord, format=None, grid=None):
x, y, z = tile_coord
x, y, z = tile_coord
data = dict(x=x, y=y, z=z)
data = dict(x=x, y=y, z=z)
data['format'] = format or self.format
data['format'] = format or self.format
if self.with_quadkey:
if self.with_quadkey:
data['quadkey'] = quadkey(tile_coord)
data['quadkey'] = quadkey(tile_coord)
if self.with_tc_path:
if self.with_tc_path:
data['tc_path'] = tilecache_path(tile_coord)
data['tc_path'] = tilecache_path(tile_coord)
if self.with_tms_path:
if self.with_tms_path:
data['tms_path'] = tms_path(tile_coord)
data['tms_path'] = tms_path(tile_coord)
if self.with_arcgiscache_path:
if self.with_arcgiscache_path:
data['arcgiscache_path'] = arcgiscache_path(tile_coord)
data['arcgiscache_path'] = arcgiscache_path(tile_coord)
if self.with_google_static:
data['google_static_params'] = google_static(tile_coord,grid)
if self.with_bbox:
if self.with_bbox:
data['bbox'] = bbox(tile_coord, grid)
data['bbox'] = bbox(tile_coord, grid)
return self.template % data
return self.template % data