Writing /home/gribeiro/www/data/cache/2/22b246c41f60c3a4a846dab699f24a73.metadata failed
Table of Contents
Resumo
SET PATH=%PATH%;"C:\Program Files\PostgreSQL\10\bin" cd C:\Curso_BDG\Imagem_CBERS_2B_Fusao_2.36m dir raster2pgsql -c -C -P -r -s 29183 -I -M -t 128x128 -l 2,4,8,16 Fusao_CBERS.tif public.img_brasilia_cbers > img_brasilia_cbers.sql psql -U gribeiro -d bdgcurso -f img_brasilia_cbers.sql raster2pgsql -c -C -P -r -s 32623 -I -M -t 128x128 -l 2,4,8,16 L71221071_07120060531_B10.TIF public.img_brasilia_landsat_b1 > img_brasilia_landsat_b1.sql raster2pgsql -c -C -P -r -s 32623 -I -M -t 128x128 -l 2,4,8,16 L71221071_07120060531_B20.TIF public.img_brasilia_landsat_b2 > img_brasilia_landsat_b2.sql raster2pgsql -c -C -P -r -s 32623 -I -M -t 128x128 -l 2,4,8,16 L71221071_07120060531_B30.TIF public.img_brasilia_landsat_b3 > img_brasilia_landsat_b3.sql
Sistemas de Bancos de Dados Geoespaciais - Dados Matriciais - Scripts
Configurando o Ambiente de Trabalho
1. Adicione o caminho das ferramentas utilitárias do banco de dados PostgreSQL ao PATH do seu sistema.
- No Microsoft Windows com PostgreSQL 32-bit, use:
SET PATH=%PATH%;"C:\Program Files (x86)\PostgreSQL\9.3\bin"
- No Microsoft Windows com PostgreSQL 64-bit, use:
SET PATH=%PATH%;"C:\Program Files\PostgreSQL\9.3\bin"
- No Mac OS X, use:
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
Usando gdalinfo
1. Obter informações sobre cada imagem utilizando o utilitário gdalinfo
:
- Imagem do satélite CBERS-2B -
Fusao_CBERS.tif
(SRID: 29183):
gdalinfo Fusao_CBERS.tif
- Imagem LandSat-7 -
L71221071_07120060531_B10.TIF
(SRID: 32623):
gdalinfo L71221071_07120060531_B10.TIF
- Imagem SRTM -
15_48_ZN
(SRID: 4326)
gdalinfo 15_48_ZN.tif
Carregando Dados Matriciais para o Banco de Dados
1. Importando a imagem Fusao_CBERS.tif para o banco de dados:
- Convertendo a imagem Fusao_CBERS.tif para um script SQL:
raster2pgsql -c -C -P -r -s 29183 -I -M -t 128x128 -l 2,4,8,16 Fusao_CBERS.tif public.img_brasilia_cbers > img_brasilia_cbers.sql
- Carregando o script com a imagem para o banco de dados:
psql -U postgres -d bdgcurso -f img_brasilia_cbers.sql
- Verificando as tabelas criadas com a importação dos dados:
SELECT COUNT(*) FROM img_brasilia_cbers SELECT COUNT(*) FROM o_2_img_brasilia_cbers; SELECT COUNT(*) FROM o_4_img_brasilia_cbers; SELECT COUNT(*) FROM o_8_img_brasilia_cbers; SELECT COUNT(*) FROM o_16_img_brasilia_cbers;
2. Importando imagens LandSat-7 (SRID: 32623) para o banco de dados:
- Convertendo a cena L71221071_07120060531 nas bandas 1, 2 e 3 para scripts SQL:
raster2pgsql -c -C -P -r -s 32623 -I -M -t 128x128 -l 2,4,8,16 L71221071_07120060531_B10.TIF public.img_brasilia_landsat_b1 > img_brasilia_landsat_b1.sql raster2pgsql -c -C -P -r -s 32623 -I -M -t 128x128 -l 2,4,8,16 L71221071_07120060531_B20.TIF public.img_brasilia_landsat_b2 > img_brasilia_landsat_b2.sql raster2pgsql -c -C -P -r -s 32623 -I -M -t 128x128 -l 2,4,8,16 L71221071_07120060531_B30.TIF public.img_brasilia_landsat_b3 > img_brasilia_landsat_b3.sql
- Carregando os scripts com as imagens para o banco de dados:
psql -U postgres -d bdgcurso -f img_brasilia_landsat_b1.sql psql -U postgres -d bdgcurso -f img_brasilia_landsat_b2.sql psql -U postgres -d bdgcurso -f img_brasilia_landsat_b3.sql
- Verificando as tabelas criadas com a importação dos dados:
SELECT COUNT(*) FROM img_brasilia_landsat_b1; SELECT COUNT(*) FROM o_2_img_brasilia_landsat_b1; SELECT COUNT(*) FROM o_4_img_brasilia_landsat_b1; SELECT COUNT(*) FROM o_8_img_brasilia_landsat_b1; SELECT COUNT(*) FROM o_16_img_brasilia_landsat_b1;
3. Importando imagens SRTM (SRID: 4326) para o banco de dados:
- Convertendo um mosaico SRTM (SRID: 4326) para um script SQL:
raster2pgsql -c -C -P -r -s 4326 -I -M -t 128x128 -l 2,4,8,16 15_48_ZN.tif 15_495ZN.tif 16_48_ZN.tif 16_495ZN.tif public.img_brasilia_srtm > img_brasilia_srtm.sql
- Carregando o script com o mosaico de imagens para o banco de dados:
psql -U postgres -d bdgcurso -f img_brasilia_srtm.sql
- Verificando as tabelas criadas com a importação dos dados:
SELECT COUNT(*) FROM img_brasilia_srtm; SELECT COUNT(*) FROM o_2_img_brasilia_srtm; SELECT COUNT(*) FROM o_4_img_brasilia_srtm; SELECT COUNT(*) FROM o_8_img_brasilia_srtm; SELECT COUNT(*) FROM o_16_img_brasilia_srtm;
Operações e Consultas com Dados Matriciais
1. Calculando histograma da imagem CBERS:
SELECT band, (stats).* FROM (SELECT rid, band, ST_Histogram(rast, band) AS stats FROM img_brasilia_cbers CROSS JOIN generate_series(1,3) AS band WHERE rid=2) AS foo;
2. Calculando estatísticas da imagem CBERS:
SELECT band, (stats).* FROM (SELECT band, ST_SummaryStats('img_brasilia_cbers','rast', band) AS stats FROM generate_series(1,3) AS band) AS foo;
3. Juntando as bandas LandSat em um único raster
CREATE TABLE img_brasilia_landsat AS SELECT b1.rid AS rid, ST_AddBand(b1.rast, ARRAY[b2.rast, b3.rast]) AS rast FROM img_brasilia_landsat_b1 b1, img_brasilia_landsat_b2 b2, img_brasilia_landsat_b3 b3 WHERE b1.rid = b2.rid AND b2.rid = b3.rid; ALTER TABLE img_brasilia_landsat ADD PRIMARY KEY (rid); CREATE INDEX spidx_img_brasilia_landsat_rast ON img_brasilia_landsat USING gist(ST_ConvexHull(rast));
4. Fazendo um clip da imagem CBERS:
CREATE TABLE recorte_raster AS SELECT ST_Clip(rast, ST_Buffer(ST_Centroid(ST_Envelope(rast)), 100), FALSE) FROM img_brasilia_cbers WHERE rid = 2100;