GIS:GDAL开发库

一.GDAL安装

从GDAL 2.0+版本升级到3.0+版本

3.0+版本必须依赖PROJ库,而且PROJ库必须是6.0+版本
PROJ库需要proj.db数据库支持空间参考,默认在proj.dll目录中,也可以通过OSRSetPROJSearchPaths()来设置目录

 

 

二.GDAL使用

复制代码
从GDAL 2.版本升级到3.版本,使用接口发生了改变

OGRSpatialReference类用于实现OpenGIS空间参考系统定义,目前已经支持本地坐标系 地理坐标系 投影坐标系 垂直坐标系 地心坐标系 复合坐标系
OGRSpatialReference::IsProjected()
OGRSpatialReference::IsGeographic()
OGRSpatialReference::GetSemiMajor()
OGRSpatialReference::GetSemiMinor()
OGRSpatialReference::GetInvFlattening()
OGRSpatialReference::GetAttrValue()
OGRSpatialReference::GetProjParm()
OGRSpatialReference::GetLinearUnits()

OGRCoordinateTransform类使用PROJ.4库实现坐标转换
OGRCoordinateTransform::Transform()
复制代码

 

复制代码
//GDAL2.0+版本

void TestLongLat2UTM()
{
  OGRCoordinateTransformation* poCT = nullptr;
  double dfCenterLong = 104.49242396000000;
  double dfCenterLat = 26.311051110000001;
  int nZone = static_cast<int>(dfCenterLong / 6 + 31);
  int bNorth = dfCenterLat >= 0 ? TRUE : FALSE;
  
  OGRSpatialReference oWGS84;
  oWGS84.SetWellKnownGeogCS("WGS84");

  OGRSpatialReference oUtmSrs;
  oUtmSrs.SetWellKnownGeogCS("WGS84");
  oUtmSrs.SetUTM(nZone, bNorth);

  poCT = OGRCreateCoordinateTransformation(&oWGS84, &oUtmSrs);

  double dx = 104.28982973166080;
  double dy = 26.567797593704370;
  double dz = 1826.8254084027094;
  int bTransformSuccess;
  poCT->Transform(1, &dx, &dy, &dz, &bTransformSuccess);

  OGRCoordinateTransformation::DestoryCT(poCT);

}
复制代码

 

复制代码
//GDAL3.0+

void TestLongLat2UTM()
{
  OGRCoordinateTransformation* poCT = nullptr;
  double dfCenterLong = 104.49242396000000;
  double dfCenterLat = 26.311051110000001;
  int nZone = static_cast<int>(dfCenterLong / 6 + 31);
  int bNorth = dfCenterLat >= 0 ? TRUE : FALSE;

  OGRSpatialReference oWGS84;
  oWGS84.SetWellKnownGeogCS("WGS84");
  oWGS84.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);  //在新版GDAL中,这一行非常重要,必须出现才能运行
  
OGRSpatialReference oUtmSrs;
oUtmSrs.SetWellKnownGeogCS("WGS84");
oUtmSrs.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
oUtmSrs.SetUTM(nZone, bNorth);

poCT = OGRCreateCoordinateTransformation(&oWGS84, &oUtmSrs);

double dx = 104.28982973166080;
double dy = 26.567797593704370;
double dz = 1826.8254084027094;
int bTransformSuccess;
poCT->Transform(1, &dx, &dy, &dz, &bTransformSuccess);

OGRCoordinateTransformation::DestoryCT(poCT)
}
复制代码

 

1.栅格

 

2.矢量

 

3.地理网络模型

 

4.投影和空间参考系统(OSR-OGRSpatialReference)

OGRSpatialReference类

OGRCoordinateTransformation类

 

posted @   言午丶  阅读(474)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示