10

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?

whyzar
  • 12,053
  • 23
  • 38
  • 72
user89556
  • 101
  • 1
  • 3
  • 1
    Typo: there's a space missing in your first code block: "+y_0=0+datum=NAD83" - whether that's a typo in your work or just your post here we don't know... – Spacedman Jan 12 '17 at 16:56

1 Answers1

7

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. :)

La Cordillera
  • 309
  • 1
  • 7