Learn R Programming

plotKML (version 0.2-4)

spMetadata-methods: Methods to generate spatial metadata

Description

The spMetadata function will try to generate missing metadata (bounding box, location info, session info, metadata creator info and similar) for any Spatial* object (from the sp package) or Raster* object (from the raster package). The resulting object of class SpatialMetadata-class can be used e.g. to generate a Layer description documents ( tag). The read.metadata function can be used to read the formatted metadata (.xml), prepared following to the http://www.fgdc.gov/metadata/csdgm/{Federal Geographic Data Committee (FGDC) Content Standard for Digital Geospatial Metadata}, and convert them to a more readble format (data frame).

Usage

spMetadata(obj, ...)

Arguments

obj
some "Spatial" or "Raster" class object with "data" slot
...
additional kml() arguments (see details below)

Details

spMetadata tries to locate a metadata file in the working directory (it looks for a metadata file with the same name as the object name). If no .xml file exists, it will load the template xml file available in the system folder (system.file("FGDC.xml", package="plotKML")). The FGDC.xml file contains typical metadata entries with description and examples. For practical purposes, one metadata object in plotKML can be associated with only one variable i.e. one column in the "data" slot (specified via Target_variable). To prepare a metadata xml file for the layer of interest, consider using the http://plotkml.r-forge.r-project.org/FGDC.xml{FGDC.xml} template file; to enter the missing fields use e.g. the http://geology.usgs.gov/tools/metadata/tools/doc/tkme.html{Tkme} software: Another editor for formal metadata, by Peter N. Schweitzer (U.S. Geological Survey). Before commiting the metadata file, try also running a http://geo-nsdi.er.usgs.gov/validation/{validating it}. spMetadata tries to automatically generate the most usefull information, so that a user can easily find out about the input data and procedures followed to generate the visualization (KML). Typical metadata entries include e.g.:
  • metadata[["idinfo"]][["native"]]--- Session info e.g.: Produced using R version 2.12.2 (2011-02-25) running on Windows 7 x64.
  • metadata[["spdoinfo"]][["indspref"]]--- Indirect spatial reference estimated using thehttp://code.google.com/apis/maps/documentation/webservices/{Google Maps API Web Services}.
  • metadata[["idinfo"]][["spdom"]][["bounding"]]--- Bounding box in the WGS84 geographical coordinates estimated by reprojecting the original bounding box.
By default, plotKML uses the Creative Commons license, but this can be adjusted by setting the Enduser_license_URL argument above.

References

  • The Federal Geographic Data Committee, (2006) FGDC Don't Duck Metadata --- A short reference guide for writing quality metadata. Vers. 1,http://www.fgdc.gov/metadata/documents/MetadataQuickGuide.pdf
  • Content Standard for Digital Geospatial Metadata (http://www.fgdc.gov/metadata/csdgm/)
  • Template metadata file (http://plotkml.r-forge.r-project.org/FGDC.xml)
  • Tkme metadata editor (http://geology.usgs.gov/tools/metadata/tools/doc/tkme.html)
  • Creative Commons licenses (http://creativecommons.org/licenses/)

See Also

kml_metadata, SpatialMetadata-class, spMetadata.Spatial, sp::Spatial, kml_open

Examples

Run this code
# 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, Target_variable="SNDMHT_A")
# with localy prepared metadata file:
eberg.md <- spMetadata(eberg, xml.file=system.file("eberg.xml", package="plotKML"), 
Target_variable="SNDMHT_A")
# print the results of validation (it needs to be able to connect to a URL with schema):
eberg.md <- spMetadata(eberg, Target_variable="SNDMHT_A", validate.schema = TRUE)
# write the metadata to a file:
saveXML(metadata(eberg.md), "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