将雷达数据重新投影到不同的坐标系。

huangapple go评论63阅读模式
英文:

Reprojecting radar data to a different coordinate system

问题

如果我使用以下代码将一个空间栅格重新投影到另一个:

old_crs <- "+proj=stere +x_0=0 +y_0=0 +lat_0=90 +lon_0=0 +lat_ts=60 +a=6378.137 +b=6356.752 +units=m"
a <- terra::rast(ncol = 700, nrow = 765, ext=c(-236275.403,  106985.856, 501792.127,  900792.861), crs=old_crs)

newcrs = "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
b <- terra::rast(ncols=700, nrows=765, ext=c(3.2, 7.3, 50.7, 53.7), crs=newcrs)
w <- terra::project(a,b)

这将把栅格 a 从原始坐标系重新投影到 b 的坐标系。

如果要将类似于 a 的带有值的栅格重新投影到“Lat/Lon”坐标系,并出现错误,请检查以下内容:

  • 栅格 a 是否具有正确的坐标引用(+proj=stere +lat_0=90 +lat_ts=60 +lon_0=0 +x_0=0 +y_0=0 +a=6378.137 +b=6356.752 +units=m +no_defs)。
  • 确保栅格 a 和栅格 b 具有相同的分辨率和大小。
  • 检查栅格 a 是否有合适的投影参数,以确保与新坐标系兼容。

如果仍然出现错误,请提供更多关于栅格 a 的信息,以便更详细地解决问题。

英文:

If I use this code to reproject one spat raster to another:

old_crs&lt;-&quot;+proj=stere +x_0=0 +y_0=0 +lat_0=90 +lon_0=0 +lat_ts=60 +a=6378.137 +b=6356.752 +units=m&quot;
a&lt;-terra::rast(ncol = 700, nrow = 765, ext=c(-236275.403,  106985.856, 501792.127,  900792.861), crs=old_crs)

newcrs=&quot;+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0&quot;
b &lt;- terra::rast(ncols=700, nrows=765, ext=c(3.2, 7.3, 50.7, 53.7), crs=newcrs)
w &lt;- terra::project(a,b)

Which reprojects raster a:

class       : SpatRaster 
dimensions  : 765, 700, 1  (nrow, ncol, nlyr)
resolution  : 490.3732, 521.5696  (x, y)
extent      : -236275.4, 106985.9, 501792.1, 900792.9  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=stere +lat_0=90 +lat_ts=60 +lon_0=0 +x_0=0 +y_0=0 +a=6378.137 +b=6356.752 +units=m +no_defs 
&gt;

To Raster b

class       : SpatRaster 
dimensions  : 765, 700, 1  (nrow, ncol, nlyr)
resolution  : 0.005857143, 0.003921569  (x, y)
extent      : 3.2, 7.3, 50.7, 53.7  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs 

And creates Raster w

class       : SpatRaster 
dimensions  : 765, 700, 1  (nrow, ncol, nlyr)
resolution  : 0.005857143, 0.003921569  (x, y)
extent      : 3.2, 7.3, 50.7, 53.7  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs 

Then it works without a problem.

As soon as I replace Ratser a with this raster:

class       : SpatRaster 
dimensions  : 765, 700, 1  (nrow, ncol, nlyr)
resolution  : 490.3732, 521.5696  (x, y)
extent      : -236275.4, 106985.9, 501792.1, 900792.9  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=stere +lat_0=90 +lat_ts=60 +lon_0=0 +x_0=0 +y_0=0 +a=6378.137 +b=6356.752 +units=m +no_defs 
source(s)   : memory
name        : lyr.1 
min value   :     0 
max value   :   133 

Which is similat ro Ratser a but has values, The projection does not work.

Error: [project] Cannot do this transformation
In addition: Warning messages:
1: In x@ptr$warp(y@ptr, &quot;&quot;, method, mask[1], align[1], FALSE, opt) :
  GDAL Error 1: PROJ: proj_create_operations: Source and target ellipsoid do not belong to the same celestial body

What am I doing wrong?

I would like to reporject this Raster

class       : SpatRaster 
dimensions  : 765, 700, 1  (nrow, ncol, nlyr)
resolution  : 490.3732, 521.5696  (x, y)
extent      : -236275.4, 106985.9, 501792.1, 900792.9  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=stere +lat_0=90 +lat_ts=60 +lon_0=0 +x_0=0 +y_0=0 +a=6378.137 +b=6356.752 +units=m +no_defs 
source(s)   : memory
name        : lyr.1 
min value   :     0 
max value   :   133 

To "Lat/Lon" coordinates.

Thank you!

答案1

得分: 1

以下是代码部分的翻译:

library(terra)
a <- terra::rast(ncol = 700, nrow = 765, ext=c(-236275.403,  106985.856, 501792.127,  900792.861), crs=old_crs)
values(a) <- 1:ncell(a)
old_crs<-"+proj=stere +x_0=0 +y_0=0 +lat_0=90 +lon_0=0 +lat_ts=60 +a=6378.137 +b=6356.752 +units=m"
newcrs="+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
old_crs<-"+proj=stere +x_0=0 +y_0=0 +lat_0=90 +lon_0=0 +lat_ts=60 +a=6378137 +b=6356752 +units=m"
newcrs <- "+proj=longlat +datum=WGS84"
crs(a) <- old_crs
w <- terra::project(a, newcrs)
plot(w)
crs(a) <- "+proj=stere +lat_0=46 +lon_0=6"
w <- terra::project(a, newcrs)
round(ext(w), 3)
#SpatExtent : 2.413, 7.624, 50.461, 54.083 (xmin, xmax, ymin, ymax)

请注意,以上只是代码部分的翻译。

英文:

Your data

library(terra)
a &lt;- terra::rast(ncol = 700, nrow = 765, ext=c(-236275.403,  106985.856, 501792.127,  900792.861), crs=old_crs)
values(a) &lt;- 1:ncell(a)
old_crs&lt;-&quot;+proj=stere +x_0=0 +y_0=0 +lat_0=90 +lon_0=0 +lat_ts=60 +a=6378.137 +b=6356.752 +units=m&quot;
newcrs=&quot;+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0&quot;

old_crs is not good. The values for the ellipsoid parameters are in km, not in m, and that makes the earth very small. I suppose that is why you get the "other celestial body" warning.

Also, you should not add +ellps and +towgs84 to new_crs (but that is not the problem here).

This is more reasonable:

old_crs&lt;-&quot;+proj=stere +x_0=0 +y_0=0 +lat_0=90 +lon_0=0 +lat_ts=60 +a=6378137 +b=6356752 +units=m&quot;
newcrs &lt;- &quot;+proj=longlat +datum=WGS84&quot;

The best way to debug this is to only provide a crs, not a template raster, to see where the data end up. With the fixed CRS the projection "works", but the data are not in the right place.

crs(a) &lt;- old_crs
w &lt;- terra::project(a, newcrs)
plot(w)

The CRS used below gets the data in the area where The Netherlands is.

crs(a) &lt;- &quot;+proj=stere +lat_0=46 +lon_0=6&quot;
w &lt;- terra::project(a, newcrs)
round(ext(w), 3)
#SpatExtent : 2.413, 7.624, 50.461, 54.083 (xmin, xmax, ymin, ymax)

But this is not likely to be correct. So I think you need to ask the data provider what the CRS actually is. Or perhaps look at some other datasets that the KNMI provides --- these might have the correct CRS.

huangapple
  • 本文由 发表于 2023年4月11日 02:31:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75979712.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定