Skip to content

Commit

Permalink
Removal of unneeded dispute lua and additional country support (#2068)
Browse files Browse the repository at this point in the history
* lua to upgrade dependencies and territories to country status for labels.

* Remove unneeded disputes and add ne_id and ne:brk to way tags to allow for a dispute_id.
  • Loading branch information
jeffdefacto authored May 3, 2022
1 parent 5dcce22 commit 66740a3
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 115 deletions.
22 changes: 22 additions & 0 deletions integration-test/2068-place-unrecognized.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import dsl

from . import FixtureTest


class TestPlaceUnrecognized(FixtureTest):
def test_place_unrecognized_into_kind(self):

z, x, y = 16, 0, 0
self.generate_fixtures(
dsl.way(1, dsl.tile_centre_shape(z, x, y), {
'place': 'unrecognized',
'source': 'openstreetmap.org',
'name': 'Foo'
}),
)

self.assert_has_feature(
z, x, y, 'places', {
'kind': 'unrecognized',
'min_zoom': 6,
})
240 changes: 127 additions & 113 deletions osm2pgsql.lua
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ function osm2pgsql.process_node(object)
end
-- Turn off Kosovo country label for CN;RU;IN;GR
if object.tags.place and object.tags.wikidata == 'Q1246' then
output_hstore['disputed_by'] = 'CN;GR;IN;RU'
output_hstore['recognized_by'] = 'AR;BD;BR;DE;EG;ES;FR;GB;ID;IL;IT;JP;KO;MA;NL;NP;PK;PL;PS;PT;SA;SE;TR;TW;UA;US;VN'
output_hstore['disputed_by'] = 'AR;BR;CN;GR;ID;IN;MA;NP;PS;RU;UA;VN'
output_hstore['recognized_by'] = 'BD;DE;EG;ES;FR;GB;IL;IT;JP;KO;NL;PK;PL;PT;SA;SE;TR;TW;US'
end
-- Hide Kosovo region labels for several POVs including China and Russia
if object.tags.place and (object.tags.wikidata == 'Q1008042' or object.tags.wikidata == 'Q1021775' or
Expand All @@ -497,132 +497,133 @@ function osm2pgsql.process_node(object)
object.tags.wikidata == 'Q963121' or object.tags.wikidata == 'Q991291' or object.tags.wikidata == 'Q991291' or
object.tags.wikidata == 'Q991313' or object.tags.wikidata == 'Q991332' or object.tags.wikidata == 'Q994245' or
object.tags.wikidata == 'Q994730') then
output_hstore['disputed_by'] = 'CN;RU;IN;GR'
output_hstore['disputed_by'] = 'AR;BR;CN;GR;ID;IN;MA;NP;PS;RU;UA;VN'
end
-- Recast Northern Cyprus as country label and turn off for several POVs including China and Russia

-- Turn off Northern Cyprus label for most countries
if object.tags.place and object.tags.wikidata == 'Q23681' then
output_hstore['place'] = 'country'
output_hstore['place'] = 'unrecognized'
output_hstore['place:TR'] = 'country'
output_hstore['disputed_by'] = 'CN;RU;IN;GR;CY'
end
-- Turn off Abkhazia label for most countries
-- Show Abkhazia label as region for most countries
if object.tags.place and object.tags.wikidata == 'Q23334' then
output_hstore['place:AR'] = 'region'
output_hstore['place:BD'] = 'region'
output_hstore['place:BR'] = 'region'
output_hstore['place:CN'] = 'region'
output_hstore['place:DE'] = 'region'
output_hstore['place:EG'] = 'region'
output_hstore['place:GB'] = 'region'
output_hstore['place:GR'] = 'region'
output_hstore['place:ID'] = 'region'
output_hstore['place:IL'] = 'region'
output_hstore['place:IN'] = 'region'
output_hstore['place:IT'] = 'region'
output_hstore['place:JP'] = 'region'
output_hstore['place:KO'] = 'region'
output_hstore['place:MA'] = 'region'
output_hstore['place:NL'] = 'region'
output_hstore['place:NP'] = 'region'
output_hstore['place:PK'] = 'region'
output_hstore['place:PL'] = 'region'
output_hstore['place:PS'] = 'region'
output_hstore['place:PT'] = 'region'
output_hstore['place:SA'] = 'region'
output_hstore['place:SE'] = 'region'
output_hstore['place:TR'] = 'region'
output_hstore['place:TW'] = 'region'
output_hstore['place:UA'] = 'region'
output_hstore['place:VN'] = 'region'
output_hstore['place'] = 'region'
output_hstore['place:RU'] = 'country'
end
-- Turn off South Ossetia label for most countries
if object.tags.place and object.tags.wikidata == 'Q23427' then
output_hstore['place:AR'] = 'region'
output_hstore['place:BD'] = 'region'
output_hstore['place:BR'] = 'region'
output_hstore['place:CN'] = 'region'
output_hstore['place:DE'] = 'region'
output_hstore['place:EG'] = 'region'
output_hstore['place:GB'] = 'region'
output_hstore['place:GR'] = 'region'
output_hstore['place:ID'] = 'region'
output_hstore['place:IL'] = 'region'
output_hstore['place:IN'] = 'region'
output_hstore['place:IT'] = 'region'
output_hstore['place:JP'] = 'region'
output_hstore['place:KO'] = 'region'
output_hstore['place:MA'] = 'region'
output_hstore['place:NL'] = 'region'
output_hstore['place:NP'] = 'region'
output_hstore['place:PK'] = 'region'
output_hstore['place:PL'] = 'region'
output_hstore['place:PS'] = 'region'
output_hstore['place:PT'] = 'region'
output_hstore['place:SA'] = 'region'
output_hstore['place:SE'] = 'region'
output_hstore['place:TR'] = 'region'
output_hstore['place:TW'] = 'region'
output_hstore['place:UA'] = 'region'
output_hstore['place:VN'] = 'region'
output_hstore['place'] = 'unrecognized'
output_hstore['place:RU'] = 'country'
end
-- Turn off Nagorno-Karabakh label for most countries
-- Turn off Artsakh (Nagorno-Karabakh) label for most countries
if object.tags.place and object.tags.wikidata == 'Q2397204' then
output_hstore['place:AR'] = 'region'
output_hstore['place:BD'] = 'region'
output_hstore['place:BR'] = 'region'
output_hstore['place:CN'] = 'region'
output_hstore['place:DE'] = 'region'
output_hstore['place:EG'] = 'region'
output_hstore['place:ES'] = 'region'
output_hstore['place:FR'] = 'region'
output_hstore['place:GB'] = 'region'
output_hstore['place:GR'] = 'region'
output_hstore['place:ID'] = 'region'
output_hstore['place:IL'] = 'region'
output_hstore['place:IN'] = 'region'
output_hstore['place:IT'] = 'region'
output_hstore['place:JP'] = 'region'
output_hstore['place:KO'] = 'region'
output_hstore['place:MA'] = 'region'
output_hstore['place:NL'] = 'region'
output_hstore['place:NP'] = 'region'
output_hstore['place:PK'] = 'region'
output_hstore['place:PL'] = 'region'
output_hstore['place:PS'] = 'region'
output_hstore['place:PT'] = 'region'
output_hstore['place:RU'] = 'region'
output_hstore['place:SA'] = 'region'
output_hstore['place:SE'] = 'region'
output_hstore['place:TR'] = 'region'
output_hstore['place:TW'] = 'region'
output_hstore['place:US'] = 'region'
output_hstore['place:VN'] = 'region'
output_hstore['place'] = 'unrecognized'
output_hstore['place:RU'] = 'country'
end
-- Turn off Somaliland label for most countries
if object.tags.place and object.tags.wikidata == 'Q34754' then
output_hstore['place:AR'] = 'region'
output_hstore['place:BD'] = 'region'
output_hstore['place:BR'] = 'region'
output_hstore['place:CN'] = 'region'
output_hstore['place:EG'] = 'region'
output_hstore['place:GR'] = 'region'
output_hstore['place:ID'] = 'region'
output_hstore['place:IL'] = 'region'
output_hstore['place:IN'] = 'region'
output_hstore['place:MA'] = 'region'
output_hstore['place:NP'] = 'region'
output_hstore['place:PK'] = 'region'
output_hstore['place:PL'] = 'region'
output_hstore['place:PS'] = 'region'
output_hstore['place:PT'] = 'region'
output_hstore['place:RU'] = 'region'
output_hstore['place:SA'] = 'region'
output_hstore['place:SO'] = 'region'
output_hstore['place:TR'] = 'region'
output_hstore['place:TW'] = 'region'
output_hstore['place:UA'] = 'region'
output_hstore['place:VN'] = 'region'
output_hstore['place'] = 'unrecognized'
output_hstore['place:TW'] = 'country'
end

-- Recast various dependencies as countries
-- American Samoa
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'AS' then
output_hstore['place'] = 'country'
end
-- Christmas Island
if object.tags.place == 'territory' and object.tags['ISO3166-1'] == 'CX' then
output_hstore['place'] = 'country'
end
-- Cocos (Keeling) Islands
if object.tags.place == 'territory' and object.tags['ISO3166-1'] == 'CC' then
output_hstore['place'] = 'country'
end
-- French Polynesia
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'PF' then
output_hstore['place'] = 'country'
end
-- French Southern and Antarctic Lands
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'TF' then
output_hstore['place'] = 'country'
end
-- Guam
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'GU' then
output_hstore['place'] = 'country'
end
-- Heard Island and McDonald Islands
if object.tags.place == 'territory' and object.tags['ISO3166-1'] == 'HM' then
output_hstore['place'] = 'country'
end
-- New Caledonia
if object.tags.place == 'archipelago' and object.tags['ISO3166-1'] == 'NF' then
output_hstore['place'] = 'country'
end
-- Norfolk Island
if object.tags.place == 'territory' and object.tags['ISO3166-1'] == 'NF' then
output_hstore['place'] = 'country'
end
-- Northern Mariana Islands
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'MP' then
output_hstore['place'] = 'country'
end
-- Puerto Rico
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'PR' then
output_hstore['place'] = 'country'
end
-- Saint Barthelemy
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'BL' then
output_hstore['place'] = 'country'
end
-- Saint Helena, Ascension and Tristan da Cunha
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'SH' then
output_hstore['place'] = 'country'
end
-- Saint Martin
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'MF' then
output_hstore['place'] = 'country'
end
-- Saint Pierre and Miquelon
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'PM' then
output_hstore['place'] = 'country'
end
-- Svalbard
if object.tags.place == 'region' and object.tags['ISO3166-1'] == 'SJ' then
output_hstore['place'] = 'country'
end
-- United States Virgin Islands
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'VI' then
output_hstore['place'] = 'country'
end
-- Wallis and Futuna
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'WF' then
output_hstore['place'] = 'country'
end

-- Recast various French overseas departments as region
-- Réunion
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'RE' then
output_hstore['place'] = 'country'
end
-- Martinique
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'MQ' then
output_hstore['place'] = 'country'
end
-- Mayotte
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'YT' then
output_hstore['place'] = 'country'
end
-- Guadeloupe
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'GP' then
output_hstore['place'] = 'country'
end
-- French Guiana
if object.tags.place == 'state' and object.tags['ISO3166-1'] == 'GF' then
output_hstore['place'] = 'country'
end


output.tags = output_hstore

if hstore_column then
Expand Down Expand Up @@ -720,6 +721,12 @@ function osm2pgsql.process_way(object)
if v.recognized_by then
output_hstore.recognized_by = v.recognized_by
end
if v.ne_id then
output_hstore.ne_id = v.ne_id
end
if v['ne:brk_a3'] then
output_hstore['ne:brk_a3'] = v['ne:brk_a3']
end
end
end

Expand Down Expand Up @@ -833,6 +840,13 @@ function osm2pgsql.process_relation(object)
output_hstore['admin_level'] = '4'
end

-- Convert admin_level 5 boundaries in Cyprus to 4
if type == 'boundary' and object.tags.admin_level == '5' and object.tags['ISO3166-2'] then
if osm2pgsql.has_prefix(object.tags['ISO3166-2'], 'CY-') then
output_hstore['admin_level'] = '4'
end
end

-- Turn off West Bank and Judea and Samaria relations
if type == 'boundary' and object.tags.wikidata == 'Q36678' then
output_hstore = {}
Expand Down
4 changes: 2 additions & 2 deletions yaml/places.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ filters:
kind: {col: placetype}
table: wof
extra_columns: [ min_zoom ]
- filter: {name: true, place: country}
- filter: {name: true, place: [country,unrecognized]}
# note: min_zoom needs to be smaller than any min_label in
# ne_10m_admin_0_countries to make sure we're not dropping any by not being
# included in the PostgreSQL index.
Expand All @@ -148,7 +148,7 @@ filters:
min_zoom: 1
output:
<<: [*output_properties, *ne_zooms]
kind: country
kind: {col: place}
table: osm
- filter: {name: true, place: state}
# note: min_zoom needs to be smaller than any min_label in
Expand Down

0 comments on commit 66740a3

Please sign in to comment.