将 geotiff 转换为 netcdf 时值会发生变化

如何解决将 geotiff 转换为 netcdf 时值会发生变化

我有一个 geotiff,它的值从 0 到 200,nodata 值为 255。 我在 python 中使用 gdal 将其转换为 netcdf:

ds = gdal.Translate(outputfile,inputfile,format='NetCDF')

[按照 Val 的建议,我尝试添加 outputType=gdal.gdalconst.GDT_Byte,noData=255 但它也没有解决]

现在 netcdf 中的所有 0 和 nodata 值都是 0。但主要问题是其他值现在范围从 127 到 -128。 tif 中的最高值现在最低(即负值),最低值现在是最正值。

这是来自数据层上的 netcdf 的信息

<class 'netCDF4._netCDF4.Variable'>
int8 Band1(y,x)
    long_name: GDAL Band Number 1
    _Unsigned: true
    valid_range: [  0 255]
    _FillValue: 0
    grid_mapping: polar_stereographic
unlimited dimensions: 
current shape = (752,752)
filling on

这是 netcdf 的 gdal.Info:

Driver: netCDF/Network Common Data Format
Files: /Users/clip_asi-AMSR2-s3125-20200305-v5.4.nc
Size is 117,163
Coordinate System is:
PROJCRS["IDL GeoTIFF Suport
Projection = Polar Stereographic
True scale:      -70.0000deg
Gunnar Spreen,Apr 2004",BASEGEOGCRS["WGS 84",DATUM["World Geodetic System 1984",ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]]],PRIMEM["Greenwich",ANGLEUNIT["degree",0.0174532925199433]],ID["EPSG",4326]],CONVERSION["unnamed",METHOD["Polar Stereographic (variant B)",9829]],PARAMETER["Latitude of standard parallel",-70,0.0174532925199433],8832]],PARAMETER["Longitude of origin",8833]],PARAMETER["False easting",1],8806]],PARAMETER["False northing",8807]]],CS[Cartesian,2],AXIS["easting",north,ORDER[1],1]],AXIS["northing",ORDER[2],1]]]
Data axis to CRS axis mapping: 1,2
Origin = (-1810937.500000000000000,-554687.500000000000000)
Pixel Size = (3125.000000000000000,-3125.000000000000000)
Metadata:
  Band1#grid_mapping=polar_stereographic
  Band1#long_name=GDAL Band Number 1
  Band1#valid_range={0,255}
  Band1#_FillValue=-1
  Band1#_Unsigned=true
  NC_GLOBAL#Conventions=CF-1.5
  NC_GLOBAL#GDAL=GDAL 3.0.2,released 2019/10/28
  NC_GLOBAL#GDAL_AREA_OR_POINT=Area
  NC_GLOBAL#GDAL_TIFFTAG_DATETIME=2020:03:06 05:10:59
  NC_GLOBAL#GDAL_TIFFTAG_DOCUMENTNAME=/ssmi/www/htdocs/data/amsr2/asi_daygrid_swath/s3125/2020/mar/Amundsen/asi-AMSR2-s3125-20200305-v5.4.tif
  NC_GLOBAL#GDAL_TIFFTAG_IMAGEDESCRIPTION=IDL TIFF file
  NC_GLOBAL#GDAL_TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
  NC_GLOBAL#GDAL_TIFFTAG_SOFTWARE=IDL 8.1,ITT Visual Information Solutions
  NC_GLOBAL#GDAL_TIFFTAG_XRESOLUTION=100
  NC_GLOBAL#GDAL_TIFFTAG_YRESOLUTION=100
  NC_GLOBAL#history=Wed Mar 31 18:36:11 2021: GDAL CreateCopy( /Users/gjmacdonald/Downloads/clip_asi-AMSR2-s3125-20200305-v5.4.nc,... )
  polar_stereographic#false_easting=0
  polar_stereographic#false_northing=0
  polar_stereographic#GeoTransform=-1810937.5 3125 0 -554687.5 0 -3125 
  polar_stereographic#grid_mapping_name=polar_stereographic
  polar_stereographic#inverse_flattening=298.257223563
  polar_stereographic#latitude_of_projection_origin=-90
  polar_stereographic#longitude_of_prime_meridian=0
  polar_stereographic#long_name=CRS definition
  polar_stereographic#semi_major_axis=6378137
  polar_stereographic#spatial_ref=PROJCS["IDL GeoTIFF Suport
Projection = Polar Stereographic
True scale:      -70.0000deg
Gunnar Spreen,GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",AUTHORITY["EPSG","7030"]],"6326"]],0],UNIT["degree",0.0174532925199433,"9122"]],"4326"]],PROJECTION["Polar_Stereographic"],PARAMETER["latitude_of_origin",-70],PARAMETER["central_meridian",PARAMETER["false_easting",PARAMETER["false_northing",UNIT["metre",AXIS["Easting",NORTH],AXIS["Northing",NORTH]]
  polar_stereographic#standard_parallel=-70
  polar_stereographic#straight_vertical_longitude_from_pole=0
  x#long_name=x coordinate of projection
  x#standard_name=projection_x_coordinate
  x#units=m
  y#long_name=y coordinate of projection
  y#standard_name=projection_y_coordinate
  y#units=m
Corner Coordinates:
Upper Left  (-1810937.500,-554687.500) (107d 1'47.10"W,72d38'40.82"S)
Lower Left  (-1810937.500,-1064062.500) (120d26'14.82"W,70d47' 7.34"S)
Upper Right (-1445312.500,-554687.500) (110d59'45.57"W,75d46'46.47"S)
Lower Right (-1445312.500,-1064062.500) (126d21'39.97"W,73d32'29.83"S)
Center      (-1628125.000,-809375.000) (116d25'58.56"W,73d19'46.09"S)
Band 1 Block=117x1 Type=Byte,ColorInterp=Undefined
  NoData Value=255
  Metadata:
    grid_mapping=polar_stereographic
    long_name=GDAL Band Number 1
    NETCDF_VARNAME=Band1
    valid_range={0,255}
    _FillValue=-1
    _Unsigned=true

以及转换后的 Tif 的 gdal.Info(在答案中添加 Val 的建议之后)

Driver: GTiff/GeoTIFF
Files: /Users/clip_asi-AMSR2-s3125-20200305-v5.4.tif
Size is 117,-3125.000000000000000)
Metadata:
  AREA_OR_POINT=Area
  TIFFTAG_DATETIME=2020:03:06 05:10:59
  TIFFTAG_DOCUMENTNAME=/ssmi/www/htdocs/data/amsr2/asi_daygrid_swath/s3125/2020/mar/Amundsen/asi-AMSR2-s3125-20200305-v5.4.tif
  TIFFTAG_IMAGEDESCRIPTION=IDL TIFF file
  TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
  TIFFTAG_SOFTWARE=IDL 8.1,ITT Visual Information Solutions
  TIFFTAG_XRESOLUTION=100
  TIFFTAG_YRESOLUTION=100
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (-1810937.500,73d19'46.09"S)
Band 1 Block=117x70 Type=Byte,ColorInterp=Palette
  NoData Value=255
  Color Table (RGB with 256 entries)
    0: 0,138,255
    1: 0,255
    2: 0,255
    3: 0,255
    4: 0,255
    5: 0,255
    6: 0,255
    7: 0,255
    8: 0,255
    9: 0,255
   10: 0,255
   11: 0,255
   12: 0,255
   13: 0,255
   14: 0,255
   15: 0,255
   16: 0,255
   17: 0,255
   18: 0,255
   19: 0,255
   20: 29,143,254,255
   21: 29,255
   22: 29,255
   23: 29,255
   24: 29,255
   25: 29,255
   26: 29,255
   27: 29,255
   28: 29,255
   29: 29,255
   30: 29,255
   31: 29,255
   32: 29,255
   33: 29,255
   34: 29,255
   35: 29,255
   36: 29,255
   37: 29,255
   38: 29,255
   39: 29,255
   40: 29,249,159,255
   41: 29,255
   42: 29,255
   43: 29,255
   44: 29,255
   45: 29,255
   46: 29,255
   47: 29,255
   48: 29,255
   49: 29,255
   50: 29,255
   51: 29,255
   52: 29,255
   53: 29,255
   54: 29,255
   55: 29,255
   56: 29,255
   57: 29,255
   58: 29,255
   59: 29,255
   60: 33,33,255
   61: 33,255
   62: 33,255
   63: 33,255
   64: 33,255
   65: 33,255
   66: 33,255
   67: 33,255
   68: 33,255
   69: 33,255
   70: 33,255
   71: 33,255
   72: 33,255
   73: 33,255
   74: 33,255
   75: 33,255
   76: 33,255
   77: 33,255
   78: 33,255
   79: 33,255
   80: 0,255
   81: 0,255
   82: 0,255
   83: 0,255
   84: 0,255
   85: 0,255
   86: 0,255
   87: 0,255
   88: 0,255
   89: 0,255
   90: 0,255
   91: 0,255
   92: 0,255
   93: 0,255
   94: 0,255
   95: 0,255
   96: 0,255
   97: 0,255
   98: 0,255
   99: 0,255
  100: 124,255
  101: 124,255
  102: 124,255
  103: 124,255
  104: 124,255
  105: 124,255
  106: 124,255
  107: 124,255
  108: 124,255
  109: 124,255
  110: 124,255
  111: 124,255
  112: 124,255
  113: 124,255
  114: 124,255
  115: 124,255
  116: 124,255
  117: 124,255
  118: 124,255
  119: 124,255
  120: 172,46,255
  121: 172,255
  122: 172,255
  123: 172,255
  124: 172,255
  125: 172,255
  126: 172,255
  127: 172,255
  128: 172,255
  129: 172,255
  130: 172,255
  131: 172,255
  132: 172,255
  133: 172,255
  134: 172,255
  135: 172,255
  136: 172,255
  137: 172,255
  138: 172,255
  139: 172,255
  140: 249,255
  141: 249,255
  142: 249,255
  143: 249,255
  144: 249,255
  145: 249,255
  146: 249,255
  147: 249,255
  148: 249,255
  149: 249,255
  150: 249,255
  151: 249,255
  152: 249,255
  153: 249,255
  154: 249,255
  155: 249,255
  156: 249,255
  157: 249,255
  158: 249,255
  159: 249,255
  160: 249,124,255
  161: 249,255
  162: 249,255
  163: 249,255
  164: 249,255
  165: 249,255
  166: 249,255
  167: 249,255
  168: 249,255
  169: 249,255
  170: 249,255
  171: 249,255
  172: 249,255
  173: 249,255
  174: 249,255
  175: 249,255
  176: 249,255
  177: 249,255
  178: 249,255
  179: 249,255
  180: 185,84,210,255
  181: 185,255
  182: 185,255
  183: 185,255
  184: 185,255
  185: 185,255
  186: 185,255
  187: 185,255
  188: 185,255
  189: 185,255
  190: 147,255
  191: 147,255
  192: 147,255
  193: 147,255
  194: 147,255
  195: 147,255
  196: 147,255
  197: 147,255
  198: 147,255
  199: 119,89,255
  200: 119,255
  201: 0,255
  202: 0,255
  203: 0,255
  204: 0,255
  205: 0,255
  206: 0,255
  207: 0,255
  208: 0,255
  209: 0,255
  210: 0,255
  211: 0,255
  212: 0,255
  213: 0,255
  214: 0,255
  215: 0,255
  216: 0,255
  217: 0,255
  218: 0,255
  219: 0,255
  220: 0,255
  221: 0,255
  222: 0,255
  223: 0,255
  224: 0,255
  225: 0,255
  226: 0,255
  227: 0,255
  228: 0,255
  229: 0,255
  230: 0,255
  231: 0,255
  232: 0,255
  233: 0,255
  234: 0,255
  235: 0,255
  236: 0,255
  237: 0,255
  238: 0,255
  239: 0,255
  240: 0,255
  241: 0,255
  242: 0,255
  243: 0,255
  244: 0,255
  245: 0,255
  246: 0,255
  247: 0,255
  248: 0,255
  249: 0,255
  250: 0,255
  251: 99,99,255
  252: 0,255
  253: 0,255
  254: 0,255
  255: 0,0

Tif 文件: https://drive.google.com/file/d/1y5UGAteXUOzGaqWsuFc7DXi8XTzGMVJ_/view?usp=sharing 转换后的 nc 文件:https://drive.google.com/file/d/1CjZJ9pRcLJomHMkTjatkXHTKx4zQ6ehl/view?usp=sharing

解决方法

看起来您正在将输入数据转换为最有可能的 uint8int8,因此高于数据类型最大“溢出”的值进入负侧。您需要专门将数据类型设置为 Byte(在 uint8 行话中是 gdal)。

您可以通过添加 outputType 选项关键字参数来解决此问题。此外,您可以使用 noData 选项设置所需的无数据值。

这是具有正确数据类型和无数据值为 255 的完整调用:

gdal.Translate(outputfile,inputfile,format='NetCDF',outputType=gdal.gdalconst.GDT_Byte,noData=255)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-