Title: | World Map Data from Natural Earth |
---|---|
Description: | Facilitates mapping by making natural earth map data from <https://www.naturalearthdata.com/> more easily available to R users. |
Authors: | Philippe Massicotte [aut, cre] (ORCID: <https://orcid.org/0000-0002-5919-4116>), Andy South [aut], Koen Hufkens [ctb] (ORCID: <https://orcid.org/0000-0002-5070-8109>) |
Maintainer: | Philippe Massicotte <pmassicotte@hotmail.com> |
License: | MIT + file LICENSE |
Version: | 1.1.0 |
Built: | 2025-04-14 20:21:01 UTC |
Source: | https://github.com/ropensci/rnaturalearth |
checks from a list dependent on type, category and scale. If it returns FALSE the data may still exist on the website. Doesn't yet do checking on raster names because I found the naming convention too tricky.
check_data_exist( type, scale = 110L, category = c("cultural", "physical", "raster") )
check_data_exist( type, scale = 110L, category = c("cultural", "physical", "raster") )
type |
type of natural earth file to download one of 'countries', 'map_units', 'map_subunits', 'sovereignty', 'states' OR the portion of any natural earth vector url after the scale and before the . e.g. for 'ne_50m_urban_areas.zip' this would be 'urban_areas' OR the raster filename e.g. for 'MSR_50M.zip' this would be 'MSR_50M' |
scale |
The scale of map to return, one of '110', '50', '10' or 'small', 'medium', 'large'. |
category |
one of natural earth categories : 'cultural', 'physical', 'raster' |
Note that the filename of the requested object will be returned if 'load = FALSE'.
If the data is to be loaded into memory ('load = TRUE'), the download will be handled using the GDAL virtual file system, allowing direct access to the data without writing it to disk.
TRUE or FALSE
ne_load
, pre-downloaded data are available using
ne_countries
, ne_states
. Other geographic data
are available in the raster package : getData
.
check_data_exist(type = "countries", scale = 110, category = "cultural") # Type not in list for this category check_data_exist(type = "airports", scale = 110, category = "physical") # Type in list but scale shows FALSE check_data_exist(type = "airports", scale = 110, category = "cultural")
check_data_exist(type = "countries", scale = 110, category = "cultural") # Type not in list for this category check_data_exist(type = "airports", scale = 110, category = "physical") # Type in list but scale shows FALSE check_data_exist(type = "airports", scale = 110, category = "cultural")
If the rnaturalearthdata package is not installed, install it from GitHub using devtools. If it is not up to date, reinstall it.
check_rnaturalearthdata()
check_rnaturalearthdata()
If the rnaturalearthhires package is not installed, install it from GitHub using devtools. If it is not up to date, reinstall it.
check_rnaturalearthhires()
check_rnaturalearthhires()
check name or numeric scale representations, return numeric one
check_scale(x)
check_scale(x)
x |
scale of map to return, one of |
integer scale of map
returns downloaded data as a spatial object or the filename if
load=FALSE
. if destdir
is specified the data can be reloaded in
a later R session using ne_load
with the same arguments.
convert_spatial_class(x, returnclass = c("sf", "sv"))
convert_spatial_class(x, returnclass = c("sf", "sv"))
x |
Object to be converted |
returnclass |
A string determining the spatial object to return. Either "sf" for for simple feature (from 'sf', the default) or "sv" for a 'SpatVector' (from 'terra'). |
Note that the filename of the requested object will be returned if 'load = FALSE'.
If the data is to be loaded into memory ('load = TRUE'), the download will be handled using the GDAL virtual file system, allowing direct access to the data without writing it to disk.
Object of class "sf" or "sv"
ne_load
, pre-downloaded data are available using
ne_countries
, ne_states
. Other geographic data
are available in the raster package : getData
.
## Not run: spdf_world <- ne_download(scale = 110, type = "countries") plot(spdf_world) plot(ne_download(type = "populated_places")) # reloading from the saved file in the same session with same arguments spdf_world2 <- ne_load(scale = 110, type = "countries") # download followed by load from specified directory will work across sessions spdf_world <- ne_download(scale = 110, type = "countries", destdir = getwd()) spdf_world2 <- ne_load(scale = 110, type = "countries", destdir = getwd()) # for raster, here an example with Manual Shaded Relief (MSR) download & load rst <- ne_download(scale = 50, type = "MSR_50M", category = "raster", destdir = getwd()) # load after having downloaded rst <- ne_load( scale = 50, type = "MSR_50M", category = "raster", destdir = getwd() ) # plot library(terra) terra::plot(rst) # end dontrun ## End(Not run)
## Not run: spdf_world <- ne_download(scale = 110, type = "countries") plot(spdf_world) plot(ne_download(type = "populated_places")) # reloading from the saved file in the same session with same arguments spdf_world2 <- ne_load(scale = 110, type = "countries") # download followed by load from specified directory will work across sessions spdf_world <- ne_download(scale = 110, type = "countries", destdir = getwd()) spdf_world2 <- ne_load(scale = 110, type = "countries", destdir = getwd()) # for raster, here an example with Manual Shaded Relief (MSR) download & load rst <- ne_download(scale = 50, type = "MSR_50M", category = "raster", destdir = getwd()) # load after having downloaded rst <- ne_load( scale = 50, type = "MSR_50M", category = "raster", destdir = getwd() ) # plot library(terra) terra::plot(rst) # end dontrun ## End(Not run)
at 1:110m scale (small). Other data and resolutions are in the packages rnaturalearthdata and rnaturalearthhires.
countries110
countries110
A sf
object.
An object of class sf
(inherits from data.frame
) with 177 rows and 169 columns.
data
A data frame with country attributes.
https://naciscdn.org/naturalearth/10m/cultural/ne_10m_admin_0_countries.zip
list of cultural layers available from Natural Earth
df_layers_cultural
df_layers_cultural
A DataFrame
An object of class data.frame
with 43 rows and 4 columns.
list of physical layers available from Natural Earth
df_layers_physical
df_layers_physical
A DataFrame
An object of class data.frame
with 29 rows and 4 columns.
returns world country polygons at a specified scale, used by ne_countries()
get_data( scale = 110L, type = c("countries", "map_units", "sovereignty", "tiny_countries") )
get_data( scale = 110L, type = c("countries", "map_units", "sovereignty", "tiny_countries") )
scale |
The scale of map to return, one of '110', '50', '10' or 'small', 'medium', 'large'. |
type |
country type, one of 'countries', 'map_units', 'sovereignty', 'tiny_countries' |
Note that the filename of the requested object will be returned if 'load = FALSE'.
If the data is to be loaded into memory ('load = TRUE'), the download will be handled using the GDAL virtual file system, allowing direct access to the data without writing it to disk.
A sf
object.
ne_load
, pre-downloaded data are available using
ne_countries
, ne_states
. Other geographic data
are available in the raster package : getData
.
## Not run: spdf_world <- ne_download(scale = 110, type = "countries") plot(spdf_world) plot(ne_download(type = "populated_places")) # reloading from the saved file in the same session with same arguments spdf_world2 <- ne_load(scale = 110, type = "countries") # download followed by load from specified directory will work across sessions spdf_world <- ne_download(scale = 110, type = "countries", destdir = getwd()) spdf_world2 <- ne_load(scale = 110, type = "countries", destdir = getwd()) # for raster, here an example with Manual Shaded Relief (MSR) download & load rst <- ne_download(scale = 50, type = "MSR_50M", category = "raster", destdir = getwd()) # load after having downloaded rst <- ne_load( scale = 50, type = "MSR_50M", category = "raster", destdir = getwd() ) # plot library(terra) terra::plot(rst) # end dontrun ## End(Not run)
## Not run: spdf_world <- ne_download(scale = 110, type = "countries") plot(spdf_world) plot(ne_download(type = "populated_places")) # reloading from the saved file in the same session with same arguments spdf_world2 <- ne_load(scale = 110, type = "countries") # download followed by load from specified directory will work across sessions spdf_world <- ne_download(scale = 110, type = "countries", destdir = getwd()) spdf_world2 <- ne_load(scale = 110, type = "countries", destdir = getwd()) # for raster, here an example with Manual Shaded Relief (MSR) download & load rst <- ne_download(scale = 50, type = "MSR_50M", category = "raster", destdir = getwd()) # load after having downloaded rst <- ne_load( scale = 50, type = "MSR_50M", category = "raster", destdir = getwd() ) # plot library(terra) terra::plot(rst) # end dontrun ## End(Not run)
Install the naturalearthdata package after checking with the user
install_rnaturalearthdata()
install_rnaturalearthdata()
Install the naturalearthhires package after checking with the user
install_rnaturalearthhires()
install_rnaturalearthhires()
Generate the layer name for a Natural Earth dataset
layer_name(type, scale)
layer_name(type, scale)
type |
type of natural earth file to download one of 'countries', 'map_units', 'map_subunits', 'sovereignty', 'states' OR the portion of any natural earth vector url after the scale and before the . e.g. for 'ne_50m_urban_areas.zip' this would be 'urban_areas' OR the raster filename e.g. for 'MSR_50M.zip' this would be 'MSR_50M' |
scale |
The scale of map to return, one of '110', '50', '10' or 'small', 'medium', 'large'. |
A string representing the dataset layer name.
returns world coastline at specified scale
ne_coastline(scale = 110L, returnclass = c("sf", "sv"))
ne_coastline(scale = 110L, returnclass = c("sf", "sv"))
scale |
The scale of map to return, one of '110', '50', '10' or 'small', 'medium', 'large'. |
returnclass |
A string determining the spatial object to return. Either "sf" for for simple feature (from 'sf', the default) or "sv" for a 'SpatVector' (from 'terra'). |
Note that the filename of the requested object will be returned if 'load = FALSE'.
If the data is to be loaded into memory ('load = TRUE'), the download will be handled using the GDAL virtual file system, allowing direct access to the data without writing it to disk.
An object of class 'sf' for simple feature (from 'sf', the default) or 'SpatVector' (from 'terra').
ne_load
, pre-downloaded data are available using
ne_countries
, ne_states
. Other geographic data
are available in the raster package : getData
.
if (requireNamespace("rnaturalearthdata")) { coast <- ne_coastline() plot(coast) }
if (requireNamespace("rnaturalearthdata")) { coast <- ne_coastline() plot(coast) }
returns world country polygons at a specified scale, or points of tiny_countries
ne_countries( scale = 110L, type = "countries", continent = NULL, country = NULL, geounit = NULL, sovereignty = NULL, returnclass = c("sf", "sv") )
ne_countries( scale = 110L, type = "countries", continent = NULL, country = NULL, geounit = NULL, sovereignty = NULL, returnclass = c("sf", "sv") )
scale |
The scale of map to return, one of '110', '50', '10' or 'small', 'medium', 'large'. |
type |
country type, one of 'countries', 'map_units', 'sovereignty', 'tiny_countries' |
continent |
a character vector of continent names to get countries from. |
country |
a character vector of country names. |
geounit |
a character vector of geounit names. |
sovereignty |
a character vector of sovereignty names. |
returnclass |
A string determining the spatial object to return. Either "sf" for for simple feature (from 'sf', the default) or "sv" for a 'SpatVector' (from 'terra'). |
Note that the filename of the requested object will be returned if 'load = FALSE'.
If the data is to be loaded into memory ('load = TRUE'), the download will be handled using the GDAL virtual file system, allowing direct access to the data without writing it to disk.
An object of class 'sf' for simple feature (from 'sf', the default) or 'SpatVector' (from 'terra').
ne_load
, pre-downloaded data are available using
ne_countries
, ne_states
. Other geographic data
are available in the raster package : getData
.
world <- ne_countries() africa <- ne_countries(continent = "africa") france <- ne_countries(country = "france") plot(world$geometry) plot(africa$geometry) plot(france$geometry) # get as SpatVector world <- ne_countries(returnclass = "sv") terra::plot(world) tiny_countries <- ne_countries(type = "tiny_countries", scale = 50) plot(tiny_countries)
world <- ne_countries() africa <- ne_countries(continent = "africa") france <- ne_countries(country = "france") plot(world$geometry) plot(africa$geometry) plot(france$geometry) # get as SpatVector world <- ne_countries(returnclass = "sv") terra::plot(world) tiny_countries <- ne_countries(type = "tiny_countries", scale = 50) plot(tiny_countries)
returns downloaded data as a spatial object or the filename if
load=FALSE
. if destdir
is specified the data can be reloaded in
a later R session using ne_load
with the same arguments.
ne_download( scale = 110L, type = "countries", category = c("cultural", "physical", "raster"), destdir = tempdir(), load = TRUE, returnclass = c("sf", "sv") )
ne_download( scale = 110L, type = "countries", category = c("cultural", "physical", "raster"), destdir = tempdir(), load = TRUE, returnclass = c("sf", "sv") )
scale |
The scale of map to return, one of '110', '50', '10' or 'small', 'medium', 'large'. |
type |
type of natural earth file to download one of 'countries', 'map_units', 'map_subunits', 'sovereignty', 'states' OR the portion of any natural earth vector url after the scale and before the . e.g. for 'ne_50m_urban_areas.zip' this would be 'urban_areas'. See Details. OR the raster filename e.g. for 'MSR_50M.zip' this would be 'MSR_50M' |
category |
one of natural earth categories : 'cultural', 'physical', 'raster' |
destdir |
where to save files, defaults to |
load |
'TRUE' to load the spatial object into R, 'FALSE' to return the filename of the downloaded object. If the requested object is a vector, it will be saved as a GPKG file. If a raster is requested, it will be saved as a GeoTIFF file. |
returnclass |
A string determining the spatial object to return. Either "sf" for for simple feature (from 'sf', the default) or "sv" for a 'SpatVector' (from 'terra'). |
Note that the filename of the requested object will be returned if 'load = FALSE'.
If the data is to be loaded into memory ('load = TRUE'), the download will be handled using the GDAL virtual file system, allowing direct access to the data without writing it to disk.
An object of class 'sf' for simple feature (from 'sf', the default) or 'SpatVector' (from 'terra').
ne_load
, pre-downloaded data are available using
ne_countries
, ne_states
. Other geographic data
are available in the raster package : getData
.
## Not run: spdf_world <- ne_download(scale = 110, type = "countries") plot(spdf_world) plot(ne_download(type = "populated_places")) # reloading from the saved file in the same session with same arguments spdf_world2 <- ne_load(scale = 110, type = "countries") # download followed by load from specified directory will work across sessions spdf_world <- ne_download(scale = 110, type = "countries", destdir = getwd()) spdf_world2 <- ne_load(scale = 110, type = "countries", destdir = getwd()) # for raster, here an example with Manual Shaded Relief (MSR) download & load rst <- ne_download(scale = 50, type = "MSR_50M", category = "raster", destdir = getwd()) # load after having downloaded rst <- ne_load( scale = 50, type = "MSR_50M", category = "raster", destdir = getwd() ) # plot library(terra) terra::plot(rst) # end dontrun ## End(Not run)
## Not run: spdf_world <- ne_download(scale = 110, type = "countries") plot(spdf_world) plot(ne_download(type = "populated_places")) # reloading from the saved file in the same session with same arguments spdf_world2 <- ne_load(scale = 110, type = "countries") # download followed by load from specified directory will work across sessions spdf_world <- ne_download(scale = 110, type = "countries", destdir = getwd()) spdf_world2 <- ne_load(scale = 110, type = "countries", destdir = getwd()) # for raster, here an example with Manual Shaded Relief (MSR) download & load rst <- ne_download(scale = 50, type = "MSR_50M", category = "raster", destdir = getwd()) # load after having downloaded rst <- ne_load( scale = 50, type = "MSR_50M", category = "raster", destdir = getwd() ) # plot library(terra) terra::plot(rst) # end dontrun ## End(Not run)
returns a string that can then be used to download the file.
ne_file_name( scale = 110L, type = "countries", category = c("cultural", "physical", "raster") )
ne_file_name( scale = 110L, type = "countries", category = c("cultural", "physical", "raster") )
scale |
The scale of map to return, one of '110', '50', '10' or 'small', 'medium', 'large'. |
type |
type of natural earth file to download one of 'countries', 'map_units', 'map_subunits', 'sovereignty', 'states' OR the portion of any natural earth vector url after the scale and before the . e.g. for 'ne_50m_urban_areas.zip' this would be 'urban_areas' OR the raster filename e.g. for 'MSR_50M.zip' this would be 'MSR_50M' |
category |
one of natural earth categories : 'cultural', 'physical', 'raster' |
Note that the filename of the requested object will be returned if 'load = FALSE'.
If the data is to be loaded into memory ('load = TRUE'), the download will be handled using the GDAL virtual file system, allowing direct access to the data without writing it to disk.
string
ne_load
, pre-downloaded data are available using
ne_countries
, ne_states
. Other geographic data
are available in the raster package : getData
.
ne_url <- ne_file_name(scale = 110, type = "countries")
ne_url <- ne_file_name(scale = 110, type = "countries")
Checks the Natural Earth Github repository for current vector layers and provides the file name required in the type argument of ne_download.
ne_find_vector_data( scale = 110L, category = c("cultural", "physical"), getmeta = FALSE )
ne_find_vector_data( scale = 110L, category = c("cultural", "physical"), getmeta = FALSE )
scale |
The scale of map to return, one of '110', '50', '10' or 'small', 'medium', 'large'. |
category |
one of natural earth categories : 'cultural', 'physical' |
getmeta |
whether to get url of the metadata for each layer |
Note that the filename of the requested object will be returned if 'load = FALSE'.
If the data is to be loaded into memory ('load = TRUE'), the download will be handled using the GDAL virtual file system, allowing direct access to the data without writing it to disk.
dataframe with two variables: layer and metadata
ne_load
, pre-downloaded data are available using
ne_countries
, ne_states
. Other geographic data
are available in the raster package : getData
.
## Not run: ne_find_vector_data(scale = 10, category = "physical") ## End(Not run)
## Not run: ne_find_vector_data(scale = 10, category = "physical") ## End(Not run)
ne_download
returns loaded data as a spatial object.
ne_load( scale = 110L, type = "countries", category = c("cultural", "physical", "raster"), destdir = tempdir(), file_name = NULL, returnclass = c("sf", "sv") )
ne_load( scale = 110L, type = "countries", category = c("cultural", "physical", "raster"), destdir = tempdir(), file_name = NULL, returnclass = c("sf", "sv") )
scale |
The scale of map to return, one of '110', '50', '10' or 'small', 'medium', 'large'. |
type |
type of natural earth file one of 'countries', 'map_units', 'map_subunits', 'sovereignty', 'states' OR the portion of any natural earth vector url after the scale and before the . e.g. for 'ne_50m_urban_areas.zip' this would be 'urban_areas' OR the raster filename e.g. for 'MSR_50M.zip' this would be 'MSR_50M' |
category |
one of natural earth categories : 'cultural', 'physical', 'raster' |
destdir |
folder to load files from, default=tempdir() |
file_name |
OPTIONAL name of file (excluding path) instead of natural earth attributes |
returnclass |
A string determining the spatial object to return. Either "sf" for for simple feature (from 'sf', the default) or "sv" for a 'SpatVector' (from 'terra'). |
Note that the filename of the requested object will be returned if 'load = FALSE'.
If the data is to be loaded into memory ('load = TRUE'), the download will be handled using the GDAL virtual file system, allowing direct access to the data without writing it to disk.
An object of class 'sf' for simple feature (from 'sf', the default) or 'SpatVector' (from 'terra').
## Not run: # download followed by load from tempdir() works in same R session spdf_world <- ne_download(scale = 110, type = "countries") spdf_world2 <- ne_load(scale = 110, type = "countries") # download followed by load from specified directory works between R sessions spdf_world <- ne_download(scale = 110, type = "countries", destdir = getwd()) spdf_world2 <- ne_load(scale = 110, type = "countries", destdir = getwd()) # for raster download & load rst <- ne_download(scale = 50, type = "OB_50M", category = "raster", destdir = getwd()) # load after having downloaded rst <- ne_load(scale = 50, type = "OB_50M", category = "raster", destdir = getwd()) # plot library(terra) plot(rst) # end dontrun ## End(Not run)
## Not run: # download followed by load from tempdir() works in same R session spdf_world <- ne_download(scale = 110, type = "countries") spdf_world2 <- ne_load(scale = 110, type = "countries") # download followed by load from specified directory works between R sessions spdf_world <- ne_download(scale = 110, type = "countries", destdir = getwd()) spdf_world2 <- ne_load(scale = 110, type = "countries", destdir = getwd()) # for raster download & load rst <- ne_download(scale = 50, type = "OB_50M", category = "raster", destdir = getwd()) # load after having downloaded rst <- ne_load(scale = 50, type = "OB_50M", category = "raster", destdir = getwd()) # plot library(terra) plot(rst) # end dontrun ## End(Not run)
returns state polygons (administrative level 1) for specified countries
ne_states( country = NULL, geounit = NULL, iso_a2 = NULL, spat_object = NULL, returnclass = c("sf", "sv") )
ne_states( country = NULL, geounit = NULL, iso_a2 = NULL, spat_object = NULL, returnclass = c("sf", "sv") )
country |
a character vector of country names. |
geounit |
a character vector of geounit names. |
iso_a2 |
a character vector of iso_a2 country codes |
spat_object |
an optional alternative states map |
returnclass |
A string determining the spatial object to return. Either "sf" for for simple feature (from 'sf', the default) or "sv" for a 'SpatVector' (from 'terra'). |
By default, this function uses the scale = 10 data from the
rnaturalearthhires package. While data at scales 50 and 110 exist,
they are not used as defaults because they contain fewer countries
(e.g. scale 50 only includes Australia, Brazil, Canada and United
States of America). For finer control, use ne_download
.
ne_download( scale = 10L, type = "states", category = "cultural")
ne_download( scale = 50L, type = "states", category = "cultural")
ne_download( scale = 110L, type = "states", category = "cultural")
An object of class 'sf' for simple feature (from 'sf', the default) or 'SpatVector' (from 'terra').
ne_load
, pre-downloaded data are available using
ne_countries
, ne_states
. Other geographic data
are available in the raster package : getData
.
# comparing using country and geounit to filter if (requireNamespace("rnaturalearthhires")) { spdf_france_country <- ne_states(country = "france") spdf_france_geounit <- ne_states(geounit = "france") plot(spdf_france_country) plot(spdf_france_geounit) plot(ne_states(country = "united kingdom")) plot(ne_states(geounit = "england")) }
# comparing using country and geounit to filter if (requireNamespace("rnaturalearthhires")) { spdf_france_country <- ne_states(country = "france") spdf_france_geounit <- ne_states(geounit = "france") plot(spdf_france_country) plot(spdf_france_geounit) plot(ne_states(country = "united kingdom")) plot(ne_states(geounit = "england")) }
This function standardizes the 'type' argument by mapping common names to their respective Natural Earth dataset names.
normalize_type(type)
normalize_type(type)
type |
type of natural earth file to download one of 'countries', 'map_units', 'map_subunits', 'sovereignty', 'states' OR the portion of any natural earth vector url after the scale and before the . e.g. for 'ne_50m_urban_areas.zip' this would be 'urban_areas' OR the raster filename e.g. for 'MSR_50M.zip' this would be 'MSR_50M' |
A string representing the normalized dataset type.
This function reads a spatial vector file and returns either an 'sf' object or a 'sv' object.
read_spatial_vector(x, layer, returnclass = c("sf", "sv"))
read_spatial_vector(x, layer, returnclass = c("sf", "sv"))
x |
A character string specifying the path to the spatial vector file. |
layer |
A character string specifying the later to read in case there are more than one in the zip file. |
returnclass |
A character string specifying the class of object to return. Options are "sf" for sf object and "sv" for sv object. |
Either an 'sf' object or a 'sv' object.
This function takes a VSIZIP URL and extracts the http URL from it
sanitize_gdal_url(url)
sanitize_gdal_url(url)
url |
A character string representing the VSIZIP URL |
A character string representing the http URL extracted from the VSIZIP URL