在GDAL中定义坐标系,是很简单的一件事情。主要参考类OGRSpatialReference。
根据官方的操作文档(http://www.gdal.org/osr_tutorial.html),我们先定义一个坐标系:
#include<gdal_priv.h>
#include <ogr_spatialref.h>
int main()
{
GDALAllRegister();
OGRSpatialReference oSRS;
oSRS.SetGeogCS( "My geographic coordinate system",
"WGS_1984",
"My WGS84 Spheroid",
SRS_WGS84_SEMIMAJOR, SRS_WGS84_INVFLATTENING,
"Greenwich", 0.0,
"degree", SRS_UA_DEGREE_CONV);
}
很明显,源码中的SRS_UA_DEGREE_CONV定义的时候是 const char,这个时候不能转为double,参考gdal的bug说明(http://trac.osgeo.org/gdal/ticket/3775)。
修改后的源码为:
[code=cpp]
#include<gdal_priv.h>
#include <ogr_spatialref.h>
int main()
{
GDALAllRegister();
OGRSpatialReference oSRS;
oSRS.SetGeogCS( "My geographic coordinate system",
"WGS_1984",
"My WGS84 Spheroid",
SRS_WGS84_SEMIMAJOR, SRS_WGS84_INVFLATTENING,
"Greenwich", 0.0,
"degree", atof(SRS_UA_DEGREE_CONV));
}
[/code]