getKMLcoordinates: Get a list of coordinates out of a KML file

Description Usage Arguments Value Author(s) See Also Examples

View source: R/getKMLcoordinates.R

Description

This function parses a KML file to get the content of <coordinates> tags and returns a list of matrices representing the longitude-latitute or if ignoreAltitude is FALSE the longitude-latitute-altitude coordinates of a KML geometry.

Usage

1
getKMLcoordinates(kmlfile, ignoreAltitude=FALSE)

Arguments

kmlfile

connection object or a character string of the KML file

ignoreAltitude

if set to TRUE the altitude values of a KML points will be ignored

Value

coords is a list of matrices representing the longitude-latitute or if ignoreAltitude is FALSE the longitude-latitute-altitude coordinates

Author(s)

Hans-J. Bibiko

See Also

kmlPolygon, kmlLine

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
data(wrld_simpl)
## creates a KML file containing the polygons of South Africa (plus hole)
sw <- slot(wrld_simpl[wrld_simpl$NAME=="South Africa",], "polygons")[[1]]
tf <- tempfile()
kmlPolygon(sw, kmlfile=tf, name="South Africa", col="#df0000aa", lwd=5, 
    border=4, kmlname="R Test", 
    kmldescription="This is <b>only</b> a <a href='http://www.r-project.org'>R</a> test.")
zz <- getKMLcoordinates(tf, ignoreAltitude=TRUE)
str(zz)
zz <- getKMLcoordinates(system.file("shapes/Testing.kml", package="maptools"))
str(zz)

Example output

Loading required package: sp
Checking rgeos availability: TRUE
List of 4
 $ : num [1:47, 1:2] 29.9 31.3 32 32 31.3 ...
 $ : num [1:8, 1:2] 28.6 27 27.6 28.1 28.4 ...
 $ : num [1:4, 1:2] 37.9 37.6 37.8 37.9 -47 ...
 $ : num [1:4, 1:2] 38 37.9 37.9 38 -46.7 ...
List of 1
 $ : num [1:3, 1:3] -71 -71.5 -71.1 42.3 42.7 ...

maptools documentation built on Sept. 7, 2021, 5:09 p.m.