[R-sig-Geo] coerce SpatialPolygonsDataFrame to SpatialLinesDataFrame for plotKML

Ross Dwyer ross.dwyer at uq.edu.au
Thu Sep 20 04:03:29 CEST 2012


Hi Tony,

If all you want to do is export a .kml with fully transparent vertices, try the writeOGR function in the rgdal package...

ver <- getverticeshr(ud, percent=ct)  ## extract the home-range contours
writeOGR(ver, dsn="my file name.kml", layer= "myvertices", driver="KML", dataset_options=c("NameField=ct")) #where ct is a column in your spdf.

However I'm unsure how to specify the colour here - the default border colour is red and writeOGR doesn't seem to have the option to alter the output colour.

Alternatively, try the kml() function in the plotKML package. However this will only generate a 'filled' rather than a 'border-only' polygon. 

Sorry I can't be more help!

Cheers,
Ross

Dr Ross Dwyer | University of Queensland | Email: ross.dwyer at uq.edu.au

-----Original Message-----
From: r-sig-geo-bounces at r-project.org [mailto:r-sig-geo-bounces at r-project.org] On Behalf Of Anthony Fischbach
Sent: Thursday, 20 September 2012 8:57 AM
To: r-sig-geo at r-project.org
Subject: [R-sig-Geo] coerce SpatialPolygonsDataFrame to SpatialLinesDataFrame for plotKML

For purposes of sharing data in a form that may be visualized on shipboard chart plotters, I wish to export contours as a KML(or KMZ) of lines with a color corresponding to a contour level.
I have generated the contours as SpatialPolygonsDataFrame from kernel density estimators in adehabitatHR.

Is there a handy means to coerce the outlines SpatialPolygonsDataFrame into a SpatialLinesDataFrame object to facilitate this KML/KMZ export?

#########################################################
### Here is a toy example of what I wish to have

require(adehabitatHR) 
data(puechabonsp)                   ## load animal movement data
loc <- puechabonsp$relocs  
(ud <- kernelUD(loc[,1]))           ## estimate utilization distribution
ct <- 95                                 ## Specify the contour level
ver <- getverticeshr(ud, percent=ct)  ## extract the home-range contours
class(ver)                               ## this produces a
SpatialPolygonsDataFrame object
#### Here I want to export the home range as a line into a KML/KMZ file #### I want a function that will do this
ver.sLinesdf<-coerceToSpatialLinesDataFrame(ver)
class(ver.sLinesdf)                    ## returns SpatialLinesDataFrame
plotKML(ver.sLinesdf, colour=ct)  ## Generate KMZ and color using the contour level

#########################################################



-----
Tony Fischbach, Wildlife Biologist
Walrus Research Program
Alaska Science Center
U.S. Geological Survey
4210 University Drive
Anchorage, AK 99508-4650

AFischbach at usgs.gov
http://alaska.usgs.gov/science/biology/walrus
--
View this message in context: http://r-sig-geo.2731867.n2.nabble.com/coerce-SpatialPolygonsDataFrame-to-SpatialLinesDataFrame-for-plotKML-tp7580986.html
Sent from the R-sig-geo mailing list archive at Nabble.com.

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list