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这个接口应该慎用。

  • 相关阅读:
    rsync安装配置实时同步
    ORA-00392: log 4 of thread 2 is being cleared, operation not allowed
    CentOS 6.4安装配置LNMP服务器(Nginx+PHP+MySQL)
    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
    常见服务端口
    linux客户端传输文件到Windows本地
    windows/Linux主机重启NetBackup服务和后台进程
    linux命令之grep命令
    linux命令之awk命令
    Shiro安全框架
  • 原文地址:https://www.cnblogs.com/lanzhi/p/6470215.html
Copyright © 2011-2022 走看看