在 R 中从 netCDF 文件创建光栅块时 crs 投影信息出现问题
我正在处理存储在 netCDF 文件中的瑞士气象数据。示例数据可在此处。
下载并读取数据后,
download.file(url = "https://www.meteoswiss.admin.ch/content/dam/meteoswiss/de/Ungebundene-Seiten/Produkte/doc/tnorm9120.zip")
unzip("tnorm9120.zip")
filename <- "TnormM9120_ch01r.swiss.lv95_000001010000_000012010000.nc"
tnorm9120 <- nc_open(filename)
tnorm9120
我有以下形式的文件:
File data-raw/tnorm9120/TnormM9120_ch01r.swiss.lv95_000001010000_000012010000.nc (NC_FORMAT_CLASSIC):
5 variables (excluding dimension variables):
float swiss_lv95_coordinates[]
_FillValue: -1
grid_mapping_name: Oblique Mercator (LV95 - CH1903+)
longitude_of_projection_center: 7.43958333
latitude_of_projection_center: 46.9524056
false_easting: 2600000
false_northing: 1200000
inverse_flattening: 299.1528128
semi_major_axis: 6377397.155
double climatology_bounds[ncb,time]
units: months since 1991-01-01 00:00:00
_FillValue: -1
float TnormM9120[E,N,time]
units: degree
_FillValue: -999.989990234375
grid_mapping: swiss_lv95_coordinates
coordinates: lon lat
long_name: mean monthly temperature 1991-2020
grid_name: ch01r.swiss.lv95
version: v1.4
prod_date: 2021-09-30 17:40:40
cell_methods: time: mean within years time: mean over years
float lon[E,N]
units: degrees_east
_FillValue: NaN
long_name: longitude coordinate
standard_name: longitude
float lat[E,N]
units: degrees_north
_FillValue: NaN
long_name: latitude coordinate
standard_name: latitude
4 dimensions:
ncb Size:2
long_name: ncb
time Size:12 *** is unlimited ***
units: months since 1991-01-01 00:00:00
long_name: time
axis: T
calendar: standard
climatology: climatology_bounds
E Size:370
units: meters_east
long_name: swiss easting (lv95)
standard_name: projection x coordinate
N Size:240
units: meters_north
long_name: swiss northing (lv95)
standard_name: projection y coordinate
3 global attributes:
Conventions: CF-1.6
institution: Federal Office of Meteorology and Climatology MeteoSwiss
References: Frei C., 2014: Interpolation of temperatures in a mountainous region using nonlinear profiles and non-Euclidean distances. Int. J. Climatol., 34, 1585-1605. DOI: 10.1002/joc.3786.
我试图设置坐标系(应该是 EPSG: 2056)在光栅砖上使用:
b <- brick(filename, crs = st_crs(2056)$proj4string)
但是,这给了我以下警告:
Warning messages:
1: In .getCRSfromGridMap4(atts) : cannot process these parts of the crs:
_FillValue=-1
longitude_of_projection_center=7.43958333
latitude_of_projection_center=46.9524056
2: In .getCRSfromGridMap4(atts) : cannot create a valid crs
grid_mapping_name; false_easting; false_northing; scale_factor_at_projection_origin; scale_factor_at_central_meridian; standard_parallel; standard_parallel1; standard_parallel2; longitude_of_central_meridian; longitude_of_projection_origin; latitude_of_projection_origin; straight_vertical_longitude_from_pole; longitude_of_prime_meridian; semi_major_axis; semi_minor_axis; inverse_flattening; earth_radius; +proj; +x_0; +y_0; +k_0; +k_0; +lat_1; +lat_1; +lat_2; +lon_0; +lon_0; +lat_0; +lon_0; +pm; +a; +b; +rf; +a
我尝试了其他设置 CRS 的方法,但这要么导致错误,要么导致与上面相同的警告。有什么办法解决吗?
更新:替代尝试记录在此要点中。
奇怪的是,当我尝试在 QGIS 中绘制这些数据时,我最终发现国家颠倒了 o_O
I'm working with Swiss meteo data stored in netCDF files. Example data are available here.
After downloading and reading the data
download.file(url = "https://www.meteoswiss.admin.ch/content/dam/meteoswiss/de/Ungebundene-Seiten/Produkte/doc/tnorm9120.zip")
unzip("tnorm9120.zip")
filename <- "TnormM9120_ch01r.swiss.lv95_000001010000_000012010000.nc"
tnorm9120 <- nc_open(filename)
tnorm9120
I have file of this form:
File data-raw/tnorm9120/TnormM9120_ch01r.swiss.lv95_000001010000_000012010000.nc (NC_FORMAT_CLASSIC):
5 variables (excluding dimension variables):
float swiss_lv95_coordinates[]
_FillValue: -1
grid_mapping_name: Oblique Mercator (LV95 - CH1903+)
longitude_of_projection_center: 7.43958333
latitude_of_projection_center: 46.9524056
false_easting: 2600000
false_northing: 1200000
inverse_flattening: 299.1528128
semi_major_axis: 6377397.155
double climatology_bounds[ncb,time]
units: months since 1991-01-01 00:00:00
_FillValue: -1
float TnormM9120[E,N,time]
units: degree
_FillValue: -999.989990234375
grid_mapping: swiss_lv95_coordinates
coordinates: lon lat
long_name: mean monthly temperature 1991-2020
grid_name: ch01r.swiss.lv95
version: v1.4
prod_date: 2021-09-30 17:40:40
cell_methods: time: mean within years time: mean over years
float lon[E,N]
units: degrees_east
_FillValue: NaN
long_name: longitude coordinate
standard_name: longitude
float lat[E,N]
units: degrees_north
_FillValue: NaN
long_name: latitude coordinate
standard_name: latitude
4 dimensions:
ncb Size:2
long_name: ncb
time Size:12 *** is unlimited ***
units: months since 1991-01-01 00:00:00
long_name: time
axis: T
calendar: standard
climatology: climatology_bounds
E Size:370
units: meters_east
long_name: swiss easting (lv95)
standard_name: projection x coordinate
N Size:240
units: meters_north
long_name: swiss northing (lv95)
standard_name: projection y coordinate
3 global attributes:
Conventions: CF-1.6
institution: Federal Office of Meteorology and Climatology MeteoSwiss
References: Frei C., 2014: Interpolation of temperatures in a mountainous region using nonlinear profiles and non-Euclidean distances. Int. J. Climatol., 34, 1585-1605. DOI: 10.1002/joc.3786.
I was trying to set up the coordinate system (which should be EPSG:2056) on the raster brick using:
b <- brick(filename, crs = st_crs(2056)$proj4string)
However that gives me the following warnings:
Warning messages:
1: In .getCRSfromGridMap4(atts) : cannot process these parts of the crs:
_FillValue=-1
longitude_of_projection_center=7.43958333
latitude_of_projection_center=46.9524056
2: In .getCRSfromGridMap4(atts) : cannot create a valid crs
grid_mapping_name; false_easting; false_northing; scale_factor_at_projection_origin; scale_factor_at_central_meridian; standard_parallel; standard_parallel1; standard_parallel2; longitude_of_central_meridian; longitude_of_projection_origin; latitude_of_projection_origin; straight_vertical_longitude_from_pole; longitude_of_prime_meridian; semi_major_axis; semi_minor_axis; inverse_flattening; earth_radius; +proj; +x_0; +y_0; +k_0; +k_0; +lat_1; +lat_1; +lat_2; +lon_0; +lon_0; +lat_0; +lon_0; +pm; +a; +b; +rf; +a
I tried other ways of setting up CRS but that either resulted in error or the same warnings as above. Is there any way around it?
Update: alternative attempts are documented in this gist.
Odly enough when I tried plotting this data in QGIS I ended up with the country upside down o_O
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们是 MeteoSwiss 这些 NetCDF 文件的作者。如果您可以指导我们如何格式化存储在 NetCDF 网格映射变量中的 crs 信息,请回复我们。我们尝试遵循 CF 约定,它适用于旧的瑞士 (LV03/CH1903) 投影和常规经/纬度。但对于您的应用程序中的新瑞士手表(LV95/CH1903+)来说,它似乎失败了。
我们很乐意发布测试文件,以防您发现 CRS 中出现的问题。
您能否确认您可以读取我们之前 (LV03/ch1903) 文件中存储的 CRS,因为我们从未收到过任何关于这些的投诉:
ftp://ftp.cscs.ch/out/stockli/swisscors/TminM_ch01r.swisscors_201903010000_201903010000.nc
干杯
雷托
We are the authors of these NetCDF files at MeteoSwiss. If you can direct us how to format the crs info stored in the NetCDF grid mapping variable, please get back to us. We tried to follow the CF-convention and it works for the old swiss (LV03/CH1903) projection and regular lon/lat. But it seems to fail for the new swiss (LV95/CH1903+) in your application.
We're happy to post test files in case you find out what goes wrong in the CRS.
Can you confirm that you can read the CRS stored in our previous (LV03/ch1903) files, since we never got any complaint on these:
ftp://ftp.cscs.ch/out/stockli/swisscors/TminM_ch01r.swisscors_201903010000_201903010000.nc
Cheers
Reto