sf2KML: Generate KML Files from simple SF Geometry type: POINT...

View source: R/sf2KML.R

sf2KMLR Documentation

Generate KML Files from simple SF Geometry type: POINT objects with Custom Icon colours

Description

This function creates KML files from 'sf' objects. Users can specify colours for the placemarks, which are then mapped to predefined URLs for icons in those colours. If no colour is specified, a default icon is used.

Usage

sf2KML(sf_object, colour = NULL, outputPath = NULL)

Arguments

sf_object

An 'sf' object containing the spatial data to be plotted. Must have an 'ID' column for placemark labels and geometry for coordinates. Must be of Geometry type: POINT.

colour

Optional; a character string specifying the colour of the placemark pins. Valid options are "green", "blue", "red", "purple", "lightblue", "pink", and "white". Defaults to NULL, which uses the default yellow colour.

outputPath

Optional; the file path where the KML file will be saved. If not specified, the file is saved in the current working directory with a name based on the ‘sf' object’s name.

Value

Writes a KML file to the specified or default path.

Examples

# Start with a simple data.frame with three columns: "ID", "X", and "Y"
Flinders_University <- data.frame(
  ID = c("MELFU", "Tavern", "Animal House", "Aquaculture compound", "Lake", "$1,360 car park"),
  X = c(138.570071, 138.571627, 138.569855, 138.569586, 138.572218, 138.569437), 
  Y = c(-35.026967, -35.026029, -35.028127, -35.027034, -35.026907, -35.029019)
)

# Convert the data frame to an sf object
library(sf)
Flinders_sf <- st_as_sf(Flinders_University, coords = c("X", "Y"), crs = 4326)

# Generate the KML file
sf2KML(Flinders_sf, colour = "red", outputPath = "Flinders_University.kml")


pygmyperch/melfuR documentation built on April 19, 2024, 7:24 a.m.