[GIS] Error: identicalCRS(x, y) is not TRUE

r

I have a spatial Grid dataframe, Elev, that I want to crop by a spatial polygon object (state.sp).

I assigned the CRS to both objects with spTransform and the CRS defined as:

CRS.new<-CRS("+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0+datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0")  #EPSG:102003

Both objects seem to be in conformity CRS, because when I type

 > Elev@proj4string
    CRS arguments:
     +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83
    +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0 

  > state.sp@proj4string
    CRS arguments:
     +proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0+datum=NAD83
    +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0 

Nevertheless, when I do

Felev <- Elev[state.sp, ]

It returns the following error:

Error: identicalCRS(x, y) is not TRUE 

Does anyone know why this might be happening?

Best Answer

Well, in case anyone has this problem, here's a solution I just realized that works. By simply:

proj4string(state.sp) <- CRS.new 
proj4string(Elev) <- CRS.new

before doing the over() and it works perfectly. I'm letting the question stay here, in the hope that it might help someone in the future. :)