Skip to content

plotKML 'kml' function with raster input

6 messages · Paul Woods, Gregovich, Dave P (DFG), Vijay Lulla +1 more

#
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.
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
__________________________________
#
Try changing your forward slashes (/) to backward slashes (\) as per Windows standard?

Paul
#
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
#
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:
-------------- 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>
#
Hi Dave

Can you please check that you have a working installation of GDAL.

I installed GDAL on my new windows laptop. First I tried unzipping this release,  release-1800-x64-gdal-1-11-1-mapserver-6-4-1.zip

from http://www.gisinternals.com/query.html?content=filelist&file=release-1800-x64-gdal-1-11-1-mapserver-6-4-1.zip

I opened a cmd window and tried calling gdaltransform.exe (of course specifying the full path) but got an error saying that some dll could not be found. I guess that the dlls didn't get registered by Windows OS this way of installation.

Well installing the 
 
gdal-111-1800-x64-core.msi

from same homepage as above it seemed that the dlls are now registered correctly, because in a cmd window I can now call the gdal functions:

Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

C:\Users\frtog>c:\"Program Files"\GDAL\gdaltransform.exe --help
Usage: gdaltransform [--help-general]
    [-i] [-s_srs srs_def] [-t_srs srs_def] [-to "NAME=VALUE"]
    [-order n] [-tps] [-rpc] [-geoloc]
    [-gcp pixel line easting northing [elevation]]*
    [srcfile [dstfile]]

Now in R this works:

library(raster)
library(rgdal)
library(plotKML)

gdalt <- "C:/Program Files/GDAL/gdaltransform.exe"
gdalw <- "C:/Program Files/GDAL/gdalwarp.exe"

plotKML.env(gdalwarp = gdalw, gdal_translate = gdalt)

kml.folder <- "."
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.folder, kml.file, colour = 'black')


Yours sincerely / Med venlig hilsen

Frede Aakmann T?gersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
frtog at vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender. 



-----Original Message-----
From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Vijay Lulla
Sent: 14. oktober 2015 00:53
To: Gregovich, Dave P (DFG)
Cc: r-sig-geo at r-project.org
Subject: Re: [R-sig-Geo] plotKML 'kml' function with raster input

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:
#
Frede,
Thanks kindly for taking the time.
I installed gdal via the installer 'gdal-111-1800-x64-core.msi' at http://www.gisinternals.com.
The kml function is now working fine. 
Note one minor change to your code below: gdalt <- "C:/Program Files/GDAL/gdaltransform.exe" should be gdalt <- "C:/Program Files/GDAL/gdal_translate.exe"
Dave.

-----Original Message-----
From: Frede Aakmann T?gersen [mailto:frtog at vestas.com] 
Sent: Tuesday, October 13, 2015 9:59 PM
To: Vijay Lulla; Gregovich, Dave P (DFG)
Cc: r-sig-geo at r-project.org
Subject: RE: [R-sig-Geo] plotKML 'kml' function with raster input

Hi Dave

Can you please check that you have a working installation of GDAL.

I installed GDAL on my new windows laptop. First I tried unzipping this release,  release-1800-x64-gdal-1-11-1-mapserver-6-4-1.zip

from http://www.gisinternals.com/query.html?content=filelist&file=release-1800-x64-gdal-1-11-1-mapserver-6-4-1.zip

I opened a cmd window and tried calling gdaltransform.exe (of course specifying the full path) but got an error saying that some dll could not be found. I guess that the dlls didn't get registered by Windows OS this way of installation.

Well installing the 
 
gdal-111-1800-x64-core.msi

from same homepage as above it seemed that the dlls are now registered correctly, because in a cmd window I can now call the gdal functions:

Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

C:\Users\frtog>c:\"Program Files"\GDAL\gdaltransform.exe --help
Usage: gdaltransform [--help-general]
    [-i] [-s_srs srs_def] [-t_srs srs_def] [-to "NAME=VALUE"]
    [-order n] [-tps] [-rpc] [-geoloc]
    [-gcp pixel line easting northing [elevation]]*
    [srcfile [dstfile]]

Now in R this works:

library(raster)
library(rgdal)
library(plotKML)

gdalt <- "C:/Program Files/GDAL/gdaltransform.exe"
gdalw <- "C:/Program Files/GDAL/gdalwarp.exe"

plotKML.env(gdalwarp = gdalw, gdal_translate = gdalt)

kml.folder <- "."
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.folder, kml.file, colour = 'black')


Yours sincerely / Med venlig hilsen

Frede Aakmann T?gersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
frtog at vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice If you have received this e-mail in error please contact the sender. 



-----Original Message-----
From: R-sig-Geo [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Vijay Lulla
Sent: 14. oktober 2015 00:53
To: Gregovich, Dave P (DFG)
Cc: r-sig-geo at r-project.org
Subject: Re: [R-sig-Geo] plotKML 'kml' function with raster input

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: