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. 1、Laravel 环境配置及安装

    一.开发工具及环境 PHPStorm + phpStudy 最新版 Composer 安装 https://www.phpcomposer.com/ 下载就可以,设置中国镜像 安装完成后 compos ...

  2. 通过queue实现前端的被动接收

    一般请求都是由前端主动发起请求,后端响应,但有些情况必须要后端达到一定条件了才向前端相应数据,这就变成前端被动了.比如微信接收信息,只有别人给你发消息,你才能被动接收消息. 最近做了个项目,当有人经过 ...

  3. adb常用命令-android学习第一天

    转载出处:http://www.cnblogs.com/xiaoxuetu/ 转载来源:https://www.cnblogs.com/xiaoxuetu/p/3411214.html 平时开发and ...

  4. Quartz的简单使用

    一.Quartz 介绍 Quartz是Java领域最著名的.功能丰富的.开放源码的作业调度工具,几乎可以在所有的Java应用程序中集成--从小的单机应用到大的电子商务系统. Quartz可以用来执行成 ...

  5. 【记录】ajax 设置请求header的Content-Type 为 application/json;charset=utf8

    具体案例如下 $.ajax({ url: context.state.IpccSendIm, method: 'POST', data: JSON.stringify(val), headers:{' ...

  6. 微信小程序(15)--上传图片公用组件(2)

    接下来开始写写上传图片的公用组件,可以自定义上传几张图片. chooseImage文件夹里面的index.wxml和index.js,涉及图片上传,删除,预览. <view class=&quo ...

  7. Kvm --01 虚拟化基础概念

    目录 1. 虚拟化基础概念 01. 什么是虚拟化? 02. 为什么要用虚拟化? 03. 虚拟化在企业中的应用场景? 04. 虚拟化软件介绍 05. Kvm介绍 2. 安装部署Kvm 3. Kvm虚拟机 ...

  8. 8VC Venture Cup 2017 - Elimination Round - C

    题目链接:http://codeforces.com/contest/755/problem/C 题意:PolandBall 生活在一个森林模型的环境中,定义森林由若干树组成,定义树为K个点,K-1条 ...

  9. Java面向对象的特征与含义

    面向对象的主要特征包括抽象.继承.封装和多态. 抽象 把一个类对象的共同特征总结出来,构造新类的过程. 继承 从已有类中得到继承信息,创建新类的过程. 封装 把数据和对数据的操作绑定起来,对数据的访问 ...

  10. 简单说下cookie,LocalStorage与SessionStorage.md

    最近在网上看到有人讨论这三个的一些概念与区别,发现自己也一直没有较好的总结,所以查阅了一些资料来阐述一下. 基本概念 cookie cookie英文意思是小甜饼,是原来的网景公司创造,目前是在客户端存 ...