[R-sig-Geo] Trouble with 'gdal_grid'

Jonathan Greenberg jgrn at illinois.edu
Tue Jan 5 18:07:59 CET 2016


Xavier:

It looks like gdalUtils is not finding your install of GDAL -- first
question, are you up to date with the latest gdalUtils?

gdalUtils will only look in "standard" locations for the installs -- if you
have your install in a non-standard location (easy to do with the OSGEO
installer, since you can set the install directory to wherever you want
it), then you can fix it the following two ways:

1) Brute force-- as the error above stated, if you run:
gdal_setInstallation(ignore.full_scan=FALSE)

It will do a brute force search for it on your computer.  This could take
awhile, since it is searching your entire hard drive for any and all valid
gdal installs (technically, it is looking for the folder with "gdalinfo" or
"gdalinfo.exe").

A faster step would be before you run gdal_grid to:
1) Manually search on your computer for "gdal_grid.exe" -- you need to know
what folder it is hiding in.
2) Run:
gdal_setInstallation(search_path="pathto/gdalexecutables",rescan=T)

Note that gdalUtils does NOT use rgdal's install -- rgdal doesn't contain
the executables typically, at any rate.

Hope this helps!  Please let me know if you are still having problems.  I'm
going to cc r-sig-geo in this email (with your contact info removed) so
there is a record of this suggestion.

--j


> Dear Jonathan,
>
>
>
> I am trying to use the R wrapper ‘gdal_grid’ from the ‘gdalUtils’ R
> package, in order to perform interpolation on a dataset. But I encounter
> difficulties.
>
>
>
> Running a copy-paste of the example on p 37-38 of the package
> documentation:
>
>
>
> *# We'll pre-check to make sure there is a valid GDAL install*
>
> *# and that raster and rgdal are also installed.*
>
> *# Note this isn't strictly neccessary, as executing the function will*
>
> *# force a search for a valid GDAL install.*
>
> *gdal_setInstallation()*
>
> *valid_install <- !is.null(getOption("gdalUtils_gdalPath"))*
>
> *if(require(raster) && valid_install)*
>
> *{*
>
> *# Create a properly formatted CSV:*
>
> *temporary_dir <- tempdir()*
>
> *tempfname_base <- file.path(temporary_dir,"dem")*
>
> *tempfname_csv <- paste(tempfname_base,".csv",sep="")*
>
> *pts <- data.frame(*
>
> *Easting=c(86943.4,87124.3,86962.4,87077.6),*
>
> *Northing=c(891957,892075,892321,891995),*
>
> *Elevation=c(139.13,135.01,182.04,135.01)*
>
> *)*
>
> *write.csv(pts,file=tempfname_csv,row.names=FALSE)*
>
> *# 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="Easting" y="Northing"
> z="Elevation"/>',*
>
> *'\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:*
>
> *setMinMax(gdal_grid(src_datasource=tempfname_vrt,*
>
> *dst_filename=tempfname_tif,a="invdist:power=2.0:smoothing=1.0",*
>
> *txe=c(85000,89000),tye=c(894000,890000),outsize=c(400,400),*
>
> *of="GTiff",ot="Float64",l="dem",output_Raster=TRUE))*
>
> *}*
>
>
>
> Leads to the following message after the following two lines of code:
>
>
>
> > library(gdalUtils)
>
> > gdal_setInstallation()
>
> Warning messages:
>
> 1: In gdal_setInstallation() :
>
>   No GDAL installation found. Please install 'gdal' before continuing:
>
>         - www.gdal.org (no HDF4 support!)
>
>         - www.trac.osgeo.org/osgeo4w/ (with HDF4 support RECOMMENDED)
>
>         - www.fwtools.maptools.org (with HDF4 support)
>
>
>
> 2: In gdal_setInstallation() : If you think GDAL is installed, please run:
>
> gdal_setInstallation(ignore.full_scan=FALSE)
>
>
>
> However, I do have GDAL installed on my computer. GDAL was installed using
> the option 2 mentioned in the above Warning message (i.e.
> http://trac.osgeo.org/osgeo4w/).
>
>
>
> Also, loading and using the ‘rgdal’ package is no problem, as shown in the
> small example below:
>
>
>
> > setwd("D:/GIS/Preprocessing/Factories_and_beet_zones")
>
> > ### Subsetting ".csv" file for operating factories of a given year only
>
> > DF <- read.csv(file="Factories.csv", header = TRUE, sep = ";", dec = "," )
>
> > DF2 <- subset(DF, Year == "2013")
>
> > DF3 <- subset(DF2, Operating == "yes")
>
> >
>
> > ### Specifying project CRS
>
> > library(rgdal)
>
> Loading required package: sp
>
> rgdal: version: 1.1-1, (SVN revision 572)
>
>  Geospatial Data Abstraction Library extensions to R successfully loaded
>
>  Loaded GDAL runtime: GDAL 1.11.2, released 2015/02/10
>
>  Path to GDAL shared files: C:/Users/sauvenier.xavier/Documents/R/win-library/3.2/rgdal/gdal
>
>  GDAL does not use iconv for recoding strings.
>
>  Loaded PROJ.4 runtime: Rel. 4.9.1, 04 March 2015, [PJ_VERSION: 491]
>
>  Path to PROJ.4 shared files: C:/Users/sauvenier.xavier/Documents/R/win-library/3.2/rgdal/proj
>
>  Linking to sp version: 1.2-1
>
> > project_CRS <- CRS("+init=epsg:4326") #WGS84
>
>
>
> I have spent quite some time trying to understand what is going on. But so
> far I have failed.
>
>
>
> My R version is 3.2.2. My platform is a windows 64-bit (Windows Server 2012 Datacenter). And
>
>
>
> Would you have any idea on what I am doing wrong?
>
>
>
> Thanks for any help.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20160105/3fbd87f1/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.gif
Type: image/gif
Size: 4567 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20160105/3fbd87f1/attachment.gif>


More information about the R-sig-Geo mailing list