Skip to content

KML file read via vect() on Windows loads only 2 attributes (vs ~26 on Linux) — likely due to missing LIBKML driver #1954

@YONGHUNI

Description

@YONGHUNI

Description:

Summary

When reading the same KML file using terra::vect() on Windows, only 2 attributes are loaded. On the same file in Ubuntu, the full ~26 attributes load correctly. The difference appears tied to the presence of the LIBKML driver in the GDAL build on Linux, which is absent on the Windows build.

Environment

Ubuntu

  • terra::gdal() → “3.8.4”
  • terra::gdal(drivers=TRUE) shows LIBKML among vector drivers

Windows

  • terra::gdal() → “3.11.0”
  • terra::gdal(drivers=TRUE) shows only KML and KMLSUPEROVERLAY, no LIBKML

Reproducible example

library(terra)
fn <- "https://gitlab.mpcdf.mpg.de/yhsuh/RefugeeCamp/-/raw/main/Accessibility/data/camp_outline/20230412_a1_camp_outlines.kml"
v <- vect(fn)
print(v)
terra::gdal(drivers=TRUE) |> subset(grepl("KML|kml", name))
  • On Ubuntu the output shows dimensions : 33, 26 (geometries, attributes)
> terra::vect("https://gitlab.mpcdf.mpg.de/yhsuh/RefugeeCamp/-/raw/main/Accessibility/data/camp_outline/20230412_a1_camp_outlines.kml")
 class       : SpatVector 
 geometry    : polygons 
 dimensions  : 33, 26  (geometries, attributes)
 extent      : 92.12973, 92.26863, 20.91856, 21.22292  (xmin, xmax, ymin, ymax)
 source      : 20230412_a1_camp_outlines.kml (20230412_A1_Camp_Outlines)
 coord. ref. : lon/lat WGS 84 (EPSG:4326) 
 names       :  Name description timestamp    begin      end altitudeMode tessellate extrude visibility drawOrder (and 16 more)
 type        : <chr>       <chr>  <POSIXt> <POSIXt> <POSIXt>        <chr>      <int>   <int>      <int>     <int>              
 values      :    NA          NA      <NA>     <NA>     <NA>           NA         -1       0         -1        NA              
                  NA          NA      <NA>     <NA>     <NA>           NA         -1       0         -1        NA              
                  NA          NA      <NA>     <NA>     <NA>           NA         -1       0         -1        NA              
> terra::gdal()
[1] "3.8.4"
> subset(terra::gdal(drivers=TRUE), grepl("KML|kml", name))
               name raster vector        can  vsi                        long.name
103             KML  FALSE   TRUE read/write TRUE    Keyhole Markup Language (KML)
104 KMLSUPEROVERLAY   TRUE  FALSE read/write TRUE                Kml Super Overlay
110          LIBKML  FALSE   TRUE read/write TRUE Keyhole Markup Language (LIBKML)
  • On Windows it shows dimensions : 33, 2 (geometries, attributes)
> terra::vect("https://gitlab.mpcdf.mpg.de/yhsuh/RefugeeCamp/-/raw/main/Accessibility/data/camp_outline/20230412_a1_camp_outlines.kml")
 class       : SpatVector 
 geometry    : polygons 
 dimensions  : 33, 2  (geometries, attributes)
 extent      : 92.12973, 92.26863, 20.91856, 21.22292  (xmin, xmax, ymin, ymax)
 source      : 20230412_a1_camp_outlines.kml (20230412_A1_Camp_Outlines)
 coord. ref. : lon/lat WGS 84 (EPSG:4326) 
 names       :  Name Description
 type        : <chr>       <chr>
 values      :                  
                                
                                
> terra::gdal()
[1] "3.11.0"
> subset(terra::gdal(drivers=TRUE), grepl("KML|kml", name))
              name raster vector        can  vsi                     long.name
94             KML  FALSE   TRUE read/write TRUE Keyhole Markup Language (KML)
95 KMLSUPEROVERLAY   TRUE  FALSE read/write TRUE             Kml Super Overlay

Hypothesis

The GDAL build on Windows uses only the KML OGR driver, which may not fully support nested folder structures, extended attributes or style/detail tags in KML. The build on Ubuntu includes the LIBKML driver, which supports a fuller KML spec and thus loads more attributes. According to GDAL documentation: “If you build and include this LIBKML driver, it will become the default reader of KML for OGR.”

Request / Questions

  • Could the Windows binaries of terra (or its GDAL dependency) include a version built with LIBKML, or provide guidance for users to install one?

Additional details

  • KML file: polygon layer (33 geometries) with ~26 attribute fields.
  • On Windows: names(v) yields only "Name", "Description" (2 fields).
  • On Ubuntu: names(v) yields all ~26 fields.
  • Similar issues have been observed via the sf package: driver difference (KML vs LIBKML) leads to attribute loss on some platforms.
  • Providing an optional diagnostic: terra::gdal(drivers=TRUE) and verifying driver list.

Session Info

  • Ubuntu
> sessionInfo()
R version 4.5.0 (2025-04-11)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] terra_1.8-54

loaded via a namespace (and not attached):
[1] compiler_4.5.0    tools_4.5.0       rstudioapi_0.17.1 yaml_2.3.10       Rcpp_1.0.14       codetools_0.2-20  renv_1.1.4  
  • Windows
> sessionInfo()
R version 4.5.0 (2025-04-11 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 26100)

Matrix products: default
  LAPACK version 3.12.1

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                           LC_TIME=English_United States.utf8    

time zone: Europe/Berlin
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] terra_1.8-54

loaded via a namespace (and not attached):
[1] compiler_4.5.0    tools_4.5.0       rstudioapi_0.17.1 Rcpp_1.0.14       codetools_0.2-20 

Thank you for your attention.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions