GDAL是个非常优秀的GIS数据操作库,最近在和实习生介绍GDAL的简单使用,顺手写下记录

本篇记录栅格数据,代码环境为C#

在GDAL中,栅格数据大致是以一个Dataset对应一个栅格数据文件(.Tif/GeoTiff格式),而这个栅格中的各种信息被包含在Dataset的对象中作为属性。

基本上一个栅格数据在GDAL的数据模型中存储是基于波段的方式,一般一个单波段数据在GDAL中读取后,所得到的Dataset中仅包含一个Band对象,而BandCount属性也为1.多波段数据类似,即是说在GDAL里的Dataset对象与在ArcGIS里所谈的栅格数据集是类似的概念。

这里以官方文档为准搬运相关的概念和说明。

Dataset

A dataset (represented by the GDALDataset class) is an assembly of related raster bands and some information common to them all. In particular the dataset has a concept of the raster size (in pixels and lines) that applies to all the bands. The dataset is also responsible for the georeferencing transform and coordinate system definition of all bands. The dataset itself can also have associated metadata, a list of name/value pairs in string form.

Note that the GDAL dataset, and raster band data model is loosely based on the OpenGIS Grid Coverages specification.

其中标红的部分是在具体的栅格数据处理中我们应该关注的内容,包括数据的大小(图像的长宽),地理参考和坐标系定义, 数据的元数据等。这些项目在Dataset对象中定义,对所有这个Dataset下的Band有效。

接下来首先讨论Dataset中包含的基本内容。

非常重要的是数据的投影和地理参考。

数据的坐标系【Coordinate System】

GDAL的坐标系定义采用OpenGIS的投影字符串规范表示,所以当你使用 Dataset.GetProjection()方法时会发现返回值为一个字符串而不是什么Projection对象。这保证在大部分情况下数据的投影文件(信息)能够被GDAL读取并正确解释。这个坐标系定义中包含以下内容:

  • An overall coordinate system name.
  • A geographic coordinate system name.
  • A datum identifier.
  • An ellipsoid name, semi-major axis, and inverse flattening.
  • A prime meridian name and offset from Greenwich.
  • A projection method type (i.e. Transverse Mercator).
  • A list of projection parameters (i.e. central_meridian).
  • A units name, and conversion factor to meters or radians.
  • Names and ordering for the axes.
  • Codes for most of the above in terms of predefined coordinate systems from authorities such as EPSG.

这里感觉需要提一下的就是在调用一些GDAL的投影转换方法时,要求的参数可能写作“WKT”,熟悉OpenGIS的会知道这是OpenGIS WKT coordiante System Definitions,也就是这里的投影字符串。

个人感觉稍微有用一些的Tips是最近同事提醒的,原来用于判定两个数据是否同一个坐标系统我是直接采用Dataset.GetProjection()对得到的字符串做Equals判断,这样并不严谨。原因自然是某些软件读取了数据之后会将其WKT坐标系定义(此处存疑)修改为其他标准的坐标系定义,所以更建议使用GDAL中的OGR库的SpatialReference对象进行判定。

代码示例如下(暂时没学会怎么插入代码段,先截图了)

因为GDAL是C++的库,所以习惯各方面保持C++的风格,比如条件判断基本是以01方式做,需要习惯下。

转换参数【 GeoTransform】

这个参数一般可以被叫做6参数,因为其对象是个double[6]数组。这个参数用于标定数据的地理位置等信息,相关的方法是 Dataset.GetGeoTransform(out double[] args)、 Dataset.SetGeoTransform(double[] args)

GDAL datasets have two ways of describing the relationship between raster positions (in pixel/line coordinates) and georeferenced coordinates. The first, and most commonly used is the affine transform (the other is GCPs).

关于六参数的具体解释将在另外的文章中解释。

一个真实地理坐标和影像数据行列的转换关系如下:

Xgeo = GT(0) + Xpixel*GT(1) + Yline*GT(2)
    Ygeo = GT(3) + Xpixel*GT(4) + Yline*GT(5)

【GCPs】

关于GCPs了解不多,这里暂时搬运官方解释

A dataset can have a set of control points relating one or more positions on the raster to georeferenced coordinates. All GCPs share a georeferencing coordinate system (returned by GDALDataset::GetGCPProjection()). Each GCP (represented as the GDAL_GCP class) contains the following:

typedef struct
{
char *pszId;
char *pszInfo;
double dfGCPPixel;
double dfGCPLine;
double dfGCPX;
double dfGCPY;
double dfGCPZ;
} GDAL_GCP;

元数据【Metadata】

这个部分请参阅前一篇博客,关于GDAL的Metadata

栅格波段 【Raster Band】

波段对象(Raster Band)是GDAL中的重要对象。一个Band对象表示一个波段/通道/图层,因此一个RGB数据在GDAL的模型中实际上是一个包含3个波段的Dataset,其中波段与Red/Green/Blue分别对应。

关于波段的内容同样将在另一篇博客中详细解释。

【Color Table】

这个几乎没用过,直接搬运了。

先看结构定义:

A color table consists of zero or more color entries described in C by the following structure:

 typedef struct
{
/- gray, red, cyan or hue -/
short c1;
/- green, magenta, or lightness -/
short c2;
/- blue, yellow, or saturation -/
short c3;
/- alpha or black band -/
short c4;
} GDALColorEntry;

The color table also has a palette interpretation value (GDALPaletteInterp) which is one of the following values, and indicates how the c1/c2/c3/c4 values of a color entry should be interpreted.

  • GPI_Gray: Use c1 as gray scale value.
  • GPI_RGB: Use c1 as red, c2 as green, c3 as blue and c4 as alpha.
  • GPI_CMYK: Use c1 as cyan, c2 as magenta, c3 as yellow and c4 as black.
  • GPI_HLS: Use c1 as hue, c2 as lightness, and c3 as saturation.

