0

I am trying to grid point cloud data. I created a csv with coordinates x,y and elevation z-values.

The first lines of the .csv file look like this:

"X", "Y", "Z"
666578.24179169,5747856.3361029,-0.24
666578.251458881,5747856.34642544,-0.24
666578.250803538,5747856.36641516,-0.24
666578.250803538,5747856.36641516,-0.25
666578.260143058,5747856.38673256,-0.25

I run the following code in R:

gdal_setInstallation()
valid_install <- !is.null(getOption("gdalUtils_gdalPath"))


temporary_dir <- "directory"
tempfname_base <- file.path(temporary_dir,"dem")
tempfname_csv <- paste(tempfname_base,".csv",sep="")

# Now make a matching VRT file
tempfname_vrt <- paste(tempfname_base,".vrt",sep="")
vrt_header <- c(
  '<OGRVRTDataSource>',
  '\t<OGRVRTLayer name="dem">',
  '\t<SrcDataSource>dem.csv</SrcDataSource>',
  '\t<GeometryType>wkbPoint</GeometryType>', 
  '\t<GeometryField encoding="PointFromColumns" x="X" y="Y" z="Z"/>',
  '\t</OGRVRTLayer>',
  '\t</OGRVRTDataSource>'           
)
vrt_filecon <- file(tempfname_vrt,"w")
writeLines(vrt_header,con=vrt_filecon)
close(vrt_filecon)

tempfname_tif <- paste(tempfname_base,".tiff",sep="")

# Now run gdal_grid:
gdal_grid(src_datasource=tempfname_vrt,
                    dst_filename=tempfname_tif, a="invdist:power=2.0:smoothing=1.0",
                    txe=c(666360.2, 666580.4),tye=c(5747818, 5747878),outsize=c(400,400),
                    of="GTiff",ot="Float64",l="dem",output_Raster=TRUE)

The code does not give any error, but results in only null-values (elevation).

  • Works for me. Why do you think the values are null? I get a dem.tiff generated and library(raster);r = raster("./dem.tiff");summary(r[]) shows the values are around 0.24 which is expected from the data. – Spacedman Aug 27 at 13:31
  • You have a missing library(gdalUtils) call. – Spacedman Aug 27 at 13:31
  • If I run code through the command window I get the error 'Failed to open datasource 'dem.csv' No point geometry found on layer dem, skipping. – judith Aug 27 at 13:36
  • I think you need to get the full path to dem.csv into the .vrt file if the CSV isn't in the current folder. – Spacedman Aug 27 at 13:46

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.