3

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

1 Answer 1

3

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.

2
  • ah thanks again, i suppose i can modify OGR code to support fixed-width :)
    – Lydon Ch
    May 2, 2011 at 1:11
  • Ah yes, if you're of a programming bent, then your options are greater. If you do make a change to the OGR code, it'd be great if you could submit it as a patch on the gdal-dev mailing list. May 2, 2011 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.