Search code examples
rastergdalshapefilegeotiff

How to create irregular raster with gdal using csv points


I am trying to create a irregular shaped .tiff from a csv list of points (xyz data). I am doing this using gdal_grid.

I can seem to generate the .tiff file no problem but I cannot preserve the outline / shape of the original csv points.

Everytime I generate the .tiff file it creates a raster with the size of (xmax-xmin) x (ymax-ymin) and assigns interpolated values to pixels that fall far away from my initial points.

Is it possible to generate a .tiff file of ONLY the points I provide?

For context, I am trying to generate a raster of xyz data for a river, and only want the raster in the river (not the entire bounding box of the river). I am only providing xyz data in the river.

I tried playing with the -nodata flag, and limiting -max_points to the number of points I've provided.

My final code (once everything is imported and declared):

gdal_grid -a invdist:power=2.0:smoothing=1.0:nodata=-999:max_points=2128164 -txe 582387.4 591069.4 -tye 4505028.08 4515344.079999999 -outsize 50 50 -zfield "z" -of GTiff -ot Float64 -l Book2 Book2.vrt Book2.tiff


Solution

  • Welcome to Stack Overflow, Derek!

    Maybe there is a creation option inside gdal_grid that would do it, but I think that you will have to achieve desired result with additional calculation:

    1. Run the gdal_grid as you have it.
    2. Create a concave hull from the given points. If this is a one time job, I suggest using QGIS (with grass tools), because there is some tweaking of concave hull parameters required.
    3. Cut the raster with the created shapefile by using gdalwarp.

    Let me know if this got you through!