###Drawing lines
###Drawing closed polygons
#Prepare fake data
pol1 = rbind(c(1,1,1e5), c(1,2,2e5), c(2,2,3e5), c(3,3,4e5))
pol2 = rbind(c(1,1,1e5), c(2,2,2e5), c(3,3,1e5), c(4,4,2e5))
coords = rbind(pol1, pol2)
nesting = rep(c(1,2), each = 4)
#data to be displayed
fakedata = cbind(nesting, coords)
colnames(fakedata) = c("nesting", "Lon", "Lat", "Alt")
fakedata
#Producing KML - all points are at the same altitude
PolyLines2GE(coords = fakedata[, 2:3],
nesting = fakedata[, 1],
colors = "auto",
goo = "Lines2GE_V1a.kml",
maxAlt = 1e4,
fill = FALSE,
closepoly = FALSE,
lwd = 2,
extrude = 0)
#Producing KML - all points, from a same line share the same altitude
PolyLines2GE(coords = fakedata[, 2:3],
nesting = fakedata[, 1],
colors = "auto",
goo = "Lines2GE_V1b.kml",
maxAlt = c(1e4, 1e5),
fill = FALSE,
closepoly = FALSE,
lwd = 2,
extrude = 0)
#Producing KML - Each point has its own altitude
PolyLines2GE(coords = fakedata[, 2:3],
nesting = fakedata[, 1],
colors = "auto",
goo = "Lines2GE_V1c.kml",
maxAlt = fakedata[, 4],
fill = FALSE,
closepoly = FALSE,
lwd = 2,
extrude = 0)
###Drawing closed polygons
#Prepare fake data
pol1 = rbind(c(1,1), c(1,2), c(2,2), c(2,1))
pol2 = (2 * pol1) - 0.5
coords = rbind(pol1, pol2)
coords = coords[ nrow(coords) : 1,]
nesting = rep(c(1,2), each = 4)
#data to be displayed
fakedata = cbind(nesting, coords)
fakedata
#Producing KML - the easy way
PolyLines2GE(coords = fakedata[, 2:3],
nesting = fakedata[, 1],
colors = "auto",
goo = "Poly2GE_V1.kml",
maxAlt = 0,
fill = FALSE,
closepoly = TRUE,
lwd = 2,
extrude = 0)
#Producing KML - the easy way, polygons at distinct heights
PolyLines2GE(coords = fakedata[, 2:3],
nesting = fakedata[, 1],
colors = "auto",
goo = "Poly2GE_V1b.kml",
maxAlt = c(1e4, 1e5),
fill = FALSE,
closepoly = TRUE,
lwd = 2,
extrude = 0)
#Producing KML - with filled polygon
PolyLines2GE(coords = fakedata[, 2:3],
nesting = fakedata[, 1],
colors = "auto",
goo = "Poly2GE_V2.kml",
maxAlt = 0,
fill = TRUE,
closepoly = TRUE,
lwd = 2,
extrude = 0)
#Producing KML - with polygon extruded from ground
PolyLines2GE(coords = fakedata[, 2:3],
nesting = fakedata[, 1],
colors = "auto",
goo = "Poly2GE_V3.kml",
maxAlt = c(1e4, 1e5),
fill = TRUE,
closepoly = TRUE,
lwd = 2,
extrude = 1)
###Drawing a contour plot using the PolyLines2GE function:
#Prepare data
data(volcano)
lat = seq(1, 6, length.out = nrow(volcano))
lon = seq(1, 6, length.out = ncol(volcano))
#Get contour lines
cont = contourLines(lat, lon, volcano, nlevels = 20)
#Convert them into Lines2GE input format
cont.data = NULL
for(i in 1:length(cont)){
subs = cont[[i]]
tmp = cbind(i, subs$x, subs$y)
cont.data = rbind(cont.data, tmp)
}
#Produce KML
PolyLines2GE(coords = cont.data[, 2:3],
nesting = cont.data[, 1],
colors = "auto",
goo = "Contour2GE_V1.kml",
maxAlt = seq(1e4, 1e5, length.out = length(cont)),
fill = FALSE,
closepoly = FALSE,
lwd = 2,
extrude = 0)
Run the code above in your browser using DataLab