1
/*
2
=========================================================================================
3
以下是一些测试GDAL用法的函数
4
=========================================================================================
5
*/
6
7
//
描述:测试某类型是否支持CreateCopy和Create
8
//
参数:pszFormat-驱动格式,比如“GTIFF”
9
//
输出:结果打印到命令行
10
void
ISCanCreate(
const
char
*
pszFormat)
11
{
12
//
determine if a particular format supports Create or CreateCopy it is possible to check the
13
//
DCAP_CREATE and DCAP_CREATECOPY metadata on the format driver object.
14
15
GDALDriver
*
poDriver;
16
char
**
papszMetadata;
17
GDALAllRegister();
18
poDriver
=
GetGDALDriverManager()
->
GetDriverByName(pszFormat);
19
20
if
( poDriver
==
NULL )
21
exit(
1
);
22
23
char
message[
100
];
24
papszMetadata
=
poDriver
->
GetMetadata();
25
if
( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATE, FALSE ) )
26
sprintf(message,
"
Driver %s supports Create() method.\n
"
, pszFormat );
27
if
( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATECOPY, FALSE ) )
28
sprintf(message,
"
Driver %s supports CreateCopy() method.\n
"
, pszFormat );
29
30
AfxMessageBox(message);
31
}
32
33
//
描述:测试读取到DataSet并输出图像的基本信息
34
//
参数:pszFilename-文件名称
35
//
输出:信息打印到命令行
36
bool
OpenFileToDataSet(
char
*
pszFilename)
37
{
38
GDALDataset
*
poDataset;
39
40
poDataset
=
(GDALDataset
*
) GDALOpen( pszFilename, GA_ReadOnly );
41
if
( poDataset
!=
NULL )
42
{
43
double
adfGeoTransform[
6
];
44
char
message[
100
];
45
46
sprintf(message,
"
Driver: %s/%s\n
"
,
47
poDataset
->
GetDriver()
->
GetDescription(),
48
poDataset
->
GetDriver()
->
GetMetadataItem( GDAL_DMD_LONGNAME ) );
49
50
sprintf(message,
"
Size is %dx%dx%d\n
"
,
51
poDataset
->
GetRasterXSize(), poDataset
->
GetRasterYSize(),
52
poDataset
->
GetRasterCount() );
53
54
if
( poDataset
->
GetProjectionRef()
!=
NULL )
55
sprintf(message,
"
Projection is `%s'\n
"
, poDataset
->
GetProjectionRef());
56
57
if
( poDataset
->
GetGeoTransform( adfGeoTransform )
==
CE_None )
58
{
59
sprintf(message,
"
Origin = (%.6f,%.6f)\n
"
,
60
adfGeoTransform[
0
], adfGeoTransform[
3
] );
61
62
sprintf(message,
"
Pixel Size = (%.6f,%.6f)\n
"
,
63
adfGeoTransform[
1
], adfGeoTransform[
5
] );
64
}
65
66
AfxMessageBox(message);
67
return
true
;
68
}
else
69
return
false
;
70
}
71
72
//
描述:测试读取一个BAND并输出基本信息
73
//
参数:poDataset-数据集
74
//
输出:信息打印到命令行
75
void
ReadBandInf(GDALDataset
*
poDataset)
76
{
77
GDALRasterBand
*
poBand;
78
int
nBlockXSize, nBlockYSize;
79
int
bGotMin, bGotMax;
80
double
adfMinMax[
2
];
81
char
message[
100
];
82
83
poBand
=
poDataset
->
GetRasterBand(
1
);
84
poBand
->
GetBlockSize(
&
nBlockXSize,
&
nBlockYSize );
85
sprintf(message,
"
Block=%dx%d Type=%s, ColorInterp=%s\n
"
,
86
nBlockXSize, nBlockYSize,
87
GDALGetDataTypeName(poBand
->
GetRasterDataType()),
88
GDALGetColorInterpretationName(
89
poBand
->
GetColorInterpretation()) );
90
91
adfMinMax[
0
]
=
poBand
->
GetMinimum(
&
bGotMin );
92
adfMinMax[
1
]
=
poBand
->
GetMaximum(
&
bGotMax );
93
if
(
!
(bGotMin
&&
bGotMax) )
94
GDALComputeRasterMinMax((GDALRasterBandH)poBand, TRUE, adfMinMax);
95&n (本文已被浏览 次) | | |