英文:
How to convert longlat coordinate into Lambert conformal conic in R
问题
我有一个包含北美洲365层日常气候数据的大型.nc文件。我想要使用R提取特定位置(具有特定纬度和经度的点)的一个气候变量的时间序列。
我尝试过使用ncvar_get("filename.nc", "variable"),但是内存限制不允许我使用这个函数。
我只能使用brick函数,如下所示:
brick.nc <- brick("filename.nc", "variable")
由brick函数创建的RasterBrick的坐标系统和范围如下:
范围:-5802750,-5518750,-622500,-38500(xmin,xmax,ymin,ymax)
crs:+proj=lcc +lat_0=42.5 +lon_0=-100 +lat_1=25 +lat_2=60 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs
我需要提取的位置具有纬度和经度:(18.241755,-158.844437)
问题是我不知道如何将经纬度转换为lcc。
我尝试了这个答案,但它没有给出正确的答案。
任何帮助将不胜感激。
英文:
I have a big .nc file for daily climate data with 365 layers for north America. I want to use R to extract the timeseries of one climate variables for a specific location (a point with specific lat and lon).
I tried ncvar_get(“filename.nc', "variable") but the memory limitation does not let me to use this function.
I can only use brick function as:
brick.nc <- brick(“filename.nc', "variable")
The coordinate system and extent of the RasterBrick made by brick function are as:
extent: -5802750, -5518750, -622500, -38500 (xmin, xmax, ymin, ymax)
crs: +proj=lcc +lat_0=42.5 +lon_0=-100 +lat_1=25 +lat_2=60 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs
The location I need to extract has lat and lon: (18.241755, -158.844437)
the problem is that I don’t know how to convert longlat into lcc.
I tried this answer, but it does not give correct answer.
Any help would be appreciated.
答案1
得分: 1
你可能需要重新考虑你的工作流程,但要将单个纬度/经度点转换为由提供的投影字符串描述的投影,你可以首先创建该点(注意顺序:X(经度,东经),Y(纬度,北纬)),将其转换为了解CRS的对象(如sfc),然后将其转换为目标CRS并提取坐标:
library(sf)
#> 链接到 GEOS 3.9.3、GDAL 3.5.2、PROJ 8.2.1;sf_use_s2() 为 TRUE
st_point(c(-158.844437, 18.241755)) |>
st_sfc(crs = "WGS84") |>
st_transform("+proj=lcc +lat_0=42.5 +lon_0=-100 +lat_1=25 +lat_2=60 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs") |>
st_coordinates()
#> X Y
#> [1,] -5954329 -453417
再次确保在处理坐标时正确处理纬度/经度和X/Y的顺序;在地理坐标(通常是纬度/经度)和投影坐标(通常是X、Y)之间转换时,通常需要交换它们的顺序。
创建于2023-08-10,使用 reprex v2.0.2
英文:
You might want to re-think your workflow, but to transform a single lat/lon point to projection described by provided proj-string, you could first create the point (note the order: X (longitude, easting), Y (latitude, northing)), convert it to something that's aware of CRS (like sfc), transform to target CRS and extract coordinates:
library(sf)
#> Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
st_point(c(-158.844437, 18.241755)) |>
st_sfc(crs = "WGS84") |>
st_transform("+proj=lcc +lat_0=42.5 +lon_0=-100 +lat_1=25 +lat_2=60 +x_0=0 +y_0=0 +ellps=WGS84 +units=m +no_defs") |>
st_coordinates()
#> X Y
#> [1,] -5954329 -453417
Again, make sure you handle latitude / longitude and X / Y in the correct order when you deal with coordinates; you often need to swap those when moving between geographic coordinates (usually lat/lon) and projected coordinates (usually X,Y).
<sup>Created on 2023-08-10 with reprex v2.0.2</sup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论