1

I have a shapefile with shapelength and shapearea, and would like to convert to WGS84 to use with ggmap.

enter image description here

Eventually, I would like to get plot google map of individual regions of the shapefile, and overlay it with other date

What can I use in R program to do this, i.e. convert to WGS84?

  • 1
    Note: The WKID is EPSG:2263, NAD83 / New York Long Island (ftUS). – mkennedy Jun 30 '15 at 16:54
3

Use functions from the sp and rgdal packages. Assuming your shape file is named myshp

library(sp)
library(rgdal)
proj4string(myshp) # Gives the CRS of the data 
myshp=spTransform(myshp,CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")) # To convert it to WGS84

ggplot2 input has to be a DataFrame, to convert a SpatialDataFrame to a DataFrame named mydf, run

library(ggplot2)
mydf=fortify(myshp,byid="your id variable") # Converting the SpatialDataFrame to a DataFrame
myshp$id=row.names(myshp) # Adding your SpatialDataFrame data to the DataFrame
mydf=merge(mydf,myshp@data,by="id",all=T)
  • Will try this very soon – Rhonda Jul 1 '15 at 12:13
  • When I execute proj4string(nysd) I get Error: object 'nysd' not found – Rhonda Jul 1 '15 at 12:45
  • I downloaded shapefile from nyc.gov/html/dcp/download/bytes/nysd_15b.zip – Rhonda Jul 1 '15 at 12:47
  • proj4string() uses a SpatialObject as input. To load the spatial object use setwd("your working directory");myshp=readOGR(dsn=getwd(),layer="nysd"). Then run proj4string(nysd), your CRS is NAD83. – goclem Jul 1 '15 at 12:50
  • This certainly helps – Rhonda Jul 1 '15 at 12:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.