【GDAL】聊聊GDAL的数据模型
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的数据模型的更多相关文章
- 【GDAL】GDAL栅格数据结构学习笔记(一): 关于Metadata
在维护一段代码时看到前任程序员写的获取栅格数据的CellSize的功能,竟然在知道GDAL的情况下去调用AE的接口来解算,觉得费解. 原来的思路是使用AE的Raster对象读取出Raster的文件大小 ...
- 【GDAL】聊聊GDAL的数据模型(二)——Band对象
在GDAL中栅格数据直接参与各种计算的重要对象是Band 摘录官方描述: Raster Band A raster band is represented in GDAL with the GDALR ...
- 利用GDAL进行工具开源化改造
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 为利于项目实施,团队用AE写过一个插件式的工具集,主要包括了数 ...
- GDAL生成Erdas Imagine
GDAL原生支持超过100种栅格数据类型,涵盖所有主流GIS与RS数据格式,包括• ArcInfo grids, ArcSDE raster, Imagine, Idrisi, ENVI, GRAS ...
- [GDAL]读取HDF格式的calipso数据
探测地球云层分布的CloudSat和CALIPSO卫星 http://www.nasa.gov/mission_pages/calipso/main/index.html http://www.nas ...
- 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 ...
- GDAL编译(转)
一.简单的编译 1.使用VisualStudio IDE编译 首先进入GDAL的源代码目录,可以看到有几个sln为后缀的文件名,比如makegdal10.sln,makegdal80.sln,make ...
- GDAL的安装和配置(编译proj.4)
1.下载地址 http://trac.osgeo.org/gdal/wiki/DownloadSource 下面是两个版本: http://pan.baidu.com/s/1bntuXER (1.1 ...
- GDAL的RASTERIO功能
为了能快速的显示大影像,最近一直在学习GDAL,GDAL确实是一个功能强大的开源库,其核心部分数据集和波段,下面这个图很详细的描述了它们之间的关系,还有其中的细节: GDAL ...
随机推荐
- Vue CLI UI:Vue开发者必不可少的工具
突然发现一个Vue cli 比较好用的工具,一个可视化图形界面方便你去创建.更新和管理Vue项目.这里分享2个作者写得比较好的文章 https://codeseeding.com/portal.php ...
- Phone-java标准类
//project-module-package //.代表包的目录层次 package cn.learn.day01.demo01; /* 1.类是一组相关属性(成员变量)与行为(方法)的集合,对象 ...
- MyEclipse下Junit报错"The input type of the launch configuration"
MyEclipse下Junit运行测试用例的时候报错: "The input type of the launch configuration does not exist" 原因 ...
- [已解决]报错: Windows下Redis服务无法启动,错误 1067 进程意外终止解决方案
启动redis时出现的报错内容: 解决方法: 找到登录状态 如果是网络服务,直接双击此服务,修改为本地系统服务即可启动!
- [洛谷P1552] [APIO2012]派遣(左偏树)
这道题是我做的左偏树的入门题,奈何还是看了zsy大佬的题解才能过,唉,我太弱了. 左偏树总结 Part 1 理解题目 很显然,通过管理关系的不断连边,最后连出来的肯定是一棵树,那么不难得出,当一个忍者 ...
- StatusStrip 分类: C# 2015-07-23 11:58 2人阅读 评论(0) 收藏
通过StatusStrip显示窗体状态栏 同时将状态栏分成三部分 居左边显示相关文字信息 中间空白显示 居右边显示时间信息 1.创建窗体及添加StatusStrip 默认StatusStrip名称 ...
- VS code 生成html模板快捷键
第一步:在空html文档中输入 ! 第二步:按下tab键.
- 【转载】windows 开启 nginx 监听80 端口 以及 禁用 http 服务后,无法重启 HTTP 服务,提示 系统错误 123,文件目录、卷标出错
https://www.cnblogs.com/TianyuSu/p/9509873.html location / { proxy_set_header Host $Host; proxy_set_ ...
- 一、WebApi模型验证实践项目使用
一.启语 前面我们说到,模型验证的原理(包含1.项目创建,2.模型创建,3.走通测试模型验证,4.在过滤器中处理返回json格式(非控制器内))-完全是新手理解使用的,新番理解 通常情况下,对于那些经 ...
- Kvm --01 虚拟化基础概念
目录 1. 虚拟化基础概念 01. 什么是虚拟化? 02. 为什么要用虚拟化? 03. 虚拟化在企业中的应用场景? 04. 虚拟化软件介绍 05. Kvm介绍 2. 安装部署Kvm 3. Kvm虚拟机 ...