Search code examples
rkmlraster

plotkml raster displays a red X instead of the image


Raster image can be downloaded here:

https://github.com/Alexvonrass/BS_Selection_tool/blob/master/data/msc_raster.RDS

I run this code:

r <- readRDS("msc_raster.RDS")
kml(r, colour = r@data@values, file='ms.kml') 

Then i get these warnings (not sure if they are related to the problem or not)

KML file opened for writing...
Writing to KML...
Closing  ms.kml
Warning messages:
1: 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.
2: In paths(show.paths = TRUE) :
  Could not locate SAGA GIS! Install program and add it to the Windows registry. See http://www.saga-gis.org/en/ for more info.

I get a kml file with the correct legend, correct position and size of the raster image, but instead of the actual image there's a red X:

http://imgur.com/a/Xzado

It does write the desired image into the .png, but doesn't put it into the .kml I'm thinking it has something to do with the filename of .png image that r writes, but i can't get it working at the moment.


Solution

  • plotKML seems to mess up the referencing of the png to display. It can't find it, hence the red X.

    A simple workaround is to just add the parameter raster_name to your function call:

    kml(r,raster_name = 'layer.png', colour = r@data@values, file='ms.kml')