To associate a color with a raster pixel, the pixel value is used as a subscript into the color table. That means that the colors are always applied starting at zero and ascending. There is no provision for indicating a pre-scaling mechanism before looking up in the color table.

【Overviews】

根据官方说明,这个是波段的缩略图。

A band may have zero or more overviews. Each overview is represented as a "free standing" GDALRasterBand. The size (in pixels and lines) of the overview will be different than the underlying raster, but the geographic region covered by overviews is the same as the full resolution band.

The overviews are used to display reduced resolution overviews more quickly than could be done by reading all the full resolution data and downsampling.

Bands also have a HasArbitraryOverviews property which is TRUE if the raster can be read at any resolution efficiently but with no distinct overview levels. This applies to some FFT encoded images, or images pulled through gateways (like OGDI) where downsampling can be done efficiently at the remote point.

关于最后两个对象,后期研究一下再来补充。

感谢观看

【GDAL】聊聊GDAL的数据模型的更多相关文章

  1. 【GDAL】GDAL栅格数据结构学习笔记(一): 关于Metadata

    在维护一段代码时看到前任程序员写的获取栅格数据的CellSize的功能,竟然在知道GDAL的情况下去调用AE的接口来解算,觉得费解. 原来的思路是使用AE的Raster对象读取出Raster的文件大小 ...

  2. 【GDAL】聊聊GDAL的数据模型(二)——Band对象

    在GDAL中栅格数据直接参与各种计算的重要对象是Band 摘录官方描述: Raster Band A raster band is represented in GDAL with the GDALR ...

  3. 利用GDAL进行工具开源化改造

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 为利于项目实施,团队用AE写过一个插件式的工具集,主要包括了数 ...

  4. GDAL生成Erdas Imagine

    GDAL原生支持超过100种栅格数据类型,涵盖所有主流GIS与RS数据格式,包括•  ArcInfo grids, ArcSDE raster, Imagine, Idrisi, ENVI, GRAS ...

  5. [GDAL]读取HDF格式的calipso数据

    探测地球云层分布的CloudSat和CALIPSO卫星 http://www.nasa.gov/mission_pages/calipso/main/index.html http://www.nas ...

  6. GDAL Configure in Visual Studio 2010 for Win7/ GDAL+VisualStudio2010 Win7 配置

    配置环境: OS:Win& *86 Ultimate Edition(EN) VS:Visual Studio 2010(EN) Step1: GDAL源码下载:http://www.gisi ...

  7. GDAL编译(转)

    一.简单的编译 1.使用VisualStudio IDE编译 首先进入GDAL的源代码目录,可以看到有几个sln为后缀的文件名,比如makegdal10.sln,makegdal80.sln,make ...

  8. GDAL的安装和配置(编译proj.4)

    1.下载地址 http://trac.osgeo.org/gdal/wiki/DownloadSource 下面是两个版本: http://pan.baidu.com/s/1bntuXER  (1.1 ...

  9. GDAL的RASTERIO功能

             为了能快速的显示大影像,最近一直在学习GDAL,GDAL确实是一个功能强大的开源库,其核心部分数据集和波段,下面这个图很详细的描述了它们之间的关系,还有其中的细节:     GDAL ...

随机推荐

  1. 解决bug:sprongboot2整合shiro,swagger2页面样式加载不出来问题

    问题如题: 解决思路,把shiro拦截去掉之后发现swagger-ui.html页面接在的资源如下: 因此可以推断拦截器拦截了 "/swagger-resources" " ...

  2. mybatis插件机制及分页插件原理

    MyBatis 插件原理与自定义插件: MyBatis 通过提供插件机制,让我们可以根据自己的需要去增强MyBatis 的功能.需要注意的是,如果没有完全理解MyBatis 的运行原理和插件的工作方式 ...

  3. meta标签viewport的深入理解(转)

    移动前端开发之viewport的深入理解 在移动设备上进行网页的重构或开发,首先得搞明白的就是移动设备上的viewport了,只有明白了viewport的概念以及弄清楚了跟viewport有关的met ...

  4. 断路器,AOP实现断路器模式 ------------Hystrix

    断路器:https://martinfowler.com/bliki/CircutiBreaker.html 核心思想: 在断路器对象中封装受保护的方法调用. 该断路器监控调用和断路情况 调用失败触发 ...

  5. [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)

    [Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...

  6. Warning: session_start(): open(/var/lib/php/session/)

    Warning: session_start(): open(/var/lib/php/session/) 今天放置一个新的站点www.96net.com.cn在里面,登陆后台出现这种错,之后再lin ...

  7. 最简单的神经网络-感知器-python实现

    import numpy as np import matplotlib.pyplot as plt X=np.array([[1,3,3], [1,4,3], [1,1,1]]) Y=np.arra ...

  8. elasticsearch 基础 —— 集群原理

    空集群 如果我们启动了一个单独的节点,里面不包含任何的数据和 索引,那我们的集群看起来就是一个 图 1 "包含空内容节点的集群". 图 1. 包含空内容节点的集群 一个运行中的 E ...

  9. rdev - 查询/设置内核映像文件的根设备,RAM 磁盘大小或视频模式

    总览 SYNOPSIS rdev [ -rvh ] [ -o offset ] [ image [ value [ offset ] ] ] rdev [ -o offset ] [ image [ ...

  10. 12-低延迟、全接口(HMDI、DVI、YPb Pr、RGB)H.264全高清编码器解码器

    低延迟.全接口(HMDI.DVI.YPb Pr.RGB)H.264全高清编码器解码器 一.产品介绍  1.近零延时的H.264压缩到1920x1080p60  该产品提供分辨率为1920x1080p6 ...