[R-sig-Geo] plotKML 'kml' function with raster input

Vijay Lulla vijaylulla at gmail.com
Wed Oct 14 00:52:44 CEST 2015


If you want to use backslash in your string then you'll have to double
them to remove the escape mechanism.  So your path should read
"C:\\Program Files\\GDAL\\gdalwarp.exe" etc.  Please see ?Quote in R
help.

However, there is another (simpler IMO) solution.  If you have the
latest QGIS installed then you can use SAGA and gdal utils from it.
That's how I sometimes use plotKML.  If you wish to try this solution
just download the source for plotKML package and apply the attached
patch.  Just make sure that the patch is in the top directory of
plotKML package (i.e. the directory which has DESCRIPTION and
NAMESPACE files in it).

HTH,
Vijay.

On Tue, Oct 13, 2015 at 12:25 PM, Gregovich, Dave P (DFG)
<dave.gregovich at alaska.gov> wrote:
> Paul,
> Thanks kindly for your response. I am not certain of what you mean. My windows search path has all backslashes (\) although I wasn't clear about this in my example. It is not possible to feed the gdalwarp and gdal_translate paths to plotKML.env() as strings with backslashes in them as they are recognized as escape characters.
> I forgot to include library loading in the code I shared previously, and for convenience I do so below...Thanks kindly for any further assistance.
>
> #FIRST: Include path to GDAL install that contains 'gdalwarp.exe' and 'gdal_translate.exe' to windows search path, in my case 'C:\Program Files\GDAL'
> #__________________________________
> library(raster);library(rgdal);library(plotKML)
> #Not sure if necessary, but I tried the following to ensure that paths are set up correctly....
> #plotKML.env(gdalwarp = 'C:/Program Files/GDAL', gdal_translate = 'C:/Program Files/GDAL')
> # or...
> #plotKML.env(gdalwarp = 'C:/Program > Files/GDAL/gdalwarp.exe', gdal_translate = 'C:/Program Files/GDAL/gdal_translate.exe')
>
> kml.folder <- 'c:/dave/temp';kml.file <- 'test.kml'
> rast <- raster(extent(-135.2,-135.1,58.1,58.2),nrows=10,ncol=10,crs=CRS('+init=epsg:4326'))
> rast[]<-rnorm(ncell(rast))
> kml(rast,kml.fold,kml.file,colour = 'black')
> #__________________________________
>
> Dave.
> -----Original Message-----
> From: Paul Woods [mailto:p.woods at qub.ac.uk]
> Sent: Monday, October 12, 2015 2:31 PM
> To: Gregovich, Dave P (DFG)
> Cc: r-sig-geo at r-project.org
> Subject: Re: [R-sig-Geo] plotKML 'kml' function with raster input
>
> Try changing your forward slashes (/) to backward slashes (\) as per Windows standard?
>
> Paul
>
>> On 12 Oct 2015, at 23:26, Gregovich, Dave P (DFG) <dave.gregovich at alaska.gov> wrote:
>>
>> Hello,
>> I am not able to create a .kml raster via the 'kml' function of plotKML (see the error below).
>> I am  setting the path to gdal in my windows registry as  'C:/Program Files/GDAL' -- the folder that contains 'gdalwarp.exe' and 'gdal_translate.exe' upon gdal installation.
>> I have also set the parameters in 'plotKML.env' in the two following ways (I don't know which it is supposed to be).
>> plotKML.env(gdalwarp = 'C:/Program Files/GDAL', gdal_translate =
>> 'C:/Program Files/GDAL') and plotKML.env(gdalwarp = 'C:/Program
>> Files/GDAL/gdalwarp.exe', gdal_translate = 'C:/Program
>> Files/GDAL/gdal_translate.exe')
>>
>>
>> kml.folder <- 'c:/dave/temp';kml.file <- 'test.kml'
>> rast <-
>> raster(extent(-135.2,-135.1,58.1,58.2),nrows=10,ncol=10,crs=CRS('+init
>> =epsg:4326'))
>> rast[]<-rnorm(ncell(rast))
>> kml(rast,kml.fold,kml.file,colour = 'black')
>>
>> #Results in the following messages...with no kml or kmz file output.
>> KML file opened for writing...
>> Writing to KML...
>> Closing  test.kml
>> Warning message:
>> In paths(show.paths = TRUE) :
>>  Could not locate GDAL! Install program and add it to the Windows registry. See http://www.gdal.org/ for more info.
>>
>>> sessionInfo()
>> R version 3.1.3 (2015-03-09)
>> Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64
>> (build 7601) Service Pack 1
>>
>> other attached packages:
>> [1] plotKML_0.5-3 rgdal_1.0-7   raster_2.4-20 sp_1.2-0
>>
>> ++++++++++++++++++++++++++++++++
>> Thanks kindly for your continued support.
>>
>> __________________________________
>> Dave Gregovich
>> Research Analyst
>> Alaska Department of Fish and Game
>> Wildlife Conservation Division
>> Douglas, AK 99821
>> (907) 465-4291
>> dave.gregovich at alaska.gov
>> __________________________________
>>
>>
>>       [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: use_qgis_utils.patch
Type: application/octet-stream
Size: 1063 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20151013/a1b4ace7/attachment.obj>


More information about the R-sig-Geo mailing list