def test_drop_label(self): from shapely.ops import transform from tilequeue.tile import reproject_mercator_to_lnglat import math import dsl thresholds = { 8: 200000000, 9: 100000000, 10: 10000000, 11: 4000000, 12: 750000, 13: 100000, 14: 50000, 15: 10000, } for zoom in range(8, 16): area = thresholds.get(zoom) radius = math.sqrt(area / math.pi) coord = 2 ** (zoom - 1) # larger feature should retain name shape = dsl.tile_centre_shape( zoom, coord, coord).buffer(radius * 1.1) shape_lnglat = transform( reproject_mercator_to_lnglat, shape) self.generate_fixtures( dsl.way(1, shape_lnglat, { 'natural': 'water', 'name': 'Foo', }), ) self.assert_has_feature( zoom, coord, coord, 'water', { 'kind': 'water', 'name': 'Foo', }) # smaller shape should drop it shape = dsl.tile_centre_shape( zoom, coord, coord).buffer(radius / 1.1) shape_lnglat = transform( reproject_mercator_to_lnglat, shape) self.generate_fixtures( dsl.way(1, shape_lnglat, { 'natural': 'water', 'name': 'Foo', }), ) self.assert_has_feature( zoom, coord, coord, 'water', { 'kind': 'water', 'name': type(None), })
def test_drop_label(self): from shapely.ops import transform from tilequeue.tile import reproject_mercator_to_lnglat import math import dsl thresholds = { 8: 200000000, 9: 100000000, 10: 10000000, 11: 4000000, 12: 750000, 13: 100000, 14: 50000, 15: 10000, } for zoom in range(8, 16): area = thresholds.get(zoom) radius = math.sqrt(area / math.pi) coord = 2**(zoom - 1) # larger feature should retain name shape = dsl.tile_centre_shape(zoom, coord, coord).buffer(radius * 1.1) shape_lnglat = transform(reproject_mercator_to_lnglat, shape) self.generate_fixtures( dsl.way(1, shape_lnglat, { 'natural': 'water', 'name': 'Foo', }), ) self.assert_has_feature(zoom, coord, coord, 'water', { 'kind': 'water', 'name': 'Foo', }) # smaller shape should drop it shape = dsl.tile_centre_shape(zoom, coord, coord).buffer(radius / 1.1) shape_lnglat = transform(reproject_mercator_to_lnglat, shape) self.generate_fixtures( dsl.way(1, shape_lnglat, { 'natural': 'water', 'name': 'Foo', }), ) self.assert_has_feature(zoom, coord, coord, 'water', { 'kind': 'water', 'name': type(None), })
def _check_rank(self, tags, zoom=16, source='openstreetmap.org', layer='pois', kind=None, rank=None, geom_type='point'): import dsl z, x, y = (zoom, 0, 0) all_tags = tags.copy() all_tags['source'] = source if 'name' not in all_tags: all_tags['name'] = 'Some name' assert geom_type in ('point', 'line', 'polygon') if geom_type == 'point': shape = dsl.tile_centre_shape(z, x, y) elif geom_type == 'line': shape = dsl.tile_diagonal(z, x, y) elif geom_type == 'polygon': shape = dsl.tile_box(z, x, y) self.generate_fixtures(dsl.way(1, shape, all_tags)) self.assert_has_feature(z, x, y, layer, { 'kind': kind, 'collision_rank': rank, })
def test_disputed_capital(self): import dsl z, x, y = 16, 0, 0 # a country capital which CN doesn't think is a country capital. this # is just a test case, and any resemblance to real disputes, living or # dead, is purely coincidental. self.generate_fixtures( dsl.way( 1, dsl.tile_centre_shape(z, x, y), { 'name': 'Foo', 'featurecla': 'Admin-0 capital', 'fclass_cn': 'Admin-1 capital', 'scalerank': 4, 'min_zoom': 4, 'source': 'naturalearthdata.com', }), ) self.assert_has_feature( z, x, y, 'places', { 'kind': 'locality', 'country_capital': type(True), 'country_capital:cn': type(False), 'region_capital:cn': type(True), })
def test_disputed_capital(self): import dsl z, x, y = 16, 0, 0 # a country capital which CN doesn't think is a country capital. this # is just a test case, and any resemblance to real disputes, living or # dead, is purely coincidental. self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), { 'name': 'Foo', 'featurecla': 'Admin-0 capital', 'fclass_cn': 'Admin-1 capital', 'scalerank': 4, 'min_zoom': 4, 'source': 'naturalearthdata.com', }), ) self.assert_has_feature( z, x, y, 'places', { 'kind': 'locality', 'country_capital': type(True), 'country_capital:cn': type(False), 'region_capital:cn': type(True), })
def append(self, tags={}, source='openstreetmap.org', layer='pois', geom_type='point'): import dsl all_tags = tags.copy() all_tags['source'] = source if 'name' not in all_tags: all_tags['name'] = 'Some name' assert geom_type in ('point', 'line', 'polygon') if geom_type == 'point': shape = dsl.tile_centre_shape(self.z, self.x, self.y) elif geom_type == 'line': shape = dsl.tile_diagonal(self.z, self.x, self.y) elif geom_type == 'polygon': shape = dsl.tile_box(self.z, self.x, self.y) item_fid = self.id_counter self.id_counter += 1 self.items.append(dsl.way(item_fid, shape, all_tags)) return item_fid
def _check_rank(self, tags, zoom=16, source='openstreetmap.org', layer='pois', kind=None, rank=None, geom_type='point'): import dsl z, x, y = (zoom, 0, 0) all_tags = tags.copy() all_tags['source'] = source if 'name' not in all_tags: all_tags['name'] = 'Some name' assert geom_type in ('point', 'line', 'polygon') if geom_type == 'point': shape = dsl.tile_centre_shape(z, x, y) elif geom_type == 'line': shape = dsl.tile_diagonal(z, x, y) elif geom_type == 'polygon': shape = dsl.tile_box(z, x, y) self.generate_fixtures(dsl.way(1, shape, all_tags)) self.assert_has_feature( z, x, y, layer, { 'kind': kind, 'collision_rank': rank, })
def test_new_york(self): import dsl z, x, y = (6, 18, 24) self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), { 'featurecla': u'Populated place', 'min_zoom': u'1.7', 'name': u'New York', 'name_ar': u'نيويورك', 'name_bn': u'নিউ ইয়র্ক সিটি', 'name_de': u'New York City', 'name_el': u'Νέα Υόρκη', 'name_en': u'New York City', 'name_es': u'Nueva York', 'name_fr': u'New York', 'name_hi': u'न्यूयॉर्क नगर', 'name_hu': u'New York', 'name_id': u'New York City', 'name_it': u'New York', 'name_ja': u'ニューヨーク', 'name_ko': u'뉴욕', 'name_nl': u'New York City', 'name_pl': u'Nowy Jork', 'name_pt': u'Nova Iorque', 'name_ru': u'Нью-Йорк', 'name_sv': u'New York', 'name_tr': u'New York', 'name_vi': u'Thành phố New York', 'name_zh': u'纽约', 'namealt': u'New York-Newark', 'nameascii': u'New York', 'namediff': u'0', 'namepar': u'', 'ne_id': u'1159151575', 'scalerank': 0, 'source': u'naturalearthdata.com', 'wikidataid': u'Q60', 'wof_id': u'85977539', 'worldcity': u'1.0', }), ) self.assert_has_feature( z, x, y, 'places', { 'id': 1, 'name': u'New York', 'name:en': u'New York City', 'name:el': u'Νέα Υόρκη', 'name:es': u'Nueva York', })
def test_zoom_1(self): import dsl z, x, y = (3, 7, 3) self.generate_fixtures( dsl.way(607976629, dsl.tile_centre_shape(z, x, y), { "min_zoom": 1, "__ne_max_zoom": 10, "__ne_min_zoom": 3, "area": 0, "place": "country", "name": "Guam", "population": 185427, "source": "openstreetmap.org", }), ) # should exist at zoom 3 (the min zoom from NE) self.assert_has_feature( z, x, y, 'places', { 'id': 607976629, 'kind': 'country', 'name': 'Guam', }) # should not exist at zoom 2 (one past the min zoom) self.assert_no_matching_feature( z-1, x//2, y//2, 'places', { 'id': 607976629 }) # should not exist at zoom 1 self.assert_no_matching_feature( z-2, x//4, y//4, 'places', { 'id': 607976629, }) # should not exist at zoom 0 self.assert_no_matching_feature( 0, 0, 0, 'water', { 'kind': 'ocean', 'label_placement': True, }) # should not exist at zoom 0 self.assert_no_matching_feature( 0, 0, 0, 'earth', { 'kind': 'continent', 'label_placement': True, })
def test_drinking_water(self): import dsl z, x, y = (16, 0, 0) self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), { 'amenity': 'drinking_water', 'source': 'openstreetmap.org', }), ) self.assert_has_feature(z, x, y, 'pois', { 'kind': 'drinking_water', 'min_zoom': 18, })
def test_traffic_signals(self): import dsl z, x, y = (16, 0, 0) self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), { 'highway': 'traffic_signals', 'source': 'openstreetmap.org', }), ) self.assert_has_feature(z, x, y, 'pois', { 'kind': 'traffic_signals', 'min_zoom': 18, })
def _rank(self, place, population): import dsl z, x, y = 16, 0, 0 self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), { 'place': place, 'name': 'Foo State', 'population': str(population), 'source': 'openstreetmap.org', }), ) with self.features_in_tile_layer(z, x, y, 'places') as features: assert len(features) == 1 return features[0]['properties'].get('collision_rank')
def test_region_no_ne(self): import dsl z, x, y = 16, 0, 0 self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), { 'place': 'state', 'source': 'openstreetmap.org', 'name': 'Foo', }), ) self.assert_has_feature( z, x, y, 'places', { 'kind': 'region', 'min_zoom': 8, })
def test_toilets(self): # toilets are PONIs - we want to see an icon on the map even if it's # not a famous enough set of facilities that it got a name. import dsl z, x, y = (16, 0, 0) self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), { 'amenity': 'toilets', 'source': 'openstreetmap.org', }), ) self.assert_has_feature(z, x, y, 'pois', { 'kind': 'toilets', 'collision_rank': int, })
def test_drinking_water(self): import dsl z, x, y = (16, 0, 0) self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), { 'amenity': 'drinking_water', 'source': 'openstreetmap.org', }), ) self.assert_has_feature( z, x, y, 'pois', { 'kind': 'drinking_water', 'min_zoom': 18, })
def _rank(self, place, population): import dsl z, x, y = 16, 0, 0 self.generate_fixtures( dsl.way( 1, dsl.tile_centre_shape(z, x, y), { 'place': place, 'name': 'Foo State', 'population': str(population), 'source': 'openstreetmap.org', }), ) with self.features_in_tile_layer(z, x, y, 'places') as features: assert len(features) == 1 return features[0]['properties'].get('collision_rank')
def test_traffic_signals(self): import dsl z, x, y = (16, 0, 0) self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), { 'highway': 'traffic_signals', 'source': 'openstreetmap.org', }), ) self.assert_has_feature( z, x, y, 'pois', { 'kind': 'traffic_signals', 'min_zoom': 18, })
def test_zoom_1(self): import dsl z, x, y = (3, 7, 3) self.generate_fixtures( dsl.way( 607976629, dsl.tile_centre_shape(z, x, y), { "min_zoom": 1, "__ne_max_zoom": 10, "__ne_min_zoom": 3, "area": 0, "place": "country", "name": "Guam", "population": 185427, "source": "openstreetmap.org", }), ) # should exist at zoom 3 (the min zoom from NE) self.assert_has_feature(z, x, y, 'places', { 'id': 607976629, 'kind': 'country', 'name': 'Guam', }) # should not exist at zoom 2 (one past the min zoom) self.assert_no_matching_feature(z - 1, x // 2, y // 2, 'places', {'id': 607976629}) # should not exist at zoom 1 self.assert_no_matching_feature(z - 2, x // 4, y // 4, 'places', { 'id': 607976629, }) # should not exist at zoom 0 self.assert_no_matching_feature(0, 0, 0, 'water', { 'kind': 'ocean', 'label_placement': True, }) # should not exist at zoom 0 self.assert_no_matching_feature(0, 0, 0, 'earth', { 'kind': 'continent', 'label_placement': True, })
def _check_rank(self, population, rank): import dsl z, x, y = 16, 0, 0 self.generate_fixtures( dsl.way( 1, dsl.tile_centre_shape(z, x, y), { 'place': 'city', 'population': str(population), 'name': 'Fooville', 'source': 'openstreetmap.org', }), ) self.assert_has_feature(z, x, y, 'places', { 'population': population, 'population_rank': rank, })
def _check(self, default, dispute, expected): import dsl z, x, y = 16, 0, 0 self.generate_fixtures( dsl.way( 1, dsl.tile_centre_shape(z, x, y), { 'name': 'Foo', 'featurecla': default, 'fclass_iso': dispute, 'scalerank': 4, 'min_zoom': 4, 'source': 'naturalearthdata.com', }), ) expected['kind'] = 'locality' self.assert_has_feature(z, x, y, 'places', expected)
def test_country_ne(self): import dsl z, x, y = 16, 0, 0 self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), { 'place': 'country', 'source': 'openstreetmap.org', 'name': 'Foo', '__ne_min_zoom': 2, }), ) self.assert_has_feature( z, x, y, 'places', { 'kind': 'country', 'min_zoom': 2, })
def _check(self, default, dispute, expected): import dsl z, x, y = 16, 0, 0 self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), { 'name': 'Foo', 'featurecla': default, 'fclass_iso': dispute, 'scalerank': 4, 'min_zoom': 4, 'source': 'naturalearthdata.com', }), ) expected['kind'] = 'locality' self.assert_has_feature(z, x, y, 'places', expected)
def test_region_population_rank(self): import dsl z, x, y = 16, 0, 0 self.generate_fixtures( dsl.way( 1, dsl.tile_centre_shape(z, x, y), { 'place': 'state', 'name': 'Foo State', 'population': '100000000', 'source': 'openstreetmap.org', }), ) self.assert_has_feature(z, x, y, 'places', { 'kind': 'region', 'population_rank': 17, })
def test_toilets(self): # toilets are PONIs - we want to see an icon on the map even if it's # not a famous enough set of facilities that it got a name. import dsl z, x, y = (16, 0, 0) self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), { 'amenity': 'toilets', 'source': 'openstreetmap.org', }), ) self.assert_has_feature( z, x, y, 'pois', { 'kind': 'toilets', 'collision_rank': int, })
def test_0(self): import dsl z, x, y = 16, 0, 0 self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), { 'place': 'city', # missing population 'name': 'Fooville', 'source': 'openstreetmap.org', }), ) self.assert_has_feature( z, x, y, 'places', { 'population': type(None), 'population_rank': 0, })
def _check_rank(self, population, rank): import dsl z, x, y = 16, 0, 0 self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), { 'place': 'city', 'population': str(population), 'name': 'Fooville', 'source': 'openstreetmap.org', }), ) self.assert_has_feature( z, x, y, 'places', { 'population': population, 'population_rank': rank, })
def test_region_population_rank(self): import dsl z, x, y = 16, 0, 0 self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), { 'place': 'state', 'name': 'Foo State', 'population': '100000000', 'source': 'openstreetmap.org', }), ) self.assert_has_feature( z, x, y, 'places', { 'kind': 'region', 'population_rank': 17, })
def test_islet_node(self): # NODE islet labels (from place nodes) # Pyramid Rock, SF self.generate_fixtures( dsl.way(358795646, dsl.tile_centre_shape(16, 10466, 25327), { u'gnis:state_id': u'06', u'name': u'Pyramid Rock', u'gnis:county_id': u'075', u'created_by': u'Potlatch 0.10f', u'ele': u'4', u'source': u'openstreetmap.org', u'place': u'islet', u'gnis:created': u'01/19/1981', u'gnis:feature_id': u'253806', })) self.assert_has_feature( 16, 10466, 25327, 'earth', {'kind': 'islet', 'label_placement': True, 'name': 'Pyramid Rock', 'min_zoom': 17})
def test_water(self): import dsl z, x, y = (16, 10752, 32895) self.generate_fixtures( # https://www.openstreetmap.org/node/305640005 dsl.way( 305640005, dsl.tile_centre_shape(z, x, y), { 'name': u'Pacific Ocean', 'place': u'ocean', 'source': u'openstreetmap.org', 'wikidata': u'Q98', }), ) self.assert_has_feature(z, x, y, 'water', { 'id': 305640005, 'kind': u'ocean', 'wikidata_id': u'Q98', })
def test_0(self): import dsl z, x, y = 16, 0, 0 self.generate_fixtures( dsl.way( 1, dsl.tile_centre_shape(z, x, y), { 'place': 'city', # missing population 'name': 'Fooville', 'source': 'openstreetmap.org', }), ) self.assert_has_feature(z, x, y, 'places', { 'population': type(None), 'population_rank': 0, })
def _rank_for_pop(self, population, capital=None): import dsl z, x, y = 16, 0, 0 tags = { 'place': 'city', 'population': population, 'name': 'Fooville', 'source': 'openstreetmap.org', } if capital: tags[capital] = 'yes' self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), tags), ) with self.features_in_tile_layer(z, x, y, 'places') as features: self.assertEqual(len(features), 1) return features[0]['properties'].get('collision_rank')
def test_memorial_node(self): # if a memorial _isn't_ a plaque, then it should stay as a memorial! # this is the counter-example to test_plaque_node above, as previously # there was a bug where the test for plaque was too general and # accidentally re-classified all memorials as plaques. import dsl z, x, y = (16, 0, 0) self.generate_fixtures( dsl.way( 1, dsl.tile_centre_shape(z, x, y), { 'historic': u'memorial', 'name': u'A. Name Here', 'source': u'openstreetmap.org', }), ) self.assert_has_feature(z, x, y, 'pois', { 'id': 1, 'kind': 'memorial', })
def test_water(self): import dsl z, x, y = (16, 10752, 32895) self.generate_fixtures( # https://www.openstreetmap.org/node/305640005 dsl.way(305640005, dsl.tile_centre_shape(z, x, y), { 'name': u'Pacific Ocean', 'place': u'ocean', 'source': u'openstreetmap.org', 'wikidata': u'Q98', }), ) self.assert_has_feature( z, x, y, 'water', { 'id': 305640005, 'kind': u'ocean', 'wikidata_id': u'Q98', })
def test_memorial_node(self): # if a memorial _isn't_ a plaque, then it should stay as a memorial! # this is the counter-example to test_plaque_node above, as previously # there was a bug where the test for plaque was too general and # accidentally re-classified all memorials as plaques. import dsl z, x, y = (16, 0, 0) self.generate_fixtures( dsl.way(1, dsl.tile_centre_shape(z, x, y), { 'historic': u'memorial', 'name': u'A. Name Here', 'source': u'openstreetmap.org', }), ) self.assert_has_feature( z, x, y, 'pois', { 'id': 1, 'kind': 'memorial', })