Skip to content

Instantly share code, notes, and snippets.

@gka
Created September 2, 2015 16:16
Show Gist options
  • Save gka/10006e4f78d69bd1adef to your computer and use it in GitHub Desktop.
Save gka/10006e4f78d69bd1adef to your computer and use it in GitHub Desktop.

Useful R

GEO stuff

library(rgdal)
library(maptools)

Defining projections

proj <- CRS('+proj=aea +lat_1=29.5 +lat_2=45.5 ...')
latlon <- CRS("+proj=longlat +datum=WGS84")

Converting a data frame with lat lon into a geo data set

data <- read.csv('list-of-points.csv')
# define the columns that contain the coordinates 
coordinates(data) <- c('lat', 'lon')
# and specify the source projection, usually wgs84 latlon
proj4string(data) <- latlon 

Re-projecting a dataset

data <- spTransform(data, proj)

Store as point shapefile

writePointsShape(data, 'points.shp')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment