Ir para o conteúdo

CNEFE/Pontos basicos: mudanças entre as edições

sem sumário de edição
(view2 corrigida)
Sem resumo de edição
Linha 1: Linha 1:
Ingestão. Ver Carlos, colocou na base IBGE, na tabela ibge_pontos. Tudo text.
Ingestão. Ver Carlos, colocou na base IBGE, na tabela ibge_pontos. Tudo text.
<syntaxhighlight lang="sql" style="font-size: 80%;">
<syntaxhighlight lang="sql" style="font-size: 80%;">
create table ibge_pontos (
create table ibge_pontos_raw (
   COD_UNICO_ENDERECO text,
   COD_UNICO_ENDERECO text,
   COD_UF text, COD_MUNICIPIO text, COD_DISTRITO text, COD_SUBDISTRITO text, COD_SETOR text, NUM_QUADRA text, NUM_FACE text, CEP text, DSC_LOCALIDADE text, NOM_TIPO_SEGLOGR text, NOM_TITULO_SEGLOGR text,
   COD_UF text, COD_MUNICIPIO text, COD_DISTRITO text, COD_SUBDISTRITO text,
  COD_SETOR text, NUM_QUADRA text, NUM_FACE text, CEP text, DSC_LOCALIDADE text, NOM_TIPO_SEGLOGR text, NOM_TITULO_SEGLOGR text,
  NOM_SEGLOGR text, NUM_ENDERECO text, DSC_MODIFICADOR text, NOM_COMP_ELEM1 text, VAL_COMP_ELEM1 text, NOM_COMP_ELEM2 text, VAL_COMP_ELEM2 text, NOM_COMP_ELEM3 text, VAL_COMP_ELEM3 text, NOM_COMP_ELEM4 text, VAL_COMP_ELEM4 text,  
  NOM_SEGLOGR text, NUM_ENDERECO text, DSC_MODIFICADOR text, NOM_COMP_ELEM1 text, VAL_COMP_ELEM1 text, NOM_COMP_ELEM2 text, VAL_COMP_ELEM2 text, NOM_COMP_ELEM3 text, VAL_COMP_ELEM3 text, NOM_COMP_ELEM4 text, VAL_COMP_ELEM4 text,  
  NOM_COMP_ELEM5 text,  
  NOM_COMP_ELEM5 text,  
Linha 10: Linha 11:
</syntaxhighlight>
</syntaxhighlight>


* ntot_geral=111102875; <code>select count(*) ntot_geral from ibge_pontos;</code>
* ntot_geral=111102875; <code>select count(*) ntot_geral from ibge_pontos_raw;</code>
** reduzido para 110744837 depois do filtro1.
** reduzido para 110744837 depois do filtro1.


Alvo: apenas endereços
Alvo: apenas endereços
<syntaxhighlight lang="sql" style="font-size: 80%;">
<syntaxhighlight lang="sql" style="font-size: 80%;">
-- drop view ibge_pontos2 cascade;
-- drop view vw01_ibge_pontos_raw cascade;
Create view ibge_pontos2 as  
Create table ibge_pontos_raw2 as
  SELECT cod_unico_endereco::bigint as gid,
SELECT * FROM (
   COD_MUNICIPIO AS jurisdic_id, CEP, DSC_LOCALIDADE AS nsvia,  
  SELECT cod_unico_endereco::bigint as gid, -- invalido, tem duplicação.
   CASE WHEN NOM_TIPO_SEGLOGR = 'EDF' THEN ''  
   COD_MUNICIPIO::int AS jurisdic_id, -- cod_ibge
      ELSE COALESCE(NOM_TIPO_SEGLOGR,'') || ' ' || COALESCE(NOM_TITULO_SEGLOGR,'') || ' ' || COALESCE(NOM_SEGLOGR,'')
  substring(cod_setor,1,15)::bigint as num_setor, -- melhor que CEP para nome de via unico
  END AS via,
  NUM_FACE::int as num_face,
  CEP, DSC_LOCALIDADE AS nsvia,
   trim(regexp_replace(
        CASE WHEN NOM_TIPO_SEGLOGR = 'EDF' THEN ''  
        ELSE COALESCE(NOM_TIPO_SEGLOGR,'') || ' ' || COALESCE(NOM_TITULO_SEGLOGR,'') || ' ' || COALESCE(NOM_SEGLOGR,'')
        END,
        '\s+', ' ','g')) AS via,
   NUM_ENDERECO as hnum,
   NUM_ENDERECO as hnum,
   ST_SetSRID(ST_MakePoint(LONGITUDE::float,LATITUDE::float),4326) AS geom  
   ST_SetSRID(ST_MakePoint(LONGITUDE::float,LATITUDE::float),4326) AS geom  
FROM ibge_pontos;
FROM ibge_pontos_raw
) t WHERE via>''; -- AND geom is not null;  -- nulls não ocorreram
-- das 5:52  ate..
</syntaxhighlight>
</syntaxhighlight>
* a condição <code>NOM_TIPO_SEGLOGR = 'EDF'</code> ocorre para ~1% do total (~1.270.000 casos). É significativo, foi uma decisão falha CNEFE. Estamos descartando até entender melhor como proceder.
* a condição <code>NOM_TIPO_SEGLOGR = 'EDF'</code> ocorre para ~1% do total (~1.270.000 casos). É significativo, foi uma decisão falha CNEFE. Estamos descartando até entender melhor como proceder.
Linha 35: Linha 44:


<syntaxhighlight lang="sql" style="font-size: 80%;">
<syntaxhighlight lang="sql" style="font-size: 80%;">
with tot as (select cod_uf, count(*) ntot from ibge_pontos group by 1 order by 1) select *, round((100.0*n::float/ntot)::numeric,2) as perc from ( select t.cod_uf, tot.ntot, count(t.*) n from ibge_pontos t inner join tot ON tot.cod_uf=t.cod_uf where t.NV_GEO_COORD::int>3 group by 1,2) t2 order by 1;
with tot as (select cod_uf, count(*) ntot from ibge_pontos_raw group by 1 order by 1) select *, round((100.0*n::float/ntot)::numeric,2) as perc from ( select t.cod_uf, tot.ntot, count(t.*) n from ibge_pontos_raw t inner join tot ON tot.cod_uf=t.cod_uf where t.NV_GEO_COORD::int>3 group by 1,2) t2 order by 1;
</syntaxhighlight>
</syntaxhighlight>
Perfil:<pre>
Perfil:<pre>
Linha 69: Linha 78:
</pre>
</pre>


* Ação: 358038 registtos deletados. <code>DELETE FROM ibge_pontos WHERE nv_geo_coord::int>3;</code>
* Ação: 358038 registtos deletados. <code>DELETE FROM ibge_pontos_raw WHERE nv_geo_coord::int>3;</code>


'''Filtro 2''': eliminação dos endereços com nome de rua nulo. Por definição sem o nome de rua não temos endereço, portanto, como neste momento não tentaremos interpolar ou fazer inferência por outras fontes, a melhor estratégia é remover a informação expúria.
'''Filtro 2''': eliminação dos endereços com nome de rua nulo. Por definição sem o nome de rua não temos endereço, portanto, como neste momento não tentaremos interpolar ou fazer inferência por outras fontes, a melhor estratégia é remover a informação expúria.
:Nota. A condição de nome de edificio foi suficiente.
: select count(*) from ibge_pontos_raw where NOM_TIPO_SEGLOGR = 'EDF'-- 1266130
: select count(*) from vw01_ibge_pontos_raw where via='' or via is null; -- 1266130


: Nota sobre Uso do Geohash6 na não-duplicação de nome de rua. [https://www.movable-type.co.uk/scripts/geohash.html  movable/geohash] estima que Ghs6 tem ~1km2 e Ghs5 da ordem de 25km2.  Ghs6 mellhor para pequenos municípios, dentro ou abaixo da mediana Brasil. <code>select PERCENTILE_CONT(0.5) WITHIN GROUP(ORDER BY round(sqrt((info->'area_km2')::float)) ) sqside_km_mdn from optim.jurisdiction where jurisd_base_id=76 and isolevel=3 ; -- 20km </code>.
: Nota sobre Uso do Geohash6 na não-duplicação de nome de rua. [https://www.movable-type.co.uk/scripts/geohash.html  movable/geohash] estima que Ghs6 tem ~1km2 e Ghs5 da ordem de 25km2.  Ghs6 mellhor para pequenos municípios, dentro ou abaixo da mediana Brasil. <code>select PERCENTILE_CONT(0.5) WITHIN GROUP(ORDER BY round(sqrt((info->'area_km2')::float)) ) sqside_km_mdn from optim.jurisdiction where jurisd_base_id=76 and isolevel=3 ; -- 20km </code>.
2 583

edições