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

  • 相关阅读:
    lombok工作原理分析
    jsqlparser和calcite和druid功能对比
    mysql主从备份及常见问题处理
    keepalived结合nginx实现nginx高可用
    FastDFS教程IV-文件服务器集群搭建
    FastDFS教程Ⅲ-文件服务器扩容
    fastDFS教程Ⅱ-文件服务器迁移
    FastDFS教程Ⅰ-文件服务器安装与Nginx配置
    Cognos报表调度与作业管理
    Cognos 11.0快速开发指南 Ⅱ
  • 原文地址:https://www.cnblogs.com/lanzhi/p/6470215.html
Copyright © 2011-2022 走看看