Project 1811 gdal_question 02 - geopaparazzi/Spatialite-Tasks-with-Sql-Scripts GitHub Wiki
<-- 'Index Page for RasterLite2'
<-- 'Question of 2015-06-10 from gdal-dev'
<-- 'Answer to question 1: Can I create a transparent GeoTIFF like PNG with alpha channel ?'
2. Can I used gdal_rasterize to draw shape over the GeoTIFF with transparency
- yes, you can use 'gdal_rasterize'
- together with 'gdalbuildvrt' and 'gdal_translate'
Goal:
- create an png image
- which is a combination of the pgn-image created in 'Question 3'

- a rasterized image of the streets of 1786 (in green - 0,173,83)
- a rasterized image of the streets of 1844 (in red - 255,0,0)
With the exception of the given colour, the commands are the same:
gdal_rasterize -tr 0.475211759942328 0.475212956422887 -te 24800 20700 25800 21300 -ot Byte -init 192 -a_nodata 192 -burn 0 -burn 173 -burn 83 -sql "SELECT ST_Buffer(soldner_segment,2.5) FROM segments_berlin_1786" ../sources/berlin_segments_qgis.db segments_berlin_1786_green.tif
Parameters:
Use of the following parameters only for new images
- -a_nodata, -a_srs, -co, -init, -of, -ot, -tap, -te, -tr and -ts
For creation of new image only:
-
-a_nodata192- read value from
gdalinfo
- read value from
-
-te: [ulx (min_x) lry (min_y) lrx (max_x) uly (max_y)]24800,20700,25800,21300--projwin[ulx (min_x) uly (max_y) lrx (max_x) lry (min_y)]24800 21300 25800 20700- do not get confused at the different order between
-teandprojwin
- do not get confused at the different order between
-
-tr(xres yres)0.475211759942328 0.475212956422887- use the resolution found in the final png-image with
gdalinfo- Pixel Size = (0.475211759942328,-0.475212956422887)
- Note: the
yresmust be a positive value
- Note: the
- Pixel Size = (0.475211759942328,-0.475212956422887)
- use the resolution found in the final png-image with
-
-init: Pre-initialize the output image bands- 192
-
-ot: for an RGB Image- Byte
For creation of both new image and existing image:
-
-burnthe RGB values desiredgreen (dark): 0,173,83-burn 0 -burn 173 -burn 83
red: 255,0,0
-
-sql- this is needed for 2 reasons:
- the used view has more than one field/column
- using
-lwith the view-name returns a blank image - thus
SELECT soldner_segment FROM segments_berlin_1786soldner_segmentwill be used- Warning: this will cause the created line to be 1 pixel wide
- using
ST_Buffer(): this will set the width of the created line- sample found here: 'Controlling output linewidth linestyle using gdal_rasterize shapefile shp to Geotiff'
- to calculate the value used with ST_Buffer:
- linestring width 5.0 (pixels)
- image resolution 1.0 (pixels per meter)
- 2.5=((1*5)/2)
- image resolution 970.429903115999991 (pixels per meter)
- 2426.07475779=((970.429903115999991*5)/2)
- the final sql used was
SELECT ST_Buffer(soldner_segment,2.5) FROM segments_berlin_1786
- the used view has more than one field/column
- this is needed for 2 reasons:
-
ogr-source- in this case I used a
spatialitedatabase
- in this case I used a
-
output-file
Note:
- the combination of
-initand-otseem to insure that the created image is an RGB image- and thus show up correctly in QGIS (otherwise the lines are black, Grayscale)
Next step: combine the 3 images with:
- 'gdalbuildvrt'
- first create a file with a list of the input-images
1811.Neuester_Grundriss_von_Berlin.streets.txt- for use with the
-input_file_listparameter
- first create a file with a list of the input-images
1811.Neuester_Grundriss_von_Berlin.5800.3068.area_rote_rathausturm_panorama.png
segments_berlin_1844_red.tif
segments_berlin_1786_green.tif
Note:
- the order is important
- that that comes last, wins (i.e. will be shown)
- in this case I want the 'younger/red/1844' streets
- to be over-painted by the 'older/green/1786' streets
- both should over-paint the map
- to be over-painted by the 'older/green/1786' streets
- in this case I want the 'younger/red/1844' streets
- that that comes last, wins (i.e. will be shown)
gdalbuildvrt -overwrite -b 1 -b 2 -b 3 -resolution highest -vrtnodata '192' -input_file_list 1811.Neuester_Grundriss_von_Berlin.streets.txt 1811.Neuester_Grundriss_von_Berlin.streets.vrt
# create the final png, after checking the .vrt file in QGIS
gdal_translate -of PNG 1811.Neuester_Grundriss_von_Berlin.streets.vrt 1811.Neuester_Grundriss_von_Berlin.streets.3068.png
The final result of 1811.Neuester_Grundriss_von_Berlin.streets.3068.png:

All roads lead to Rome
- this is one, of possibly, many
<-- 'Answer to question 1: Can I create a transparent GeoTIFF like PNG with alpha channel ?'
<-- 'Question of 2015-06-10 from gdal-dev'
2015-06-11: Mark Johnson, Berlin Germany