You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SF对象CRS转换异常及坐标系匹配问题求助

Fixing CRS Issues When Converting from SpatialLinesDataFrame to sf and Transforming to Raster CRS

Hey there, let's break down and fix these CRS problems step by step:

1. Repair the sf object's missing SRID and incomplete CRS

When you converted your SpatialLinesDataFrame to sf with st_as_sf(roads, crs = 27700), you might have overwritten the full, official CRS definition that was already present in the original spatial object. Instead, use st_set_crs() with the EPSG code to load the complete, standardized CRS for EPSG:27700 (which includes the datum=OSGB36 info you're missing):

# Set the correct CRS using the EPSG code
roads <- st_set_crs(roads, 27700)

# Verify the fix
st_crs(roads)

This should now show epsg (SRID): 27700 along with the full proj4string including the datum details.

2. Fix the st_transform error

The error cannot create a crs from an object of class CRS happens because st_transform() expects an sf-compatible CRS object (from st_crs()), not the sp-style CRS object returned by crs(raster). You have two simple fixes here:

Option 1: Convert the raster's CRS to an sf-compatible object

# Get the raster's CRS in sf format
target_crs <- st_crs(crs(raster))

# Transform the roads sf object
roads <- st_transform(roads, target_crs)

Option 2: Use the proj4 string directly from the raster

# Extract the proj4 string as a character
target_proj <- as.character(crs(raster))

# Transform using the proj4 string
roads <- st_transform(roads, target_proj)

3. Verify the transformation

After running either option, check that the CRS matches your raster:

# Check roads CRS
st_crs(roads)

# Compare to raster CRS
crs(raster)

They should now align, and you can proceed with extracting values from your raster.

内容的提问来源于stack exchange,提问作者TheRealJimShady

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:02:13