一.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类