Skip to content

Instantly share code, notes, and snippets.

@smakhtin
Forked from josecarlosgonz/geojson.R
Last active August 29, 2015 14:24
Show Gist options
  • Save smakhtin/f06423ae23cb9d30ce75 to your computer and use it in GitHub Desktop.
Save smakhtin/f06423ae23cb9d30ce75 to your computer and use it in GitHub Desktop.
#Write geojson
#====
#Load libraries
library(rgdal)
#dataMap is a dataframe with coordinates on cols 11 (LATITUDE) and 12 (LONGITUDE)
#Transfor coordinates to numeric
dataMap$LATITUDE <- as.numeric(dataMap$LATITUDE)
dataMap$LONGITUDE <- as.numeric(dataMap$LONGITUDE)
dataMap.SP <- SpatialPointsDataFrame(dataMap[,c(12,11)],dataMap[,-c(12,11)])
str(dataMap.SP) # Now is class SpatialPointsDataFrame
#Write as geojson
writeOGR(dataMap.SP, 'dataMap.geojson','dataMap', driver='GeoJSON', check_exists = FALSE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment