30 | | - Use gdalinfo to review several datasets. |
31 | | - Highlight: |
32 | | image size |
33 | | geotransform |
34 | | gcps |
35 | | coordinate system |
36 | | metadata |
37 | | band type |
38 | | block size |
39 | | nodata value |
40 | | color table |
41 | | |
42 | | - Use OpenEV to view datasets. |
43 | | - Highlight: |
44 | | finding exact location of a pixel (and subpixel position issues) |
45 | | Seeing pixel greyscale values (and for multiple bands) |
46 | | "see through" due nodata and alpha bands. |
47 | | Overlay flipping |
48 | | |
49 | | Perhaps also demonstrate something similar with QGIS? |
50 | | }}} |
51 | | |
52 | | == Simple Format Translation == |
53 | | |
54 | | === Know your Drivers === |
55 | | |
56 | | The --formats commandline switch of gdal_translate can be used to see a list of available format drivers. Each format reports if it is read only (ro), read/write (rw) or read/write/update (rw+). |
57 | | |
58 | | {{{ |
| 32 | GDAL Overview |
| 33 | ----------------- |
| 34 | |
| 35 | 5 minute introduction to GDAL. |
| 36 | |
| 37 | |
| 38 | 1 Exploring Your Image Data |
| 39 | --------------------------- |
| 40 | |
| 41 | 1a) Use gdalinfo to get information about the dataset. |
| 42 | |
| 43 | gdalinfo world.png |
| 44 | |
| 45 | Note: |
| 46 | - Driver is "PNG" |
| 47 | - Size is 2048x1024 |
| 48 | - 3 Bands of type Byte. |
| 49 | - No coordinate system and bounds are just pixel/line based. |
| 50 | |
| 51 | 1b) More with gdalinfo. |
| 52 | |
| 53 | gdalinfo -mm east.dem |
| 54 | |
| 55 | Note: |
| 56 | - Coordinate system is NAD83 (expressed as WKT). |
| 57 | - Origin, Pixel Size and bounds are all provided. |
| 58 | - Band is now of type "Int16" |
| 59 | - Nodata Value is -32767 |
| 60 | - Unit type is "m" |
| 61 | - Min/max elevation values shown (computed due to -mm switch) |
| 62 | |
| 63 | 1c) Even more with gdalinfo: |
| 64 | |
| 65 | gdalinfo 092b05.tif |
| 66 | |
| 67 | Note: |
| 68 | - Extra bits of TIFF metadata. |
| 69 | - Notes the compression |
| 70 | - UTM corner coordinates also reported as lat/long. |
| 71 | - Color table |
| 72 | |
| 73 | 1d) Look at your data! |
| 74 | |
| 75 | openev world.png |
| 76 | |
| 77 | Note: No georeferenced coordinates |
| 78 | |
| 79 | openev east.dem |
| 80 | |
| 81 | Note: You can point at pixels and see the elevations, and everything is |
| 82 | georeferenced. |
| 83 | |
| 84 | openev 092b05.tif |
| 85 | |
| 86 | Right click on the layer in layer dialog and look at the "Coordinate |
| 87 | System" and "Image Info" tabs for some info similar to gdalinfo. |
| 88 | |
| 89 | 1e) If you have a minute, try looking at some of the files with QGIS, |
| 90 | uDig, etc |
| 91 | |
| 92 | |
| 93 | 2 Simple Format Translation |
| 94 | --------------------------- |
| 95 | |
| 96 | -- Know your Drivers -- |
| 97 | |
| 98 | 2a) The --formats commandline switch of gdal_translate can be used to see a |
| 99 | list of available format drivers. Each format reports if it is read |
| 100 | only (ro), read/write (rw) or read/write/update (rw+). |
| 101 | |
| 143 | |
| 144 | 3 Correcting Metadata |
| 145 | --------------------- |
| 146 | |
| 147 | -- Set Coordinate System and Bounds -- |
| 148 | |
| 149 | 3a) Use gdal_translate to attach bounds, and coordinate system: |
| 150 | |
| 151 | gdal_translate -a_srs WGS84 -a_ullr -180 90 180 -90 world.png geoworld.tif |
| 152 | |
| 153 | 3b) Confirm reporting of coordinate system and georeferencing with gdalinfo: |
| 154 | |
| 155 | gdalinfo geoworld.tif |
| 156 | |
| 157 | 3c) Confirm reporting of georeferenced locations with OpenEV (optional) |
| 158 | |
| 159 | openev geoworld.tif |
| 160 | |
| 161 | -- Reset NODATA values -- |
| 162 | |
| 163 | 3d) Use gdal_translate to attach/change the nodata value of a file. |
| 164 | |
| 165 | gdal_translate -a_nodata 0 west.dem zeronodata.tif |
| 166 | |
| 167 | 3e) Use gdalinfo to verify nodata value differs between the two files. |
| 168 | |
| 169 | gdalinfo west.dem |
| 170 | gdalinfo zeronodata.tif |
| 171 | |
| 172 | |
| 173 | Reprojecting |
| 174 | ------------ |
| 175 | |
| 176 | For this process we assume that geoworld.tif has been properly created with |
| 177 | bounds and coordinate system info in the previous steps. |
| 178 | |
| 179 | a) The gdalwarp command can be used to reproject images. Here we reproject |
| 180 | the WGS84 geographic image to the Mercator projection: |
| 181 | |
| 182 | gdalwarp -t_srs '+proj=merc +datum=WGS84' geoworld.tif mercator.tif |
| 183 | |
| 184 | Compare the images with OpenEV |
| 185 | |
| 186 | openev mercator.tif |
| 187 | openev geoworld.tif |
| 188 | |
| 189 | b) Here we reproject to the Ortho projection. |
| 190 | |
| 191 | gdalwarp -t_srs '+proj=ortho +datum=WGS84' geoworld.tif ortho.tif |
| 192 | |
| 193 | openev ortho.tif |
| 194 | |
| 195 | c) Note how the poles are clipped? This is because the edges at the pole |
| 196 | can't be reprojected gdalwarp does not read all the data. We can force |
| 197 | gdalwarp to read a bunch of surplus data around chunks as one way to |
| 198 | resolve this. |
| 199 | |
| 200 | gdalwarp -wo SOURCE_EXTRA=125 -t_srs '+proj=ortho +datum=WGS84' |
| 201 | geoworld.tif ortho.tif |
| 202 | |
| 203 | d) gdalwarp can also be cause to treat particular values as nodata and to |
| 204 | produce alpha values in the output. In this example we cause oceans to |
| 205 | be treated as transparent, and generate alpha in the output. |
| 206 | |
| 207 | gdalwarp -wo SOURCE_EXTRA=125 -srcnodata "11 10 50" -dstalpha |
| 208 | -t_srs '+proj=ortho +datum=WGS84' |
| 209 | geoworld.tif ortho.tif |
| 210 | |
| 211 | Hmm, it seems the water isn't quite as uniformly blue as I hoped. It |
| 212 | must have lived as a lossily compressed image at one point! |
| 213 | |
| 214 | |
| 215 | Mosaicing |
| 216 | --------- |
| 217 | |
| 218 | a) gdal_merge.py is a python script that can be used for simple mosaicing |
| 219 | tasks. Mosaic the east.dem and west.dem into a single file: |
| 220 | |
| 221 | gdal_merge east.dem west.dem -o mergeddem.tif |
| 222 | |
| 223 | For extra credit, open gdal_merge.py in notepad and review. It's scary, |
| 224 | but not as scary as you might think! |
| 225 | |
| 226 | notepad "C:\Program Files\FWTools-1.3.6\pymod\gdal_merge.py" |
| 227 | |
| 228 | b) The same task can be accomplished with gdalwarp. gdalwarp has a variety |
| 229 | of advantages over gdal_merge, but can be slow to merge many files: |
| 230 | |
| 231 | gdalwarp east.dem west.dem warpmerged.tif |
| 232 | |
| 233 | c) Now lets mosaic two CanMatrix image for our area: |
| 234 | |
| 235 | gdalwarp 092b05.tif 092b06.tif mosaic1.tif |
| 236 | |
| 237 | Seems successful, but if we look at the image with OpenEV ... a mess! |
| 238 | |
| 239 | openev mosaic1.tif |
| 240 | |
| 241 | d) The problem is that the images have different pseudocolor tables. So |
| 242 | lets convert from pseudocolor to RGB and then mosaic. To speed up |
| 243 | later steps we will also reduce the resolution by half. |
| 244 | |
| 245 | gdal_translate -outsize 50% 50% 092b05.tif small5.tif |
| 246 | gdal_translate -outsize 50% 50% 092b06.tif small6.tif |
| 247 | |
| 248 | pct2rgb small5.tif rgb5.tif |
| 249 | pct2rgb small6.tif rgb6.tif |
| 250 | |
| 251 | gdalwarp rgb5.tif rgb6.tif mosaic2.tif |
| 252 | |
| 253 | Hmm, better but clearly we have a problem with collar overlaps. |
| 254 | |
| 255 | e) So, lets try stripping the collars off. We can do this manually by |
| 256 | digitizing a polygon representing the "valid" area of the map. This |
| 257 | can be done in OpenEV, QGIS, etc, but for our purposes we provide a |
| 258 | pre-created cutline. Review it with: |
| 259 | |
| 260 | openev rgb06.tif cutline06.shp |
| 261 | |
| 262 | "Burn away" the inverse of the polygon using the command: |
| 263 | |
| 264 | gdal_rasterize -i -burn 17 -b 1 -b 2 -b 3 cutline06.shp -l cutline06 rgb6.tif |
| 265 | |
| 266 | Review the result, we should have "17,17,17" for all outside pixels. |
| 267 | |
| 268 | f) Now mosaic again, but request that "17" be treated as a nodata value. |
| 269 | |
| 270 | gdalwarp -srcnodata "17 17 17" rgb5.tif rgb6.tif mosaic3.tif |
| 271 | |
| 272 | A pretty good result, especially if we were to also strip the collar |
| 273 | off the first image. |
| 274 | |
| 275 | g) For extra points, rerun the warp with the -dstalpha option to add an |
| 276 | alpha (transparency) band for nodata areas. |
| 277 | |
| 278 | gdalwarp -dstalpha -srcnodata "17 17 17" rgb5.tif rgb6.tif mosaic4.tif |
| 279 | |
| 280 | |
| 281 | Optimizing |
| 282 | ---------- |
| 283 | |
| 284 | ... produce an optimized version of the previous mosaic. |
| 285 | |
| 286 | ideally demonstrate effect using a mapfile and shp2img? |
| 287 | |
| 288 | |
| 289 | Virtual Files |
| 290 | ------------- |
| 291 | |
| 292 | }}} |
| 293 | |
| 294 | |