-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpgtiol-gTiffManager.cpp
112 lines (96 loc) · 2.79 KB
/
pgtiol-gTiffManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "pgtiol-gTiffManager.h"
GTiffManager::GTiffManager(void)
{
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD,&size);
igTiffMetaData = new gTiffMetaData();
igTiffData = new gTiffData();
writeProcs = -1;
}
GTiffManager::~GTiffManager(void)
{
if(igTiffMetaData!=NULL){
delete igTiffMetaData;
igTiffMetaData = NULL;
}
if(igTiffData!=NULL){
delete igTiffData;
igTiffData = NULL;
}
}
bool GTiffManager::setInputFile(const char *inputFile)
{
if(inputFile==NULL){
cerr << __FILE__ << " " << __FUNCTION__ \
<< " Error: input filename is null (" <<inputFile<<")"<<endl;
return false;
}
strcpy(inputFileName, inputFile);
return true;
}
bool GTiffManager::setOutputFile(const char *outputFile)
{
if(outputFile==NULL){
cerr << __FILE__ << " " << __FUNCTION__ \
<< " Error: output filename is null (" <<outputFile<<")"<<endl;
return false;
}
strncpy(outputFileName,outputFile, MAXLEN);
return true;
}
bool GTiffManager::readMetaData()
{
if(!igTiffMetaData->setInputFile(inputFileName)){
cerr << __FILE__ << " " << __FUNCTION__ \
<< " Error: input filename is null (" <<inputFileName<<")"<<endl;
return false;
}
if(!igTiffMetaData->readMetaData()){
cerr << __FILE__ << " " << __FUNCTION__ \
<< " Error occurred when reading file (" <<inputFileName<<")"<<endl;
return false;
}
return true;
}
bool GTiffManager::writeMetaData()
{
if(!igTiffMetaData->setOutputFile(outputFileName)){
cerr << __FILE__ << " " << __FUNCTION__ \
<< " Error output filename is null (" <<outputFileName<<")"<<endl;
return false;
}
if(rank == writeProcs){
if(!igTiffMetaData->writeMetaData()){
cerr << __FILE__ << " " << __FUNCTION__ \
<< " Error occurred when writing metadata of (" <<outputFileName<<")"<<endl;
return false;
}
}
//MPI_Barrier(MPI_COMM_WORLD); // guan edit
if(!igTiffMetaData->getMetaDataRaster()){
cerr << __FILE__ << " " << __FUNCTION__ \
<< " Error occurred when reading metadata of (" <<outputFileName<<")"<<endl;
return false;
}
return true;
}
bool GTiffManager::writeIO(long nXOff, long nYOff, long nYSize,long nXSize, void*pData,GDALDataType dataType,long nLineSpace)
{
if(!igTiffData->setOutputFileName(outputFileName)){
return false;
}
if(!igTiffData->writeData(nXOff, nYOff, nYSize, nXSize,pData,dataType,igTiffMetaData,nLineSpace)){
return false;
}
return true;
}
bool GTiffManager::readIO(long nXOff, long nYOff, long nYSize,long nXSize, void*pData,GDALDataType dataType,int band_count)
{
if(!igTiffData->setInputFileName(inputFileName)){
return false;
}
if(!igTiffData->readData(nXOff, nYOff, nYSize, nXSize,pData,dataType,band_count,igTiffMetaData)){
return false;
}
return true;
}