% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sp_read.R
\name{sp_read}
\alias{sp_read}
\title{Function to read spatial data files in a consistent way.}
\usage{
sp_read(
  file,
  layer = NULL,
  geom = NULL,
  lower = TRUE,
  use_iconv = FALSE,
  verbose = TRUE
)
}
\arguments{
\item{file}{Spatial data file name. For shapefiles and Mapinfo TAB files, a
file extension is optional. For File Geodatabases, an extension is required 
(usually \code{.gdb}). For spatial data types which are composed of a single 
file, \code{file} can be a URL and the file will be downloaded into a 
temporary directory and then loaded.}

\item{layer}{Layer within \code{file} to read. Default is \code{NULL} and 
should not be needed for shapefiles, Mapinfo TAB files, and GeoJSON files. 
Default behaviour for GPX files is to attempt to read the \code{"tracks"} 
layer.}

\item{geom}{An override for when spatial data files contain more than one 
geometry type in a layer. This is commonly found in GeoJSON and KML files. 
\code{geom} can be one of: \code{"points"}, \code{"lines"}, or 
\code{"polygons"}.}

\item{lower}{Should the names of the data slot be forced to be lower case? 
Note that the default is \code{TRUE}.}

\item{use_iconv}{Should the input strings attempted to be converted by iconv?}

\item{verbose}{Should information about the data be printed when being 
loaded? Default is \code{TRUE}.}
}
\description{
\code{sp_read} is a wrapper for \code{rgdal::readOGR}, but its usage is the 
same as the other file readers in R. Unlike \code{rgdal::readOGR},
\code{sp_read} will expand file paths and make a "best-guess" on what layer 
is to be loaded for spatial data files. Use \code{sp_list_layers} to find what
layers a spatial data file contains.
}
\details{
\code{sp_read} will also wrap \code{readRDS} if an \code{.rds} file is 
detected, but will raise a warning if the file does not contain a spatial 
data type.
}
\examples{
\dontrun{

# Load a shapefile without extension
sp_london <- sp_read("london_borough")

# Load a shapefile with an extension within home area
sp_london <- sp_read("~/Desktop/london_borough.shp")

# Load a gpx file
sp_hira <- sp_read("~/Desktop/hira_mtb_park.gpx", type = "tracks")

# Load GeoJSON file
sp_thames_locks <- sp_read("thames_locks.json", verbose = FALSE)

# Load mapinfo file
sp_coastline <- sp_read("nz-land-districts.map", verbose = FALSE)

# Geodatabase
sp_yemen <- sp_read("world.gdb", layer = "yemen", verbose = FALSE)

# Load a file by using a url
file <- "https://bit.ly/2FkUuAP"
sp_ridgeway <- sp_read(file, layer = "routes") 

}

}
\seealso{
\code{\link{readOGR}}, \code{\link{sp_list_drivers}}, 
\code{\link{sp_list_layers}}
}
\author{
Stuart K. Grange
}
