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

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

Reprojecting radar data to a different coordinate system

问题

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

  1. 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"
  2. a <- terra::rast(ncol = 700, nrow = 765, ext=c(-236275.403, 106985.856, 501792.127, 900792.861), crs=old_crs)
  3. newcrs = "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
  4. b <- terra::rast(ncols=700, nrows=765, ext=c(3.2, 7.3, 50.7, 53.7), crs=newcrs)
  5. 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:

  1. 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;
  2. a&lt;-terra::rast(ncol = 700, nrow = 765, ext=c(-236275.403, 106985.856, 501792.127, 900792.861), crs=old_crs)
  3. newcrs=&quot;+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0&quot;
  4. b &lt;- terra::rast(ncols=700, nrows=765, ext=c(3.2, 7.3, 50.7, 53.7), crs=newcrs)
  5. w &lt;- terra::project(a,b)

Which reprojects raster a:

  1. class : SpatRaster
  2. dimensions : 765, 700, 1 (nrow, ncol, nlyr)
  3. resolution : 490.3732, 521.5696 (x, y)
  4. extent : -236275.4, 106985.9, 501792.1, 900792.9 (xmin, xmax, ymin, ymax)
  5. 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
  6. &gt;

To Raster b

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

And creates Raster w

  1. class : SpatRaster
  2. dimensions : 765, 700, 1 (nrow, ncol, nlyr)
  3. resolution : 0.005857143, 0.003921569 (x, y)
  4. extent : 3.2, 7.3, 50.7, 53.7 (xmin, xmax, ymin, ymax)
  5. 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:

  1. class : SpatRaster
  2. dimensions : 765, 700, 1 (nrow, ncol, nlyr)
  3. resolution : 490.3732, 521.5696 (x, y)
  4. extent : -236275.4, 106985.9, 501792.1, 900792.9 (xmin, xmax, ymin, ymax)
  5. 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
  6. source(s) : memory
  7. name : lyr.1
  8. min value : 0
  9. max value : 133

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

  1. Error: [project] Cannot do this transformation
  2. In addition: Warning messages:
  3. 1: In x@ptr$warp(y@ptr, &quot;&quot;, method, mask[1], align[1], FALSE, opt) :
  4. 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

  1. class : SpatRaster
  2. dimensions : 765, 700, 1 (nrow, ncol, nlyr)
  3. resolution : 490.3732, 521.5696 (x, y)
  4. extent : -236275.4, 106985.9, 501792.1, 900792.9 (xmin, xmax, ymin, ymax)
  5. 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
  6. source(s) : memory
  7. name : lyr.1
  8. min value : 0
  9. max value : 133

To "Lat/Lon" coordinates.

Thank you!

答案1

得分: 1

以下是代码部分的翻译:

  1. library(terra)
  2. a <- terra::rast(ncol = 700, nrow = 765, ext=c(-236275.403, 106985.856, 501792.127, 900792.861), crs=old_crs)
  3. values(a) <- 1:ncell(a)
  4. 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"
  5. newcrs="+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
  1. 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"
  2. newcrs <- "+proj=longlat +datum=WGS84"
  1. crs(a) <- old_crs
  2. w <- terra::project(a, newcrs)
  3. plot(w)
  1. crs(a) <- "+proj=stere +lat_0=46 +lon_0=6"
  2. w <- terra::project(a, newcrs)
  3. round(ext(w), 3)
  4. #SpatExtent : 2.413, 7.624, 50.461, 54.083 (xmin, xmax, ymin, ymax)

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

英文:

Your data

  1. library(terra)
  2. a &lt;- terra::rast(ncol = 700, nrow = 765, ext=c(-236275.403, 106985.856, 501792.127, 900792.861), crs=old_crs)
  3. values(a) &lt;- 1:ncell(a)
  4. 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;
  5. 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:

  1. 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;
  2. 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.

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

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

  1. crs(a) &lt;- &quot;+proj=stere +lat_0=46 +lon_0=6&quot;
  2. w &lt;- terra::project(a, newcrs)
  3. round(ext(w), 3)
  4. #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:

确定