Upload
jorge-arevalo
View
156
Download
0
Embed Size (px)
DESCRIPTION
Brevísima introducción a GDAL y PostGIS Raster como herramientas de geoprocesamiento en si mismas, más allá de servir como soporte a otras herramientas como QGIS, gvSIG o ArcGIS. Presentado en congreso Geocamp ES 2013, en Vigo.
Citation preview
GEOPROCESAMIENTO CON GDAL
Y POSTGIS RASTER
Jorge Arévalohttp://about.me/jorgeas80
GDAL committerPostGIS committer
¿Quién soy?
martes 25 de junio de 2013
¿Qué es GDAL?
• Librería Open Source + utilidades de línea de comandos
• Manipulación de datos tanto en formato raster como vectorial
• Abstracción cara a aplicaciones, para poder trabajar con cualquier formato soportado de manera transparente
• Multiplataforma: Linux - Windows - Mac
• Creada por Frank Warmerdam
martes 25 de junio de 2013
¿Para qué se usa?
• Principalmente, para convertir entre formatos
• También para reproyectar capas raster/vector
• ... pero tiene MUCHOS más usos
martes 25 de junio de 2013
GDAL ES
SEXY
¡PAMELA GDALNDERSON!
por @carlosazaustre
martes 25 de junio de 2013
GDAL ES
SEXY II
¡DAVID GDALSSELHOF!
por @carlosazaustre
martes 25 de junio de 2013
QUIZ #1
¿En qué año comenzó el desarrollo de GDAL?
martes 25 de junio de 2013
gdalinfo: datos capa rasterECW: FileInfo: SizeXY=110680,74840 Bands=3 OriginXY=511960,4.68695e+06 CellIncrementXY=0.25,-0.25 ColorSpace=4, eCellType=0
ECW: projection=NUTM29, datum=ETRS89, units=METERSGDAL: GDALOpen(PNOA_MR_OF_ETRS89_HU29_h50_0223.ecw, this=0x8da42a8) succeeds as ECW.Driver: ECW/ERDAS Compressed Wavelets (SDK 3.x)Files: PNOA_MR_OF_ETRS89_HU29_h50_0223.ecwSize is 110680, 74840Coordinate System is `'Origin = (511960.000000000000000,4686950.000000000000000)Pixel Size = (0.250000000000000,-0.250000000000000)Metadata: COLORSPACE=RGB COMPRESSION_RATE_TARGET=10 VERSION=2Corner Coordinates:Upper Left ( 511960.000, 4686950.000) Lower Left ( 511960.000, 4668240.000) Upper Right ( 539630.000, 4686950.000) Lower Right ( 539630.000, 4668240.000) Center ( 525795.000, 4677595.000) Band 1 Block=256x256 Type=Byte, ColorInterp=Red Description = Red Overviews: 55340x37420, 27670x18710, 13835x9355, 6917x4677, 3458x2338, 1729x1169, 864x584, 432x292, 216x146Band 2 Block=256x256 Type=Byte, ColorInterp=Green Description = Green Overviews: 55340x37420, 27670x18710, 13835x9355, 6917x4677, 3458x2338, 1729x1169, 864x584, 432x292, 216x146Band 3 Block=256x256 Type=Byte, ColorInterp=Blue Description = Blue Overviews: 55340x37420, 27670x18710, 13835x9355, 6917x4677, 3458x2338, 1729x1169, 864x584, 432x292, 216x146
Tip:export CPL_DEBUG=ecw
martes 25 de junio de 2013
gdal_translate: clipgdal_translate -a_srs epsg:25829 -projwin 522222.0661435421 4675944.730194233 522941.44762708514 4675225.314583662PNOA_MR_OF_ETRS89_HU29_h50_0223.ecw monte_do_castro.tif
martes 25 de junio de 2013
gdal_translate: clip
martes 25 de junio de 2013
gdal_translate: reducir resolución
Resolución al 10% de la original
gdal_translate -outsize 10% 10%-a_srs epsg:25829 PNOA_MR_OF_ETRS89_HU29_h50_0223.ecw PNOA_MR_OF_ETRS89_HU29_h50_0223_red.tif
martes 25 de junio de 2013
gdalwarp: remuestreargdalwarp -ts 22136, 14968-r cubicsplinePNOA_MR_OF_ETRS89_HU29_h50_0223_red.tifPNOA_MR_OF_ETRS89_HU29_h50_0223_2x.tif
Espec ificamos e l t amaño deseado y el algoritmo de remuestreo a utilizar
martes 25 de junio de 2013
gdal_edit.py: editar metadatos
gdal_edit.py -a_nodata -32768 -a_srs epsg:25829 PNOA_MR_OF_ETRS89_HU29_h50_0223.tif
martes 25 de junio de 2013
Optimizandogdal_translate -co TILED=YES -co COMPRESS=DEFLATE -co INTERLEAVE=PIXELPNOA_MR_OF_ETRS89_HU29_h50_0223.tif PNOA_MR_OF_ETRS89_HU29_h50_0223_tiled.tif
gdaladdo PNOA_MR_OF_ETRS89_HU29_h50_0223_tiled.tif 2 4 8 16 32 64
martes 25 de junio de 2013
QUIZ #2
¿Cuántos drivers maneja GDAL/OGR?
martes 25 de junio de 2013
Mapa de elevacióngdal_contour -a elev -i 25 MDT25-0223-H29.asc dem_vigo.shp
martes 25 de junio de 2013
Mapa de relievegdaldem hillshade MDT25-0223-H29.asc hillshade_vigo.tif
martes 25 de junio de 2013
¿Qué tal las dos cosas? gdal_rasterize
gdal_rasterize -b 1 -b 2 -b 3 -burn 255 -burn 0 -burn 0 -where 'elev > 500' -l dem_vigo dem_vigo.shp dem_vigo_rasterized.tif
gdal_rasterize -b 1 -b 2 -b 3 -burn 255 -burn 100 -burn 0 -where 'elev > 350 and elev <= 500' -l dem_vigo dem_vigo.shp dem_vigo_rasterized.tif
gdal_rasterize -b 1 -b 2 -b 3 -burn 255 -burn 180 -burn 130 -where 'elev > 200 and elev <= 350' -l dem_vigo dem_vigo.shp dem_vigo_rasterized.tif
gdal_rasterize -b 1 -b 2 -b 3 -burn 190 -burn 180 -burn 80 -where 'elev > 100 and elev <= 200' -l dem_vigo dem_vigo.shp dem_vigo_rasterized.tif
gdal_rasterize -b 1 -b 2 -b 3 -burn 0 -burn 255 -burn 0 -where 'elev <= 100' -l dem_vigo dem_vigo.shp dem_vigo_rasterized.tif
martes 25 de junio de 2013
¿Qué tal las dos cosas? gdal_rasterize
Monte de O Castro
martes 25 de junio de 2013
¿Y PostGIS Raster?¡Nueva versión! Buen rendimiento en visualización (QGIS, Mapserver)
Desde 2013-06-19
https://github.com/jorgeas80/gdal_postgis_raster_driver.git
martes 25 de junio de 2013
GDAL + PostGIS RasterCargamos en PostGIS el SHP generado a partir del DEM
Cargamos en PostGIS Raster el TIFF generado a partir del DEM
shp2pgsql -s epsg:25829 -I dem_vigo.shp > dem_vigo.sqlpsql -d geocamp -f dem_vigo.sql
raster2pgsql -s epsg:25829 -I -M -C -t 50x50 hillshade_vigo.tiff > hillshade_vigo.sqlpsql -d geocamp -f dem_vigo.sql
martes 25 de junio de 2013
GDAL + PostGIS RasterObtenemos la intersección de ambas capas únicamente en los puntos en los que la altitud es mayor a 600 m
create table hillshade_up_from_600 asselect st_clip(rast, geom) as rastfrom hillshade_vigo, dem_vigo where st_intersects(rast, geom) and elev > 600
alter table hillshade_up_from_600 add column rid bigserial primary key;
select addrasterconstraints('hillshade_up_from_600', 'rast')
gdal_translate PG:"dbname=geocamp table=hillshade_up_from_600 mode=2" hillshade_up_from_600.tif
martes 25 de junio de 2013
GDAL + PostGIS Raster
martes 25 de junio de 2013
Quiz #3
¿En qué orden muestra GDAL los drivers disponibles?
martes 25 de junio de 2013
Quiz #3a) Orden alfabético
b) Como les da la gana a los desarrolladores
c) Primero los compilados de manera interna y luego los enlazados externamente
martes 25 de junio de 2013
OGR: Geocoding
http://erouault.blogspot.fr/2012/12/a-geocoding-client-api-in-gdalogr.html
/* Create a session with default options */OGRGeocodingSessionH hSession = OGRGeocodeCreateSession(NULL);
/* Now query the service */ OGRLayerH hLayer = OGRGeocode(hSession, "Paris", NULL, NULL);
/* Use the result layer (the first feature is generally the most relevant) */
/* Cleanup */OGRGeocodeFreeResult(hLayer);OGRGeocodeDestroySession(hSession);
SELECT ST_Centroid(ogr_geocode('Paris'))
returns:
OGRFeature(SELECT):0POINT (2.342878767069653 48.85661793020374)
En C En SQL
Más info
martes 25 de junio de 2013
Más funcionalidades sexy de OGRhttp://trac.osgeo.org/gdal/wiki/rfc39_ogr_layer_algebra
http://gdal.org/ogr/ogr_sql_sqlite.html
OGR álgebra
SQL sobre capas no SQL(soporta dialecto SQLite)
martes 25 de junio de 2013
Enlaces útiles
• http://www.gdal.org/
• http://trac.osgeo.org/gdal/
• http://home.gdal.org/~warmerda/
• http://erouault.blogspot.fr/
• http://trac.osgeo.org/postgis/wiki/WKTRaster
• http://trac.osgeo.org/gdal/wiki/frmts_wtkraster.html
martes 25 de junio de 2013
Créditos
• Roger Andre (http://download.osgeo.org/gdal/presentations/OpenSource_Weds_Andre_CUGOS.pdf)
• Even Rouault (http://even.rouault.free.fr/)
martes 25 de junio de 2013
MUCHAS GRACIAS
Jorge Aré[email protected]@libregis.org
Junio 2013
¡Escríbeme!
martes 25 de junio de 2013