3

I'm attempting to create a raster file from XYZ data. I used GDAL.Grid on a .csv file with XYZ data and .vrt definition. The code produces a .tif file with no data. I'm having a hard time troubleshooting my code as Python GDAL is not throwing any error on Google Colab. I tried changing data, .vrt definition, and parameters of gdal.grid.

A reproducible example is located here:

asked May 8, 2021 at 20:33
1
  • Good question, but the reproducible code you linked is generally not available. Could you either make the code fully reproducible on the site, allow the colab access to anyone, or something else? Commented Aug 3, 2023 at 16:31

2 Answers 2

3

This is a well-known python GDAL "gotcha". The data doesn't get written until the dataset is closed and dereferenced.

lin = None
#Or
del lin

Apart from that, your code works for me:

enter image description here

answered May 8, 2021 at 21:34
1
  • Thanks! I'm the latest victim :) Commented May 8, 2021 at 21:52
2

A test with your CSV file and gdal_command line utility print a lot of errors. It seems that your sample data is not suitable.

gdal_grid grid.vrt -a linear -zfield Elevation out.tif
Warning 1: qhull precision error: initial facet 1 is coplanar with the interior point
Warning 1: ERRONEOUS FACET:
Warning 1: - f1
Warning 1: - flags:
Warning 1: bottom
Warning 1: simplicial
Warning 1: upperDelaunay
Warning 1: flipped
Warning 1:
Warning 1: - normal:
Warning 1: 0
Warning 1: -1
Warning 1: -0
Warning 1:
Warning 1: - offset: 1.383757e+07
Warning 1: - vertices:
Warning 1: p5(v2)
Warning 1: p4(v1)
Warning 1: p0(v0)
Warning 1:
Warning 1: - neighboring facets:
Warning 1: f2
Warning 1: f3
Warning 1: f4
Warning 1:
Warning 1:
While executing: | qhull d Qbb Qc Qz Qt
Warning 1: Options selected for Qhull 2012.1 2012年02月18日:
 run-id 1515622475 delaunay Qbbound-last Qcoplanar-keep Qz-infinity-point
 Qtriangulate _pre-merge _zero-centrum Qinterior-keep Pgood
 _max-width 2.4e+03 Error-roundoff 1.4e-08 _one-merge 1e-07
 Visible-distance 2.9e-08 U-coplanar-distance 2.9e-08 Width-outside 5.8e-08
 _wide-facet 1.7e-07
Warning 1:
Warning 1: precision problems (corrected unless 'Q0' or an error)
Warning 1: 2
Warning 1: flipped facets
Warning 1:
The input to qhull appears to be less than 3 dimensional, or a
computation has overflowed.
Qhull could not construct a clearly convex simplex from points:
Warning 1:
Warning 1: - p1(v3):
Warning 1: 3.1e+06
Warning 1: 1.4e+07
Warning 1: 0.45
Warning 1:
Warning 1: - p5(v2):
Warning 1: 3.1e+06
Warning 1: 1.4e+07
Warning 1: 2.4e+03
Warning 1:
Warning 1: - p4(v1):
Warning 1: 3.1e+06
Warning 1: 1.4e+07
Warning 1: 1.8
Warning 1:
Warning 1: - p0(v0):
Warning 1: 3.1e+06
Warning 1: 1.4e+07
Warning 1: 0
Warning 1:
Warning 1:
The center point is coplanar with a facet, or a vertex is coplanar
with a neighboring facet. The maximum round off error for
computing distances is 1.4e-08. The center point, facets and distances
to the center point are as follows:
Warning 1: center point
Warning 1: 3.126e+06
Warning 1: 1.384e+07
Warning 1: 600.6
Warning 1:
Warning 1:
Warning 1: facet
Warning 1: p5
Warning 1: p4
Warning 1: p0
Warning 1: distance= 0
Warning 1: facet
Warning 1: p1
Warning 1: p4
Warning 1: p0
Warning 1: distance= 0
Warning 1: facet
Warning 1: p1
Warning 1: p5
Warning 1: p0
Warning 1: distance= 0
Warning 1: facet
Warning 1: p1
Warning 1: p5
Warning 1: p4
Warning 1: distance= 0
Warning 1:
These points either have a maximum or minimum x-coordinate, or
they maximize the determinant for k coordinates. Trial points
are first selected from points that maximize a coordinate.
Warning 1:
The min and max coordinates for each dimension are:
Warning 1: 0: 3.125e+06 3.127e+06 difference= 2400
Warning 1: 1: 1.384e+07 1.384e+07 difference= 0
Warning 1: 2: 0 2400 difference= 2400
Warning 1:
If the input should be full dimensional, you have several options that
may determine an initial simplex:
 - use 'QJ' to joggle the input and make it full dimensional
 - use 'QbB' to scale the points to the unit cube
 - use 'QR0' to randomly rotate the input for different maximum points
 - use 'Qs' to search all points for the initial simplex
 - use 'En' to specify a maximum roundoff error less than 1.4e-08.
 - trace execution with 'T3' to see the determinant for each point.
Warning 1:
If the input is lower dimensional:
 - use 'QJ' to joggle the input and make it full dimensional
 - use 'Qbk:0Bk:0' to delete coordinate k from the input. You should
 pick the coordinate with the least range. The hull will have the
 correct topology.
 - determine the flat containing the points, rotate the points
 into a coordinate plane, and delete the other coordinates.
 - add one or more points to make the input full dimensional.
ERROR 1: Delaunay triangulation failed
answered May 8, 2021 at 21:35
3
  • Thanks! What does that mean. How can I fix this? I just tried converting CSV to shapefile and then using gdal.grid using QGIS. The results looks good there. Since I might be processing many such files, it would be better to avoid additional steps. Thanks again! Commented May 8, 2021 at 21:40
  • I could not open your link again and I am not sure if I copied the whole csv dataset. What I did copy contain points which all have the Y coordinate value 13837571.7. I guess that it explains the errors about triangulation, the points are all on the same line and it is not possible to make triangles. The error may be irrelevant for your real data. Commented May 9, 2021 at 7:08
  • Makes perfect sense! I will read more about Delaunay triangulation. Thanks! Commented May 9, 2021 at 12:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.