Quick thoughts on transforming GeoTiff tags into parseable structure -> xml

Not a complete walk through here but some quick thoughts to a post for assist on twitter. What they wanted was to turn geotiff tags into csv or xml.

If you have GDAL installed & who doesn’t these days a quick way to turn the gdalinfo info (tags) into xml is to convert raster to Virtual Raster (VRT). This is an xml representation of raster.

>> gdal_translate -of VRT [destination name with .vrt extension]

This is what you end up with:

All that’s left to do is parse :)

<VRTDataset rasterXSize=”5529″ rasterYSize=”4607″>
<SRS>PROJCS[&quot;Lambert Conformal Conic&quot;,GEOGCS[&quot;NAD83&quot;,DATUM[&quot;North_American_Datum_1983&quot;,SPHEROID[&quot;GRS 1980&quot;,6378137,298.2572221010002,AUTHORITY[&quot;EPSG&quot;,&quot;7019&quot;]],AUTHORITY[&quot;EPSG&quot;,&quot;6269&quot;]],PRIMEM[&quot;Greenwich&quot;,0],UNIT[&quot;degree&quot;,0.0174532925199433],AUTHORITY[&quot;EPSG&quot;,&quot;4269&quot;]],PROJECTION[&quot;Lambert_Conformal_Conic_2SP&quot;],PARAMETER[&quot;standard_parallel_1&quot;,49],PARAMETER[&quot;standard_parallel_2&quot;,77],PARAMETER[&quot;latitude_of_origin&quot;,63.390675],PARAMETER[&quot;central_meridian&quot;,-91.86666666666666],PARAMETER[&quot;false_easting&quot;,6200000],PARAMETER[&quot;false_northing&quot;,3000000],UNIT[&quot;metre&quot;,1,AUTHORITY[&quot;EPSG&quot;,&quot;9001&quot;]]]</SRS>
<GeoTransform>  5.6058900000000000e+06,  3.0000000000000000e+01,  0.0000000000000000e+00,  3.8967900000000000e+06,  0.0000000000000000e+00, -3.0000000000000000e+01</GeoTransform>
<Metadata>
<MDI key=”AREA_OR_POINT”>Area</MDI>
</Metadata>
<VRTRasterBand dataType=”Float32″ band=”1″>
<Metadata>
<MDI key=”COLOR_TABLE_RULE_RGB_0″>0.000000e+00 4.821725e+01 255 255 0 0 255 0</MDI>
<MDI key=”COLOR_TABLE_RULE_RGB_1″>4.821725e+01 9.643450e+01 0 255 0 0 255 255</MDI>
<MDI key=”COLOR_TABLE_RULE_RGB_2″>9.643450e+01 1.446518e+02 0 255 255 0 0 255</MDI>
<MDI key=”COLOR_TABLE_RULE_RGB_3″>1.446518e+02 1.928690e+02 0 0 255 255 0 255</MDI>
<MDI key=”COLOR_TABLE_RULE_RGB_4″>1.928690e+02 2.410863e+02 255 0 255 255 0 0</MDI>
<MDI key=”COLOR_TABLE_RULES_COUNT”>5</MDI>
</Metadata>
<NoDataValue>-9.99900000000000E+03</NoDataValue>
<ColorInterp>Gray</ColorInterp>
<SimpleSource>
<SourceFilename relativeToVRT=”1″>cded_30m.tif</SourceFilename>
<SourceBand>1</SourceBand>
<SourceProperties RasterXSize=”5529″ RasterYSize=”4607″ DataType=”Float32″ BlockXSize=”5529″ BlockYSize=”1″ />
<SrcRect xOff=”0″ yOff=”0″ xSize=”5529″ ySize=”4607″ />
<DstRect xOff=”0″ yOff=”0″ xSize=”5529″ ySize=”4607″ />
</SimpleSource>
</VRTRasterBand>
</VRTDataset>