【发布时间】:2020-01-03 11:34:45
【问题描述】:
关于将 .nc 文件转换为 .tiff 文件时,我遇到了丢失像素地理信息的问题。我知道其他用户也遇到了同样的问题,并试图通过 kotlin 解决,但失败了。我更喜欢使用 R 的解决方案。请参阅此处了解 kotlin 方法 URL:https://gis.stackexchange.com/questions/259700/converting-sentinel-3-data-netcdf-to-geotiff
我下载了免费提供的 ESA Sentinel-3 数据 (URL:https://scihub.copernicus.eu/dhus/#/home)。不幸的是,此数据以 .nc 格式提供,因此我想将其转换为 .tiff 格式。我已经尝试了各种方法,但都失败了。到目前为止我尝试过的:
data_source <- 'D:/user_1/01_test_data/S3A_SL_1_RBT____20180708T093240_20180708T093540_20180709T141944_0179_033_150_2880_LN2_O_NT_003.SEN3/F1_BT_in.nc'
# define path to .nc-file
data_output <- 'D:/user_1/01_test_data/S3A_SL_1_RBT____20180708T093240_20180708T093540_20180709T141944_0179_033_150_2880_LN2_O_NT_003.SEN3/test.tif'
# define path of output .tiff-file
###################################################
# 1.) use gdal_translate via Windows cmd-line in R
# see here URL:https://stackoverflow.com/questions/52046282/convert-netcdf-nc-to-geotiff
system(command = paste('gdal_translate -of GTiff -sds -a_srs epsg:4326', data_source, data_output))
# hand over character string to Windows cmd-line to use gdal_translate
###################################################
# 2.) use the raster-package
# see here URL:https://www.researchgate.net/post/How_to_convert_a_NetCDF4_file_to_GeoTIFF_using_R2
epsg4326 <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
# proj4-code
# URL:https://spatialreference.org/ref/epsg/wgs-84/proj4/
specific_band <- raster(data_source)
crs(specific_band) <- epsg4326
writeRaster(specific_band, filename = data_output)
# both approaches work, i can convert the files from .nc-format into .tiff-format, but i **loose the geoinformation for the pixels** and just get pixel coordinates instead of longlat-values.
我非常感谢任何保留像素地理信息的解决方案!
非常感谢,ExploreR
【问题讨论】:
-
你能提供一个示例文件的链接吗?
-
是的,当然,只需将此数据集的 url 作为示例 URL:scihub.copernicus.eu/dhus/odata/v1/…
-
需要用户名和密码
-
是的,这是正确的,我很抱歉。但是您可以注册欧洲航天局 (ESA) 的哥白尼中心。它是免费的,您可以访问比我所指的更有趣的数据集......甚至还有一个由 J. Schwalb-Willmann 提供的 R 包(getSpatialData),自然在一篇工具箱文章中提到,您可以在其中可以很方便地下载哥白尼数据。网址:github.com/16EAGLE/getSpatialData
标签: r raster tiff netcat ncdf4