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. struts框架的一些注意点

    1.Struts.xml文件中<include file="">标签的运用 用法:此标签引用配置文件,Struts2提供了一个默认的struts.xml文件,当此配置文 ...

  2. Junit测试错误:### Error building SqlSession

    错误代码: org.apache.ibatis.exceptions.PersistenceException: ### Error building SqlSession.### The error ...

  3. 转 router-view 的理解

    主要是构建 SPA (单页应用) 时,方便渲染你指定路由对应的组件.你可以 router-view 当做是一个容器,它渲染的组件是你使用 vue-router 指定的.比如: 视图层: <div ...

  4. .net core 使用RSA获取私钥证书并签名

    RSA在.NET Core的改动 以前我们使用RSA加密主要是使用RSACryptoServiceProvider这个类,在.NET Core中也有这个类,但是这个类并不支持跨平台,所以如果你是用这个 ...

  5. C#面试 笔试题 五

    1.什么是受管制的代码? 答:unsafe:非托管代码.不经过CLR运行. 2.net Remoting 的工作原理是什么? 答:服务器端向客户端发送一个进程编号,一个程序域编号,以确定对象的位置. ...

  6. Linux查看关闭进程

    ps:进程的静态列表(Process status) - PID:进程号,每个进程独一无二的标识符(关闭进程需要使用) - TTY:终端所属,表明进程产生于哪一个终端,对于多用户使用的Linux服务器 ...

  7. activiti 5.22 表结构解析及清空流程运行测试数据

    1.结构设计 1.1.    逻辑结构设计 Activiti使用到的表都是ACT_开头的. ACT_RE_*: 'RE'表示repository(存储),RepositoryService接口所操作的 ...

  8. 天启android5.1系统无法在非1650批次号的rk3288w芯片上启动

    天启android5.1系统无法在非1650批次号的rk3288w芯片上启动 挂掉log,说明在rtc初始化后挂掉 [ ) HIGH! ======== [ [ [ 1.420258] [WLAN_R ...

  9. URAL - 1486 二维字符串HASH

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1486 题意:给定一个n*m的字符矩阵,问你是否存在两个不重合(可以有交集)的正方形矩阵完 ...

  10. rabbitmq必须应答

    当autoAck设置为true时,只要消息被消费者处理,不管成功与否,服务器都会删除该消息, 而当autoAck设置为false时,只有消息被处理,且反馈结果后才会删除 https://www.cnb ...