5

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:

555000,66600,001
555003,66610,002
555002,66601,003

VRT file

<OGRVRTDataSource>
    <OGRVRTLayer name="file">
        <SrcDataSource>CSV:file.csv</SrcDataSource>
        <GeometryType>wkbPoint</GeometryType>
        <GeometryField encoding="PointFromColumns" x="field_1" y="field_2" z="field_3"/>
    </OGRVRTLayer>
</OGRVRTDataSource>

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: 
(unknown)

closed as off-topic by user30184, LaughU, Fran Raga, whyzar, HDunn Jun 30 at 16:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – user30184, LaughU, Fran Raga, whyzar, HDunn
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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