zoukankan      html  css  js  c++  java
  • 有点坑爹的GDALComputeRasterMinMax函数

    作者:朱金灿

    来源:http://blog.csdn.net/clever101

        

            GDALComputeRasterMinMax函数是gdal库为了求取指定波段的极值而提供的接口。最近看了这个接口的源码,发现这个接口有点坑爹。GDALComputeRasterMinMax实际上是调用GDALRasterBand类的virtual double GetMinimum( int *pbSuccess = NULL )virtual double GetMaximum(int *pbSuccess = NULL );两个接口。我们看看GDALRasterBand::GetMinimum函数的实现:


    double GDALRasterBand::GetMinimum( int *pbSuccess )
    
    {
        const char *pszValue = NULL;
        
        if( (pszValue = GetMetadataItem("STATISTICS_MINIMUM")) != NULL )
        {
            if( pbSuccess != NULL )
                *pbSuccess = TRUE;
            
            return CPLAtofM(pszValue);
        }
    
        if( pbSuccess != NULL )
            *pbSuccess = FALSE;
    
        switch( eDataType )
        {
          case GDT_Byte:
          {
            const char* pszPixelType = GetMetadataItem("PIXELTYPE", "IMAGE_STRUCTURE");
            if (pszPixelType != NULL && EQUAL(pszPixelType, "SIGNEDBYTE"))
                return -128;
            else
                return 0;
          }
    
          case GDT_UInt16:
            return 0;
    
          case GDT_Int16:
            return -32768;
    
          case GDT_Int32:
            return -2147483648.0;
    
          case GDT_UInt32:
            return 0;
    
          case GDT_Float32:
            return -4294967295.0; /* not actually accurate */
    
          case GDT_Float64:
            return -4294967295.0; /* not actually accurate */
    
          default:
            return -4294967295.0; /* not actually accurate */
        }
    }

        这段函数的意义是什么呢?就是说首先从元数据文件(一般是xml文件)中查找是否有最小值记录,如果有就取出来返回;如果没有就把波段类型的值域的最小值返回。这样做就有点坑爹了,因为求取的极值并非来自统计图像而来,就是说除非派生自GDALRasterBand类的波段类重写了GetMinimumGetMaximum两个接口,否则求取的极值基本上是不准确的。我查了一下,geotiff的波段类都没重写这两个接口。因此GDALComputeRasterMinMax这个接口应该慎用。

  • 相关阅读:
    nodejs 不支持 typescript (...paramName:any[])剩余参数。变相支持方式。
    centos7安装nodejs
    .Net Core Linux centos7行—jenkins linux 构建.net core web app
    asp.net core 编译mvc,routing,security源代码进行本地调试
    发现一个很N且免费的html5拓扑图 关系图 生成组件
    Quill编辑器介绍及扩展
    vs2017 rc 离线安装包制作
    单体架构风格
    GlusterFS 安装 on centos7
    Expect 安装 on centos7
  • 原文地址:https://www.cnblogs.com/lanzhi/p/6470215.html
Copyright © 2011-2022 走看看