# NOT RUN {
library(sp)
library(uuid)
library(rjson)
## read metadata from the system file:
x <- read.metadata(system.file("FGDC.xml", package="plotKML"))
str(x)
## generate missing metadata
data(eberg)
coordinates(eberg) <- ~X+Y
proj4string(eberg) <- CRS("+init=epsg:31467")
## no metadata file specified:
eberg.md <- spMetadata(eberg["SNDMHT_A"])
## this generates some metadata automatically e.g.:
xmlRoot(eberg.md@xml)[["eainfo"]][["detailed"]][["attr"]]
## combine with localy prepared metadata file:
eberg.md <- spMetadata(eberg["SNDMHT_A"],
xml.file=system.file("eberg.xml", package="plotKML"))
## Additional metadat entries can be added by using e.g.:
eberg.md <- spMetadata(eberg["SNDMHT_A"],
md.type="INSPIRE",
CI_Citation_title = 'Ebergotzen data set',
CI_Online_resource_URL = 'http://geomorphometry.org/content/ebergotzen')
## the same using the FGDC template:
eberg.md <- spMetadata(eberg["SNDMHT_A"],
Citation_title = 'Ebergotzen data set',
Citation_URL = 'http://geomorphometry.org/content/ebergotzen')
## Complete list of names:
mdnames <- read.csv(system.file("mdnames.csv", package="plotKML"))
mdnames$field.names
## these can be assigned to the "metadata" environment by using:
metadata.env(CI_Citation_title = 'Ebergotzen data set')
get("CI_Citation_title", metadata)
## write data and metadata to a file:
library(rgdal)
writeOGR(eberg["SNDMHT_A"], "eberg_SAND.shp", ".", "ESRI Shapefile")
saveXML(eberg.md@xml, "eberg_SAND.xml")
## export to SLD format:
metadata2SLD(eberg.md, "eberg.sld")
## plot the layer with the metadata:
kml(eberg, file.name = "eberg_md.kml", colour = SNDMHT_A, metadata = eberg.md, kmz = TRUE)
# }
Run the code above in your browser using DataLab