[GIS] Importing KML files to R

kmlkmzr

I am trying to read a KML file in R using this previous guide. The file is available here as a KMZ; following suggestions from other help files, I converted it to a KML by opening it in Google Earth, right-clicking the data layer, clicking 'save as', and saving as a .kml.

Here is what I've done so far:

import <- ogrListLayers("Burrows/Burrows_et_al_Nature_traj_ocean_NH1.kml")
# [1] "SST"       "SST_start" "SST_1"    
attr(import, "driver")
# [1] "LIBKML"
attr(import, "nlayers")
# [1] 3
foo = readOGR("Burrows/Burrows_et_al_Nature_traj_ocean_NH1.kml", "SST") 
# no features foundError in readOGR("Burrows/Burrows_et_al_Nature_traj_ocean_NH1.kml", "SST") : 
# no features found

Because the output of ogrListLayers() makes it clear that the path name is correct and R can access the .kml file well enough to list the layer names, I'm confused why readOGR() isn't working. What am I missing?

Best Answer

The answer is simple, the layer SST is just the folder (s. screenshot). If you load the subfolder it works perfectly.

example google earch

file <- "Burrows_et_al_Nature_traj_ocean_NH1.kmz"

SST_start = readOGR(file,"SST_start") 
# OGR data source with driver: LIBKML 
# Source: "Burrows_et_al_Nature_traj_ocean_NH1.kmz", layer: "SST_start"
# with 42205 features
# It has 12 fields
SST_1 = readOGR(file,"SST_1") 
# OGR data source with driver: LIBKML 
# Source: "Burrows_et_al_Nature_traj_ocean_NH1.kmz", layer: "SST_1"
# with 7719 features
#It has 12 fields
Related Question