NON-DUPLICATE EDIT: This question is not a duplicate because I have tried the solution presented as the answer to the "original" question and it did not work. See results below.

I am attempting to use gdal.Grid in python to interpolate a .txt or .csv to a raster. I keep getting "ERROR 1: Failed to open datasource 'file.csv'. No point geometry found on layer file, skipping."

How do I get gdal.Grid to recognize the file? Or how do I need to alter the file in order to get gdal to recognize it?

EDIT: Ran ogrinfo twice, both with txt and csv versions. The results were the same each time, with the only difference being the extensions each time matched what was in the vrt and what the file was. ___Stupid question, if a text file is structured like a csv you can usually just change the extension to csv and programs will handle it, I've been doing that when "changing format", could this be part of the issue?

Below, column 1 is x, column 2 is y, column 3 is z but they do not have headers.

Data file structure:


VRT file

    <OGRVRTLayer name="file">
        <GeometryField encoding="PointFromColumns" x="field_1" y="field_2" z="field_3"/>

Relavant python code

rasname = str(file)
rasname = rasname.split('\\')
rasname = rasname[-1]
rasname = rasname.strip('.txt')
vrtname = rasname + '.vrt'
vrtname = input_dir + '\\' + vrtname

outputfile = output_dir + str(rasname) + '.tif'

gridopt = gdal.GridOptions(format='GTiff',algorithm='invdist:power=2')

output = gdal.Grid(outputfile, vrtname, options=gridopt)

Results of ogrinfo

INFO: Open of 'file.vrt' using driver 'OGR_VRT' successful.
Warning 1: Cannot open datasource 'file.csv' in update mode. Trying again in read-only mode
Error 1: Failed to open datasource 'file.csv'

Layer name: file
Geometry: None
Feature Coutn: 0
Layer SRS WKT: 
  • Use <SrcDataSource>CSV:file.txt</SrcDataSource> to fix it. – Mike T Aug 8 '18 at 21:09
  • @ Luke, I've tried using changing the name/format from txt to csv. Both have resulted in either .csv or .txt error. I've made sure the VRT matches when I make the change. – NorthLand Aug 8 '18 at 21:16
  • @Mike T I attempted this just now, I receive the same error. – NorthLand Aug 8 '18 at 21:16
  • What version of GDAL? – Mike T Aug 8 '18 at 21:27
  • 2.2.4 in python 3.7 – NorthLand Aug 8 '18 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.