8

I am trying to reproject a shapefile. For example, the land shapefile from Natural Earth.

library(sf)
shape <- read_sf(".../ne_10m_land.shp")

shape_proj<-spTransform(shape, CRS("+proj=gnom +lat_0=90 +lon_0=-50"))

I keep getting the following error, even when I try with CRSobj= or using other ways to express the CRS.

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘spTransform’ for signature ‘"sf", "CRS"’

1
  • 5
    You're mixing two generations of vector features packages. spTranform is for sp objects (the 'old' way). For sf objects you must use st_transform Jan 2, 2019 at 22:36

2 Answers 2

9

check the data type,

class(shape)

if it returns sf "data.frame" you should use st_transform instead of spTransform

shape_proj<-st_transform(shape, CRS("+proj=gnom +lat_0=90 +lon_0=-50"))
1

Try to use this function instead: st_transform(shape,st_crs(shape2)) #that's if you want your CRS to match another coordinate system (shape2 in this case)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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