简体   繁体   English

绘制R中地理位置的LAT / LON坐标

[英]plot LAT/LON coordinates on geotiff in R

I have a sea ice map as a "geotiff". 我有一张海冰地图作为“geotiff”。 The eventual goal is to extract sea-ice concentrations at specific lat/lon coordinates. 最终的目标是在特定的纬度/经度坐标处提取海冰浓度。

The geotiff can be found at: http://www.iup.uni-bremen.de:8084/amsr2data/asi_daygrid_swath/n6250/2015/jan/asi-AMSR2-n6250-20150101-v5.tif 地理信息可以在以下网址找到: http//www.iup.uni-bremen.de :8084 /amsr2data /asi_daygrid_swath / n6250 / 2015 / jan / as-AMSR2-n6250-20150101-v5.tif

What i am trying to do is load the geotiff using raster() and then overlay it by my locations and then using the extract() function to acquire values from the raster file at the specific location. 我想要做的是使用raster()加载geotiff,然后通过我的位置覆盖它,然后使用extract()函数从特定位置的栅格文件中获取值。

However my lat/lon points accumulate in the centre of the map. 但是我的纬度/经度积累在地图的中心。 Where do I go wrong? 我哪里出错了? Any help or input is greatly appreciated! 非常感谢任何帮助或输入!

library(raster)
library(sp)

r1 = raster("test.tif")

##check plot
plot(r1)

## check projection
projection(r1)

mydf <- structure(list(longitude = rep(22,7), latitude = seq(60,90,5)),.Names = c("longitude","latitude"), class = "data.frame", row.names = c(NA, -7L)) 

### Get long and lat from data.frame.
xy <- mydf[,c(1,2)]
spdf <- SpatialPointsDataFrame(coords = xy, data = mydf,
                           proj4string = CRS("+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0"))

 points(spdf, col="red", lwd=2)

 ##extract RGB values as reference for sea-ice concentration
 seaice_conc = extract(r1, spdf)

Geo-sp's solution would work, but is sub-optimal (slow and imprecise). Geo-sp的解决方案可行,但不是最佳的(缓慢且不精确)。 You should always (re-)project your vector (points in this case) data and not your raster data. 您应该始终(重新)投影矢量(在这种情况下为点)数据,而不是栅格数据。 Projecting raster data changes values, while this is not the case with vector data. 投影栅格数据会更改值,而矢量数据则不是这种情况。 Projecting raster data is also much more computationally intensive. 投影栅格数据的计算量也要大得多。

Thus, you should do something like this: 因此,你应该做这样的事情:

library(raster)

r <- raster("asi-AMSR2-n6250-20150101-v5.tif")
crs(r)
# CRS arguments:
# +proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 

df <- data.frame(longitude = rep(22,7), latitude = seq(60,90,5), ID=1:7)

spdf <- SpatialPointsDataFrame(coords = df[,1:2], data = df,
         proj4string = CRS("+proj=longlat +datum=WGS84"))


library(rgdal)
p <- spTransform(spdf, crs(r))       

extract(r, p)

It is important to note that you made a very common mistake: 重要的是要注意你犯了一个很常见的错误:

spdf <- SpatialPointsDataFrame(coords = xy, data = mydf, proj4string =
          CRS("+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m"))

You create a SpatialPointsDataFrame and assign the wrong coordinate reference system (crs). 您创建SpatialPointsDataFrame并分配错误的坐标参考系统(crs)。 You must assign the crs that actually matches your data, which is "+proj=longlat +datum=WGS84" . 您必须分配实际匹配数据的crs,即"+proj=longlat +datum=WGS84" After that, you can transform the data to the crs that you would like to have (using spTransform ). 之后,您可以数据转换为您想要的crs(使用spTransform )。

You can use projectRaster to reproject your raster file. 您可以使用projectRaster重新投影光栅文件。 Then you can overlay the points and extract the values. 然后,您可以叠加点并提取值。

newproj <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0")
p <- projectRaster(r1, newproj)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM