Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fronteiras entre estados #20

Closed
ppKrauss opened this issue Oct 1, 2018 · 0 comments
Closed

Fronteiras entre estados #20

ppKrauss opened this issue Oct 1, 2018 · 0 comments

Comments

@ppKrauss
Copy link
Contributor

ppKrauss commented Oct 1, 2018

Usando mapa oficial do IBGE de 2017.

uf_vigente faz_fronteira_com
AC AM
AL BA PE SE
AM AC MT PA RO RR
AP PA
BA AL ES GO MG PE PI SE TO
CE PB PE PI RN
DF GO MG
ES BA MG RJ
GO BA DF MG MS MT TO
MA PA PI TO
MG BA DF ES GO MS RJ SP
MS GO MG MT PR SP
MT AM GO MS PA RO TO
PA AM AP MA MT RR TO
PB CE PE RN
PE AL BA CE PB PI
PI BA CE MA PE TO
PR MS SC SP
RJ ES MG SP
RN CE PB
RO AM MT
RR AM PA
RS SC
SC PR RS
SE AL BA
SP MG MS PR RJ
TO BA GO MA MT PA PI
CREATE FUNCTION lib.id_ibge2uf(p_id text) REtURNS text AS $$
  SELECT ('{
    "12":"AC", "27":"AL", "13":"AM", "16":"AP", "29":"BA", "23":"CE", 
    "53":"DF", "32":"ES", "52":"GO", "21":"MA", "31":"MG", "50":"MS", 
    "51":"MT", "15":"PA", "25":"PB", "26":"PE", "22":"PI", "41":"PR", 
    "33":"RJ", "24":"RN", "11":"RO", "14":"RR", "43":"RS", "42":"SC", 
    "28":"SE", "35":"SP", "17":"TO"
  }'::jsonb)->>$1
$$ language SQL immutable;

SELECT a_nm, array_to_string(array_agg(b_nm),' ') faz_fronteira_com 
FROM (
  SELECT DISTINCT a_nm, b_nm 
  FROM (
     SELECT lib.id_ibge2uf(a.cd_geocuf) a_nm, 
                    lib.id_ibge2uf(b.cd_geocuf) b_nm, 
                    ST_Relate(a.geom,b.geom) rel 
     FROM brufe250gc_sir a, brufe250gc_sir b 
     WHERE a.cd_geocuf!=b.cd_geocuf AND a.geom && b.geom
  ) t 
WHERE rel!='FF2FF1212'
ORDER BY 1,2) tt  group by 1 order by 1

Pode-se conferir os valores rel com a função lib.ST_Relate_summary().

PS: as relações são reduzidas a interseções de área com st_buffer(a.geom,0.0001), restando 51 casos de interseção tipo rel='212101212'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant