-
Notifications
You must be signed in to change notification settings - Fork 16
Home
Peter edited this page Oct 9, 2017
·
9 revisions
Welcome to the city-codes wiki!
Obtendo mapa no OpenStreetMap
-
https://www.openstreetmap.org/relation/334407 (nominatim place_id=178623484) está já marcada com
IBGE:GEOCODIGO=5200050
,name=Abadia de Goiás
ewikidata=Q304652
.
Ver também
Manutenção:
CREATE FOREIGN TABLE tmpcsv_city_codes (
name text,state text,wdId text,idIBGE int,
lexLabel text,creation int,extinction int,
postalCode_ranges text,notes text
) SERVER csv_files OPTIONS (
filename '/tmp/city-codes/data/br-city-codes.csv',
format 'csv',
header 'true'
);
CREATE FOREIGN TABLE tmpcsv_city_cep (
ESTADO text,CIDADE text,CEP text
) SERVER csv_files OPTIONS (
filename '/tmp/cep.csv',
format 'csv',
header 'true'
);
-- check:
SELECT count(*) as n, count(DISTINCT estado||cidade) as n_cidade,
count(DISTINCT estado||oficial.name2lex(cidade)) as n_lex
FROM tmpcsv_city_cep; -- n=5570 | n_cidade=5295 | n_lex=5288
CREATE VIEW vw_cep AS
SELECT lower(trim(estado))||';'||lexlabel as lexlabel,
estado||metaphone(cidade,4) as metahash1, estado||metaphone(lexlabel,100) as metahash2,
trim(cep) as cep, cidade, estado
FROM (select *, oficial.name2lex(cidade) as lexlabel from tmpcsv_city_cep) t
;
SELECT count(*)
FROM vw_cep v INNER JOIN tmpcsv_city_codes c ON lower(c.state)||';'||c.lexLabel = v.lexlabel
; -- 5527 < 5570
SELECT '* [['||cidade||']] ('||estado||')'
FROM vw_cep where lexlabel not in (
select distinct v.lexlabel
FROM vw_cep v INNER JOIN tmpcsv_city_codes c
ON lower(c.state)||';'||c.lexLabel = v.lexlabel
) order by 1
;
A a última query foi gerada para conferir direto na discussão sobre dupla grafia da Wikipedia.
Uma listagem similar pode ser utilizada para avaliação via Metaphone:
SELECT cep.metahash1, cep.cidade, c2.name, c2.state, c2.wdid, c2.idibge, cep.cep
FROM tmpcsv_city_codes c2 INNER JOIN vw_cep cep ON cep.metahash1 = c2.state||metaphone(c2.name,4)
WHERE (lower(c2.state) ||';'|| c2.lexlabel) NOT IN (
select distinct v.lexlabel
FROM vw_cep v INNER JOIN tmpcsv_city_codes c
ON lower(c.state)||';'||c.lexLabel = v.lexlabel
)
ORDER BY 1;
metahash1 | cidade | name | state | wdid | idibge | cep |
---|---|---|---|---|---|---|
BAJKR | Jequiriçá | Jiquiriçá | BA | Q1795144 | 291820 | 45470000 |
BASNTT | Santa Terezinha | Santa Teresinha | BA | Q1795259 | 292850 | 44590000 |
GOBMJS | Bom Jesus | Bom Jesus de Goiás | GO | Q891725 | 520350 | 75570000 |
MAKFRN | Governador Edson Lobão | Governador Edison Lobão | MA | Q2012559 | 210455 | 65928000 |
MASNTM | Santo Amaro | Santo Amaro do Maranhão | MA | Q665255 | 211027 | 65195000 |
MASNTR | Senador La Roque | Senador La Rocque | MA | Q1967899 | 211176 | 65935000 |
MGTNSB | Dona Euzébia | Dona Eusébia | MG | Q1756805 | 312290 | 36784000 |
PBSTMN | São Domingos do Cariri | São Domingos | PB | Q224967 | 251396 | 58485000 |
PBSTMN | São Domingos de Pombal | São Domingos | PB | Q224967 | 251396 | 58853000 |
RJPRT | Parati | Paraty | RJ | Q926729 | 330380 | 23970000 |
RJTRJN | Trajano de Morais | Trajano de Moraes | RJ | Q1803189 | 330590 | 28750000 |
RNARS | Arez | Arês | RN | Q928712 | 240120 | 59170000 |
ROESPK | Espigão do Oeste | Espigão d'Oeste | RO | Q616498 | 110009 | 76974000 |
Os demais casos precisam de fato ser inclusos na tabela.