Created
August 7, 2014 17:26
-
-
Save josecarlosgonz/029c5ce586beae723cfb to your computer and use it in GitHub Desktop.
Create a shapefile from a csv with latitude and longitude coordinates
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
# Create a shapefile from a csv with latitude and longitude coordinates in | |
# decimal degrees | |
# Install and load rdgal | |
install.packages(rdgal) | |
require(rgdal) | |
# Load data | |
data <- read.csv("Coordinates.csv") | |
head(data) | |
# Add id so the shapefile is not empty | |
data$id <- rep(1:length(data$Longitude)) | |
head(data) | |
# Convert to spatial object longitude goes first | |
data.SP <- SpatialPointsDataFrame(data[,c(2,1)],data[,-c(2,1)]) | |
str(dataMap.SP) # Now is class SpatialPointsDataFrame | |
# Write as shapefile inside the folder "coordinates" | |
writeOGR(data.SP, "coordinates", "coordinates", driver="ESRI Shapefile", layer_options= c(encoding= "UTF-8"), | |
overwrite_layer=T) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment