Chooses the reader from tools::file_ext(path) (case-insensitive):

  • .zip — read_sf_zip()

  • .kmz — read_kmz()

  • .kml — internal KML reader (same tibble layout; fpath is the .kml file)

  • .gdb — read_gdb()

  • anything else GDAL/sf can open on path — one row per layer from sf::st_layers() (e.g. .shp, .gpkg, .geojson)

read_geo(path, layer = NULL, quiet = TRUE, by_bbox = NULL, ...)

Arguments

path

Path to a spatial file or a .gdb directory.

layer

Passed to multi-layer GDAL readers. Ignored for .zip and .kmz.

quiet

Passed to sf::read_sf().

by_bbox

If NULL (default), every feature is read. Otherwise an sf, sfc, bbox or named numeric vector (xmin, ymin, xmax, ymax) whose bounding box limits the features read: only features that intersect it are returned, filtered by GDAL at read time through the wkt_filter argument of sf::st_read(). The bounding box is reprojected to each layer's CRS; if it has no CRS, its coordinates are assumed to be in the layer's CRS. If the layer has no CRS it can be reprojected to (no .prj, or an undefined LOCAL_CS), the coordinates are used as-is with a warning. Features with empty geometry are dropped. Layers without a geometry column (e.g. a shapefile made of a .dbf only, or an attribute table in a GeoPackage) cannot be filtered: they are read in full with a warning. When set, nrows_aka_features reports the number of features read, not the layer total. Cannot be combined with wkt_filter in ....

...

Additional arguments passed to sf::read_sf().

Value

A tibble as described in read_gdb().

See also

Examples

# \donttest{
d <- system.file("extdata", package = "misc")
f <- function(...) file.path(d, ...)
if (file.exists(f("misc_example.zip"))) read_geo(f("misc_example.zip"))
if (file.exists(f("misc_example.kmz"))) read_geo(f("misc_example.kmz"))
#> # A tibble: 1 × 8
#>   fpath   file_type layer_name geometry_type nrows_aka_features ncols_aka_fields
#>   <chr>   <chr>     <chr>      <chr>                      <int>            <int>
#> 1 /home/… kmz       doc        ""                             1               12
#> # ℹ 2 more variables: crs_name <chr>, data <list>
if (file.exists(f("misc_example.kml"))) read_geo(f("misc_example.kml"))
#> # A tibble: 1 × 8
#>   fpath   file_type layer_name geometry_type nrows_aka_features ncols_aka_fields
#>   <chr>   <chr>     <chr>      <chr>                      <int>            <int>
#> 1 /home/… kml       misc_exam… ""                             1               12
#> # ℹ 2 more variables: crs_name <chr>, data <list>
if (file.exists(f("misc_example.gpkg"))) read_geo(f("misc_example.gpkg"))
#> # A tibble: 1 × 8
#>   fpath   file_type layer_name geometry_type nrows_aka_features ncols_aka_fields
#>   <chr>   <chr>     <chr>      <chr>                      <int>            <int>
#> 1 /home/… gpkg      misc_exam… Point                          1                1
#> # ℹ 2 more variables: crs_name <chr>, data <list>
if (file.exists(f("misc_example.geojson"))) read_geo(f("misc_example.geojson"))
#> # A tibble: 1 × 8
#>   fpath   file_type layer_name geometry_type nrows_aka_features ncols_aka_fields
#>   <chr>   <chr>     <chr>      <chr>                      <int>            <int>
#> 1 /home/… geojson   misc_exam… Point                          1                1
#> # ℹ 2 more variables: crs_name <chr>, data <list>
if (file.exists(f("misc_example.shp"))) read_geo(f("misc_example.shp"))
#> # A tibble: 1 × 8
#>   fpath   file_type layer_name geometry_type nrows_aka_features ncols_aka_fields
#>   <chr>   <chr>     <chr>      <chr>                      <int>            <int>
#> 1 /home/… shp       misc_exam… Point                          1                1
#> # ℹ 2 more variables: crs_name <chr>, data <list>
if (dir.exists(f("misc_example.gdb"))) read_geo(f("misc_example.gdb"), layer = "OGRGeoJSON")
#> # A tibble: 1 × 8
#>   fpath   file_type layer_name geometry_type nrows_aka_features ncols_aka_fields
#>   <chr>   <chr>     <chr>      <chr>                      <int>            <int>
#> 1 /home/… gdb       OGRGeoJSON Multi Polygon                  1                1
#> # ℹ 2 more variables: crs_name <chr>, data <list>

# read only the features that intersect a bounding box
nc <- system.file("shape/nc.shp", package = "sf")
bb <- sf::st_bbox(c(xmin = -80, ymin = 35, xmax = -79, ymax = 36), crs = 4326)
read_geo(nc, by_bbox = bb)
#> # A tibble: 1 × 8
#>   fpath   file_type layer_name geometry_type nrows_aka_features ncols_aka_fields
#>   <chr>   <chr>     <chr>      <chr>                      <int>            <int>
#> 1 /home/… shp       nc         Polygon                       15               14
#> # ℹ 2 more variables: crs_name <chr>, data <list>
# }