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:
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
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.