How to export spatial datasets in R, such as tornados
dataset in GISTools
package, as a shapefile with the exact same spatial reference and the exact values?
library(GISTools)
data(tornados)
Desired:
- "SpatialPolygonsDataFrame" to "shapefile"
- "(Forced) SpatialPointsDataFrame" to "shapefile"
- "(Non-Forced) SpatialPointsDataFrame" to "shapefile"
- "SpatialLinesDataFrame" to "shapefile".
Answer
Wesley's answer is correct. So to specifically export the tornado data you need to do:
library(GISTools)
library(rgdal)
data(tornados)
writeOGR(obj=torn, dsn="tempdir", layer="torn", driver="ESRI Shapefile") # this is in geographical projection
writeOGR(obj=torn2, dsn="tempdir", layer="torn2", driver="ESRI Shapefile") # this is in equal area projection
For R both of these datasets are simply treated as SpatialPointsDataFrames.
> class(torn)
[1] "SpatialPointsDataFrame"
attr(,"package")
[1] "sp"
> class(torn2)
[1] "SpatialPointsDataFrame"
attr(,"package")
[1] "sp"
No comments:
Post a Comment