GDAL – Troubleshooting gdal_grid Issues with VRT Files

gdalogr

I am trying to parse csv file and visualize it as geotiff using gdal_grid but I keep getting this error:

C:\work\testgdal1>gdal_grid -ot Float32 -l test  test.vrt dona.tif
ERROR 1: Failed to open datasource `test.csv'.
Unable to open input datasource "test.vrt".  
Failed to open datasource `test.csv'.

Both test.csv and test.vrt are in the same folder.

What can possibly go wrong and how to fix it?

Environment:

Windows 7 x64
osgeo4w as of 2 May 2011

test.vrt

<OGRVRTDataSource>
    <OGRVRTLayer name="test">
    <SrcDataSource>test.csv</SrcDataSource>        
    <SrcLayer>test</SrcLayer>
    <LayerSRS>WGS84</LayerSRS>
    <GeometryField encoding="PointFromColumns" x="field_10" y="field_9" z="field_20"/>
    <GeometryType>wkbPoint</GeometryType>
</OGRVRTLayer>

2 lines of test.csv

200010  207  020311    40658.5  406593 52 344927.31 7100203.50  -26.2078720  127.4491855 345060.64 7100369.14   26.4  650.3  628.0 55471.293    20.168 55648.817 55637.523  -146.062
200010  207  020311    40658.6  406594 52 344932.31 7100203.50  -26.2078726  127.4492355 345065.64 7100369.14   27.2  650.3  627.2 55456.719    20.172 55648.814 55637.520  -160.629

Best Answer

Ah yes, I feel slightly to blame for this... I've just re-read the page on OGR's handling of CSV and it says that it only accepts commas, semi-colons, and tabs as field delimiters, but your file is fixed-width.

What you will need to do is convert each run of spaces to a comma. In Linux you can use a sed script, but as you're in Windows your options are a bit more limited. A simple way would be to load the ASCII file into a spreadsheet program, telling it to use fixed-width fields, then save it out telling it to use commas as separators. Not ideal, I grant you, but it is a technique I've used in the past.