Last active
January 1, 2017 12:48
-
-
Save valentinitnelav/a415f3fbfd90f72ea06b5411fb16df16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ========================================================================== | |
# This is a simple script for downloading, unzipping and reading a shapefile | |
# from www.naturalearthdata.com | |
# ========================================================================== | |
library(rgdal) | |
# ~~~~~~~~~~~ Download shapefile from www.naturalearthdata.com ~~~~~~~~~~~ # | |
# __ Example 1 - download countries data | |
download.file(url = "http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip", | |
destfile = "ne_110m_admin_0_countries.zip") | |
# unzip the shapefile in the directory mentioned with "exdir" argument | |
unzip(zipfile="ne_110m_admin_0_countries.zip", exdir = "ne_110m_admin_0_countries") | |
# delete the zip file | |
file.remove("ne_110m_admin_0_countries.zip") | |
# read the shapefile with readOGR | |
NE_countries <- readOGR(dsn = "ne_110m_admin_0_countries", layer = "ne_110m_admin_0_countries") | |
# __ Example 2 - download main cities data | |
download.file(url = "http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_populated_places.zip", | |
destfile = "ne_110m_populated_places.zip") | |
# unzip the shapefile in the directory mentioned with "exdir" argument | |
unzip(zipfile="ne_110m_populated_places.zip", exdir = "ne_110m_populated_places") | |
# delete the zip file | |
file.remove("ne_110m_populated_places.zip") | |
# read the shapefile with readOGR | |
NE_places <- readOGR(dsn = "ne_110m_populated_places", layer = "ne_110m_populated_places", stringsAsFactors=FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment