2 544
edições
m (→tentativa 3: fez o esperado) |
m (→tentativa 3) |
||
(6 revisões intermediárias pelo mesmo usuário não estão sendo mostradas) | |||
Linha 185: | Linha 185: | ||
; | ; | ||
CREATE or replace FUNCTION osmc.grid_generate_all_levels_logistic2( | CREATE or replace FUNCTION osmc.grid_generate_all_levels_logistic2( | ||
p_lev_max numeric, p_contry text, | p_lev_max numeric, | ||
p_contry text, | |||
p_contry_base integer, | p_contry_base integer, | ||
p_id_bitlen integer, -- ex. 37 | p_id_bitlen integer, -- ex. 37 | ||
p_lev0 numeric default 2.5 | p_lev0 numeric default 2.5, | ||
p_blocksize int default 100 | |||
) RETURNS text LANGUAGE plpgsql AS $f$ | ) RETURNS text LANGUAGE plpgsql AS $f$ | ||
DECLARE | DECLARE | ||
Linha 213: | Linha 215: | ||
select cod_b16h, row_number() over() ord | select cod_b16h, row_number() over() ord | ||
from grid_br2.poc_caruaru_vw01logistic | from grid_br2.poc_caruaru_vw01logistic | ||
where length(gid_vbit)=p_id_bitlen | where length(gid_vbit)=grid_generate_all_levels_logistic2.p_id_bitlen | ||
) t1 | ) t1 | ||
GROUP BY ord/ | GROUP BY ord/grid_generate_all_levels_logistic2.p_blocksize | ||
) t2; | ) t2; | ||
FOREACH cover_frag IN ARRAY oid_list LOOP | FOREACH cover_frag IN ARRAY oid_list LOOP | ||
s:=''; | s:=''; | ||
Linha 225: | Linha 226: | ||
END LOOP; -- lev | END LOOP; -- lev | ||
s := s|| E'\n ORDER BY 1'; | s := s|| E'\n ORDER BY 1'; | ||
ret := ret || E' | ret := ret || E'\n\nINSERT INTO grid_br2.tmp_cells \n'|| s --|| E';\n COMMIT; \n\n'; | ||
END LOOP; -- cover_frag | END LOOP; -- cover_frag | ||
Linha 232: | Linha 233: | ||
$f$; | $f$; | ||
SELECT volat_file_write( -- com 37 e 500 dá 5Mb | |||
'/tmp/inserts_logistic2.sql' | |||
, osmc.grid_generate_all_levels_logistic2( 2.5, 'BR', 18, 27, 2.5, 300 ) | |||
); | |||
-- deu certo! | |||
chmod 777 | |||
psql < sql | |||
--- | |||
select count(*) from grid_br2.tmp_cells; -- 16352 | |||
select count(*) | |||
from grid_br2.tmp_cells | |||
where ST_Intersects(geom,(select geom from grid_br2.municipio where isolabel_ext='BR-PE-Caruaru')) | |||
; --14489 | |||
select count(*) from grid_br2.tmp_cells t inner join grid_br2.poc_caruaru c on c.gid_vbit=t.gid_vbit; -- 14489 | |||
---- ------------------------------------------- | |||
SELECT volat_file_write( | SELECT volat_file_write( | ||
'/tmp/inserts_logistic2.sql' | '/tmp/inserts_logistic2.sql' | ||
, osmc.grid_generate_all_levels_logistic2( 2.5, 'BR', | , osmc.grid_generate_all_levels_logistic2( 2.5, 'BR', 18, 37, 2.5, 400 ) | ||
); | ); -- 4828425 byts = 4.7M. Em 17 segundos faz 20*12800. Faz 14 mil celulas por segundo. celulas de 8 metros de lado são 64m2. | ||
-- depois de rodar | |||
delete from grid_br2.tmp_cells where not(ST_Intersects(geom,(select geom from grid_br2.municipio where isolabel_ext='BR-PE-Caruaru')) ); | |||
-- DELETE 70068 | |||
insert into grid_br2.poc_caruaru SELECT * FROM grid_br2.tmp_cells ORDER BY gid_vbit; | |||
-- INSERT 0 14420108 | |||
delete from grid_br2.tmp_cells; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Como Caruaru tem da ordem de 920 km2, são 14406456 (14 milhões) de células, portanto 1 mil segundos ou 16 minutos. | |||
=== tentativa 4 === | === tentativa 4 === |
edições