[GIS] spTransform error (unable to find inherited method for function spTransform)

rsf

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"’

Best Answer

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"))