[R-sig-Geo] plotKML kml_layer.Raster problem

Andreas Gros andigros72 at gmail.com
Fri Nov 7 18:12:07 CET 2014


Hi Frede,

This is the test case (using just values of 1): (traceback() below)

pheight = 100
pwidth = 200

> raster_layer <- raster(ncols=pwidth, nrows=pheight,
+                        xmn=xmin(r.ex), xmx=xmax(r.ex),
+                        ymn=ymin(r.ex), ymx=ymax(r.ex),
+                        crs=CRS(projection(bigraster)))
> values(raster_layer) <- rep(1, pwidth*pheight)


> kml_open(file.name="test.kml",
+   folder.name='top_folder',
+   kml_visibility=TRUE)
KML file opened for writing...
> kml_layer.Raster(raster_layer, folder.name='raster_sub_folder',
+   plot.legend=TRUE,
+   metadata=NULL,
+   colour=e.cRampPalette(255),
+   raster_name='raster_layer',
+   layer.name=names(raster_layer)[1],
+   png.width=1000,
+   png.height=833
+ )

Error in setValues(x, value) :
  values must be numeric, integer, logical or factor

> kml_close(file.name="test.kml")

Closing  test.kml

Traceback:
traceback()
6: stop("values must be numeric, integer, logical or factor")
5: setValues(x, value)
4: setValues(x, value)
3: `values<-`(`*tmp*`, value = c("#000000", "#010101", "#020202",
   "#030303", "#040404", "#060606", "#070707", "#080808", "#090909",
   "#0A0A0A", "#0C0C0C", "#0D0D0D", "#0E0E0E", "#0F0F0F", "#0F0F0F",
   "#101010", "#111111", "#121212", "#131313", "#141414", "#141414",
   "#151515", "#161616", "#161616", "#171717", "#181818", "#181818",
   "#191919", "#1A1A1A", "#1A1A1A", "#1B1B1B", "#1C1C1C", "#1C1C1C",
   "#1D1D1D", "#1E1E1E", "#1E1E1E", "#1F1F1F", "#202020", "#202020",
   "#212121", "#222222", "#222222", "#232323", "#242424", "#242424",
   "#252525", "#262626", "#272727", "#272727", "#282828", "#292929",
   "#292929", "#2A2A2A", "#2B2B2B", "#2B2B2B", "#2C2C2C", "#2D2D2D",
   "#2E2E2E", "#2E2E2E", "#2F2F2F", "#303030", "#303030", "#313131",
   "#323232", "#333333", "#333333", "#343434", "#353535", "#363636",
   "#363636", "#373737", "#383838", "#383838", "#393939", "#3A3A3A",
   "#3B3B3B", "#3B3B3B", "#3C3C3C", "#3D3D3D", "#3E3E3E", "#3E3E3E",

...

   ))

2: `values<-`(`*tmp*`, value = c("#000000", "#010101", "#020202",
   "#030303", "#040404", "#060606", "#070707", "#080808", "#090909",
   "#0A0A0A", "#0C0C0C", "#0D0D0D", "#0E0E0E", "#0F0F0F", "#0F0F0F",
   "#101010", "#111111", "#121212", "#131313", "#141414", "#141414",
   "#151515", "#161616", "#161616", "#171717", "#181818", "#181818",
   "#565656", "#575757", "#585858", "#595959", "#5A5A5A", "#5A5A5A",
...

 ))

1: kml_layer.Raster(raster_layer, folder.name = "raster_sub_folder",
       plot.legend = TRUE, metadata = NULL, colour = e.cRampPalette(255),
       raster_name = "raster_layer", layer.name = names(raster_layer)[1],
       png.width = 1000, png.height = 833)


And when I'm trying to use colour_scheme I'm gettiing an error that lets me
assume that kml_layer.Raster is not compatible with 'raster':

kml_open(file.name="test.kml",
+   folder.name='top_folder',
+   kml_visibility=TRUE)
KML file opened for writing...
> kml_layer.Raster(raster_layer, folder.name='raster_sub_folder',
+   plot.legend=TRUE,
+   metadata=NULL,
+   colour_scheme=e.cRampPalette(255),
+   raster_name='raster_layer',
+   layer.name=names(raster_layer)[1],
+   png.width=1000,
+   png.height=833
+ )

Error in is.factor(obj at data[, 1]) :
  error in evaluating the argument 'x' in selecting a method for function
'is.factor': Error in obj at data[, 1] : object of type 'S4' is not subsettable

> kml_close(file.name="test.kml")
Closing  test.kml

> traceback()
2: is.factor(obj at data[, 1])
1: kml_layer.Raster(raster_layer, folder.name = "raster_sub_folder",
       plot.legend = TRUE, metadata = NULL, colour_scheme =
e.cRampPalette(255),
       raster_name = "raster_layer", layer.name = names(raster_layer)[1],
       png.width = 1000, png.height = 833)

On Thu, Nov 6, 2014 at 10:52 PM, Frede Aakmann Tøgersen <frtog at vestas.com>
wrote:

> Hi Andreas
>
> Can you provide a small example showing the details of what you're trying
> to do. I don't think that anyone can help you with the little information
> you have given.
>
> If you do not have any example please show us the output from traceback()
> immediately after the error.
>
> I don't think this has anything to do with NA's in your data values as I
> don't get any errors doing this (from man of kml_layer.Raster):
>
>
> data(eberg_grid)
> library(sp)
> coordinates(eberg_grid) <- ~x+y
> gridded(eberg_grid) <- TRUE
> proj4string(eberg_grid) <- CRS("+init=epsg:31467")
> data(SAGA_pal)
> library(raster)
> r <- raster(eberg_grid["TWISRT6"])
>
> ## Put some NA's into data
> r at data@values[1:10] <- NA
>
> kml(r, colour_scale = SAGA_pal[[1]], colour = TWISRT6)
>
>
>
>
> 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-bounces at r-project.org [mailto:r-sig-geo-bounces at r-
> > project.org] On Behalf Of Andreas Gros
> > Sent: 6. november 2014 23:47
> > To: r-sig-geo at r-project.org
> > Subject: [R-sig-Geo] plotKML kml_layer.Raster problem
> >
> > In version 0.4-6 of plotKML, when I'm adding a kml_layer.Raster (single
> > layer, no stack/brick) to a kml file, I get the following error message:
> >
> > Error in setValues(x, value) :
> > values must be numeric, integer, logical or factor
> >
> >
> > The values in the raster range between -57 and 2000 and it also occurs
> if I
> > replace NA values first with some arbitrary numerical value.
> > Has anyone come across this problem and knows how to fix/circumnavigate
> > it?
> >
> > Thanks!
> >
> >       [[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
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list