def test_srs_match(self): assert self.layer._select_layer(SRS(4326)) == self.l4326 assert self.layer._select_layer(SRS(900913)) == self.l900913 assert self.layer._select_layer(SRS(31467)) == self.l900913
def setup(self): self.res = [1000.0, 500.0, 200.0, 100.0, 50.0, 20.0, 5.0] bbox = (3250000, 5230000, 3930000, 6110000) self.grid = TileGrid(SRS(31467), bbox=bbox, res=self.res)
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_tile_size(self): g1 = tile_grid(SRS(4326), tile_size=(128, 128)) g2 = tile_grid(SRS(4326)) assert not g1.is_subset_of(g2)
def setup(self): self.grid = TileGrid(SRS(31467), bbox=(3250000, 5230000, 3930000, 6110000))
def test_less_levels(self): g1 = tile_grid(SRS(3857), num_levels=10) g2 = tile_grid(SRS(3857)) assert g1.is_subset_of(g2)
def test_subbbox(self): g2 = tile_grid(SRS(4326)) g1 = tile_grid(SRS(4326), num_levels=10, min_res=g2.resolutions[3], bbox=(0, 0, 180, 90)) assert g1.is_subset_of(g2)
def test_resolution_low_projected(self): self.layer.get_map(MapQuery((0, 0, 10000, 10000), (100, 100), SRS(31467))) assert self.l900913.requested
def setup(self): self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90]) self.client = MockTileClient() self.source = TiledSource(self.grid, self.client)
def test_resolution_high_4326(self): self.layer.get_map(MapQuery((0, 0, 0.0001, 0.0001), (100, 100), SRS(4326))) assert self.direct.requested
def test_resolution_low_4326(self): self.layer.get_map(MapQuery((0, 0, 10, 10), (100, 100), SRS(4326))) assert self.l4326.requested
def test_resolution_high_900913(self): self.layer.get_map(MapQuery((0, 0, 100, 100), (100, 100), SRS(900913))) assert self.direct.requested
def test_no_match_first_type(self): assert self.layer._select_layer(SRS(4258)) == self.l4326
def test_srs_match_type(self): assert self.layer._select_layer(SRS(31466)) == self.l32632 assert self.layer._select_layer(SRS(32633)) == self.l32632
def test_same_grid(self): g1 = tile_grid(SRS(900913)) assert g1.is_subset_of(g1)
def test_match(self): self.source.get_map(MapQuery([-180, -90, 0, 90], (256, 256), SRS(4326))) self.source.get_map(MapQuery([0, -90, 180, 90], (256, 256), SRS(4326))) eq_(self.client.requested_tiles, [(0, 0, 1), (1, 0, 1)])
def test_similar_srs(self): g1 = tile_grid(SRS(900913)) g2 = tile_grid(SRS(3857)) assert g1.is_subset_of(g2)
def test_epsg4326(self): srs = SRS(4326) assert srs.is_latlong assert not srs.is_axis_order_en assert srs.is_axis_order_ne
def test_more_levels(self): g1 = tile_grid(SRS(3857)) g2 = tile_grid(SRS(3857), num_levels=10) assert not g1.is_subset_of(g2)
def test_epsg31467(self): srs = SRS('EPSG:31467') assert not srs.is_latlong assert not srs.is_axis_order_en assert srs.is_axis_order_ne
def test_incompatible_subbbox(self): g2 = tile_grid(SRS(4326)) g1 = tile_grid(SRS(4326), min_res=g2.resolutions[3], num_levels=10, bbox=(-10, 0, 180, 90)) assert not g1.is_subset_of(g2)
def test_epsg900913(self): srs = SRS('epsg:900913') assert not srs.is_latlong assert srs.is_axis_order_en assert not srs.is_axis_order_ne
def test_no_tile_errors(self): # g1 is not a subset, check that we don't get any NoTile errors g1 = tile_grid(SRS(3857), res=[100000, 50000, 10000, 1000, 100, 10, 1, 0.5]) g2 = tile_grid(SRS(3857), res=[100, 1]) assert not g1.is_subset_of(g2)
def test_from_srs(self): srs1 = SRS('epgs:4326') srs2 = SRS(srs1) assert srs1 == srs2
def setup(self): self.grid = TileGrid(SRS(31467), bbox=(3300000, 5300000, 3900000, 6000000), origin='ul', res=[1500, 1000, 500, 300, 150, 100])
def setup(self): self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90]) self.client = TileClient(TileURLTemplate(TESTSERVER_URL))
def export_command(args=None): parser = optparse.OptionParser("%prog export [options] mapproxy_conf") parser.add_option("-f", "--mapproxy-conf", dest="mapproxy_conf", help="MapProxy configuration") parser.add_option( "-q", "--quiet", action="count", dest="quiet", default=0, help= "reduce number of messages to stdout, repeat to disable progress output" ) parser.add_option("--source", dest="source", help="source to export (source or cache)") parser.add_option( "--grid", help="grid for export. either the name of an existing grid or " "the grid definition as a string") parser.add_option("--dest", help="destination of the export (directory or filename)") parser.add_option("--type", help="type of the export format") parser.add_option("--levels", help="levels to export: e.g 1,2,3 or 1..10") parser.add_option( "--fetch-missing-tiles", dest="fetch_missing_tiles", action='store_true', default=False, help="if missing tiles should be fetched from the sources") parser.add_option( "--force", action='store_true', default=False, help="overwrite/append to existing --dest files/directories") parser.add_option("-n", "--dry-run", action="store_true", default=False, help="do not export, just print output") parser.add_option("-c", "--concurrency", type="int", dest="concurrency", default=1, help="number of parallel export processes") parser.add_option( "--coverage", help="the coverage for the export as a BBOX string, WKT file " "or OGR datasource") parser.add_option("--srs", help="the SRS of the coverage") parser.add_option("--where", help="filter for OGR coverages") from mapproxy.script.util import setup_logging import logging setup_logging(logging.WARN) if args: args = args[1:] # remove script name (options, args) = parser.parse_args(args) if not options.mapproxy_conf: if len(args) != 1: parser.print_help() sys.exit(1) else: options.mapproxy_conf = args[0] required_options = ['mapproxy_conf', 'grid', 'source', 'dest', 'levels'] for required in required_options: if not getattr(options, required): print('ERROR: missing required option --%s' % required.replace('_', '-'), file=sys.stderr) parser.print_help() sys.exit(1) try: conf = load_configuration(options.mapproxy_conf) except IOError as e: print('ERROR: ', "%s: '%s'" % (e.strerror, e.filename), file=sys.stderr) sys.exit(2) except ConfigurationError as e: print(e, file=sys.stderr) print('ERROR: invalid configuration (see above)', file=sys.stderr) sys.exit(2) if '=' in options.grid: try: grid_conf = parse_grid_definition(options.grid) except ValidationError as ex: print('ERROR: invalid grid configuration', file=sys.stderr) for error in ex.errors: print(' ', error, file=sys.stderr) sys.exit(2) except ValueError: print('ERROR: invalid grid configuration', file=sys.stderr) sys.exit(2) options.grid = 'tmp_mapproxy_export_grid' grid_conf['name'] = options.grid custom_grid = True conf.grids[options.grid] = GridConfiguration(grid_conf, conf) else: custom_grid = False if os.path.exists(options.dest) and not options.force: print('ERROR: destination exists, remove first or use --force', file=sys.stderr) sys.exit(2) cache_conf = { 'name': 'export', 'grids': [options.grid], 'sources': [options.source], } if options.type == 'mbtile': cache_conf['cache'] = { 'type': 'mbtiles', 'filename': options.dest, } elif options.type == 'sqlite': cache_conf['cache'] = { 'type': 'sqlite', 'directory': options.dest, } elif options.type == 'geopackage': cache_conf['cache'] = { 'type': 'geopackage', 'filename': options.dest, } elif options.type == 'compact-v1': cache_conf['cache'] = { 'type': 'compact', 'version': 1, 'directory': options.dest, } elif options.type == 'compact-v2': cache_conf['cache'] = { 'type': 'compact', 'version': 2, 'directory': options.dest, } elif options.type in ('tc', 'mapproxy'): cache_conf['cache'] = { 'type': 'file', 'directory': options.dest, } elif options.type == 'arcgis': cache_conf['cache'] = { 'type': 'file', 'directory_layout': 'arcgis', 'directory': options.dest, } elif options.type in ('tms', None): # default cache_conf['cache'] = { 'type': 'file', 'directory_layout': 'tms', 'directory': options.dest, } else: print('ERROR: unsupported --type %s' % (options.type, ), file=sys.stderr) sys.exit(2) if not options.fetch_missing_tiles: for source in conf.sources.values(): source.conf['seed_only'] = True tile_grid, extent, mgr = CacheConfiguration(cache_conf, conf).caches()[0] levels = parse_levels(options.levels) if levels[-1] >= tile_grid.levels: print('ERROR: destination grid only has %d levels' % tile_grid.levels, file=sys.stderr) sys.exit(2) if options.srs: srs = SRS(options.srs) else: srs = tile_grid.srs if options.coverage: seed_coverage = load_coverage( { 'datasource': options.coverage, 'srs': srs, 'where': options.where }, base_path=os.getcwd()) else: seed_coverage = BBOXCoverage(tile_grid.bbox, tile_grid.srs) if not supports_tiled_access(mgr): print( 'WARN: grids are incompatible. needs to scale/reproject tiles for export.', file=sys.stderr) md = dict(name='export', cache_name='cache', grid_name=options.grid, dest=options.dest) task = SeedTask(md, mgr, levels, 1, seed_coverage) print(format_export_task(task, custom_grid=custom_grid)) logger = ProgressLog(verbose=options.quiet == 0, silent=options.quiet >= 2) try: seed_task(task, progress_logger=logger, dry_run=options.dry_run, concurrency=options.concurrency) except KeyboardInterrupt: print('stopping...', file=sys.stderr) sys.exit(2)
def test_different_srs(self): g1 = tile_grid(SRS(4326)) g2 = tile_grid(SRS(3857)) assert not g1.is_subset_of(g2)
class TestCombinedLayers(object): q = MapQuery((0, 0, 10000, 10000), (100, 100), SRS(3857)) def test_empty(self): eq_(combined_layers([], self.q), []) def test_same_source(self): layers = [ WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'a' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'b' }, {}))), ] combined = combined_layers(layers, self.q) eq_(len(combined), 1) eq_(combined[0].client.request_template.params.layers, ['a', 'b']) def test_mixed_hosts(self): layers = [ WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'a' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'b' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://bar/', 'layers': 'c' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://bar/', 'layers': 'd' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'e' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'f' }, {}))), ] combined = combined_layers(layers, self.q) eq_(len(combined), 3) eq_(combined[0].client.request_template.params.layers, ['a', 'b']) eq_(combined[1].client.request_template.params.layers, ['c', 'd']) eq_(combined[2].client.request_template.params.layers, ['e', 'f']) def test_mixed_params(self): layers = [ WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'a' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'b' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'c' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'd' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'e' }, {}))), WMSSource( WMSClient( create_request({ 'url': 'http://foo/', 'layers': 'f' }, {}))), ] layers[0].supported_srs = ["EPSG:4326"] layers[1].supported_srs = ["EPSG:4326"] layers[2].supported_formats = ["image/png"] layers[3].supported_formats = ["image/png"] combined = combined_layers(layers, self.q) eq_(len(combined), 3) eq_(combined[0].client.request_template.params.layers, ['a', 'b']) eq_(combined[1].client.request_template.params.layers, ['c', 'd']) eq_(combined[2].client.request_template.params.layers, ['e', 'f'])
def test_resolution_high_transform(self): self.layer.get_map(MapQuery((0, 0, 0.005, 0.005), (100, 100), SRS(4326))) assert not self.low.requested assert self.high.requested