Last active
May 17, 2021 10:28
-
-
Save josecarlosgonz/8565908 to your computer and use it in GitHub Desktop.
How to create a geojson file in R from a dataframe
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
#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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This feature generate a unique polygon? There is a iterative mode to create 1, 2, 3 polygons?