[R-sig-Geo] Formatting output of plotKML

Calum Galleitch calum at callingthetune.co.uk
Fri Nov 15 13:25:31 CET 2013


 Hello,

I am having a little trouble with plotKML and I am not sure whether to
ascribe it to my incompetence (most likely), incomplete documentation,
or other incorrect behaviour.

My aim is to produce a display in Google Earth visualising point data,
and I wish to control the size, label, and colour of these points.  I
have succesfully achieved the first two but am struggling a little to
achieve the latter.  I have attached my test data below along with the
script I am using and sessionInfo().  The test data is in the UK's
National Grid co-ordinate system so it gets converted before writing
out as a SpacialPointsDataFrame.

According to the ?plotKML documentation there is a colour argument;
however attempting to call it with a vector of required colours fails:

> plotKML(map_data_lat_long,
+         file.name='test.kml',
+         points_names = map_data_lat_long at data$Label,
+         colour = col2kml("red") # or map_data_lat_long at data$colour -
with or without col2kml
+         )
Error in `[.data.frame`(obj at data, , as.character(colour)) :
  undefined columns selected

Suspecting a localisation issue I tried color instead.  This did not
error, however it just generated the default colour palette.  Other
incantations of various sorts have not really helped, including
replacing named colours with the output of col2kml in the data.

I have tried to use kml_aes but it's not very clear to me how it is to be used.

Any advice will be most welcome, even if just possible avenues to
attack.  Also, I am not wedded by any means to plotKML and suggestions
for similar methods to achieve the same ends would also be helpful.

Many thanks,
Calum

test.csv:

xCord,yCord,size,Label,colour
532063,180615,14854874,Label A 1,red
537441,179551,851711370,Label A 2,red
560496,193284,652296152,Label A 3,red
324608,673413,936830099,Label A 4,red
532912,181045,734565801,Label B1,yellow
533045,181729,213722268,Label B2,yellow
530997,181334,104685106,Label B3,yellow
412716,94732,129014315,Label B4,yellow
532922,182308,385289711,Label B5,yellow
412782,93652,203823599,Label B6,yellow
533087,181376,666606649,Label B7,yellow
257763,665929,270940754,Label B8,yellow
410777,91722,442497572,Label B9,yellow
529425,181882,784422025,Label B10,yellow
532099,181799,679613728,Label B11,yellow
317524,671657,15213991,Label B12,yellow
532083,181106,51632818,Label B13,yellow
538538,181218,753123608,Label B14,yellow
409275,183852,916308988,Label B15,yellow
410525,91826,315714830,Label B16,yellow
531754,181472,533400391,Label B17,yellow
531283,180728,555929970,Label C1,green
532626,182039,873479599,Label C2,green
531808,180688,646380547,Label C3,green
531420,180361,672470450,Label C4,green
406677,287059,570024001,Label C5,green
360081,173983,877518563,Label C6,green
531881,180954,31953847,Label C7,green
533121,181183,983234849,Label C8,green
532923,180402,247198656,Label C9,green
532462,181973,442823961,Label C10,green
261791,669595,730094270,Label C11,green
459422,302817,884024369,Label D1,blue
429471,434310,235268642,Label D2,blue
379879,395710,674285057,Label D3,blue
384301,398337,920018841,Label D4,blue
624079,309248,317068333,Label D5,blue
625735,310478,944036809,Label D6,blue
622527,307366,269074659,Label D7,blue
629426,308707,796105708,Label D8,blue
628978,309282,469163049,Label D9,blue
309342,722860,550759988,Label D10,blue
433071,384763,205810120,Label D11,blue
433895,389174,859445905,Label D12,blue
443319,118260,662205408,Label D13,blue
459825,451261,465489204,Label D14,blue
459630,451405,807818766,Label D15,blue

Script:

# Load required libraries
library("plotKML")

# Read data
csvFile <- "test.csv"
map_data <- read.csv(csvFile, header=TRUE)

# Specify what are the x, y columns and create co-ordinate system
coordinates( map_data ) <- c("xCord","yCord")
proj4string( map_data ) <- CRS("+init=epsg:27700")

# Convert OS grid to lat/long
map_data_lat_long <- spTransform( map_data, CRS("+proj=longlat +datum=WGS84"))

# Carry out plotting
kml_aes(map_data_lat_long, colour=
col2kml(map_data_lat_long at data$colour)) #unsure about this!
plotKML(map_data_lat_long,
        file.name='test.kml',
        points_names = map_data_lat_long at data$Label
        )


> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] plotKML_0.3-8 sp_1.0-12

loaded via a namespace (and not attached):
 [1] aqp_1.5-3          cluster_1.14.4     colorRamps_2.3     colorspace_1.2-4
 [5] dichromat_2.0-0    dismo_0.8-17       grid_3.0.2         gstat_1.0-17
 [9] Hmisc_3.12-2       intervals_0.14.0   labeling_0.2       lattice_0.20-23
[13] munsell_0.4.2      pixmap_0.4-11      plotrix_3.5-2      plyr_1.8
[17] raster_2.1-49      RColorBrewer_1.0-5 reshape_0.8.4      rgdal_0.8-11
[21] rpart_4.1-3        RSAGA_0.93-6       scales_0.2.3       spacetime_1.0-9
[25] stringr_0.6.2      tools_3.0.2        XML_3.98-1.1       xts_0.9-7
[29] zoo_1.7-10



More information about the R-sig-Geo mailing list