forked from ossimlabs/ossim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ossimERSTileSource.cpp
221 lines (190 loc) · 6.38 KB
/
ossimERSTileSource.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//*******************************************************************
// Copyright (C) 2000 ImageLinks Inc.
//
// License: LGPL
//
// See LICENSE.txt file in the top level directory for more details.
//
// Author: Chong-Ket Chuah
//
// Description:
//
// Implementation for the class "ossimERSTileSource". ossimERSTileSource
// is used for reading ER Mapper raster file format. The format consists
// of a raster file with no extension and a header file with the same name
// as the raster file but with an .ers extension.
//
//*******************************************************************
// $Id: ossimERSTileSource.cpp 21512 2012-08-22 11:53:57Z dburken $
#include <ossim/imaging/ossimERSTileSource.h>
#include <ossim/support_data/ossimERS.h>
#include <ossim/base/ossimDirectory.h>
#include <ossim/base/ossimTrace.h>
#include <ossim/base/ossimKeywordNames.h>
#include <ossim/imaging/ossimImageGeometryRegistry.h>
RTTI_DEF1(ossimERSTileSource, "ossimERSTileSource", ossimGeneralRasterTileSource);
using namespace std;
//*******************************************************************
// Public Constructor:
//*******************************************************************
ossimERSTileSource::ossimERSTileSource()
: ossimGeneralRasterTileSource(),
theHdr(NULL)
{
}
//*******************************************************************
// Public Constructor:
//*******************************************************************
ossimERSTileSource::ossimERSTileSource(const ossimKeywordlist& kwl,
const char* prefix)
: ossimGeneralRasterTileSource(),
theHdr(NULL)
{
if (loadState(kwl, prefix) == false)
{
theErrorStatus = ossimErrorCodes::OSSIM_ERROR;
}
}
//*******************************************************************
// Destructor:
//*******************************************************************
ossimERSTileSource::~ossimERSTileSource()
{
if (theHdr)
{
delete theHdr;
theHdr = NULL;
}
}
bool ossimERSTileSource::open(const ossimFilename& fileName)
{
// Open and parse the header file
theHdr = new ossimERS(fileName);
// theHdr->dump(cout);
if(theHdr->errorStatus() == ossimErrorCodes::OSSIM_ERROR)
{
delete theHdr;
theHdr = NULL;
return false;
}
else
{
vector<ossimFilename> f;
ossimFilename fne;
ossimFilename fpath = fileName.path();
if (fpath.empty())
fne = fileName.fileNoExtension();
else
fne = fpath+"/"+fileName.fileNoExtension();
f.push_back(fne);
ossimGeneralRasterInfo genRasterInfo(f,
theHdr->theCelltype,
OSSIM_BIL,
theHdr->theBands,
theHdr->theLine,
theHdr->theSample,
0,
ossimGeneralRasterInfo::NONE,
0);
if(theHdr->theHasNullCells)
{
ossim_uint32 i = 0;
ossim_uint32 bands = static_cast<ossim_uint32>(theHdr->theBands);
for(i = 0; i < bands; ++i)
{
genRasterInfo.getImageMetaData().setNullPix(i, theHdr->theNullCell);
}
}
ossimFilename metadataFile = fne;
metadataFile = metadataFile + ".omd";
if(metadataFile.exists())
{
ossimKeywordlist kwl;
kwl.addFile(metadataFile.c_str());
theMetaData.loadState(kwl);
ossim_uint32 i = 0;
ossim_uint32 bands = static_cast<ossim_uint32>(theHdr->theBands);
for(i = 0; i < bands; ++i)
{
if(theMetaData.getMinValuesValidFlag())
{
genRasterInfo.getImageMetaData().setMinPix(i, theMetaData.getMinPix(i));
}
if(theMetaData.getMaxValuesValidFlag())
{
genRasterInfo.getImageMetaData().setMaxPix(i, theMetaData.getMaxPix(i));
}
if(theMetaData.getNullValuesValidFlag())
{
genRasterInfo.getImageMetaData().setNullPix(i, theMetaData.getNullPix(i));
}
}
}
ossimNotify(ossimNotifyLevel_INFO)
<< "general raster info is\n";
genRasterInfo.print(ossimNotify(ossimNotifyLevel_INFO));
ossimGeneralRasterTileSource::open(genRasterInfo);
}
return true;
}
ossimRefPtr<ossimImageGeometry> ossimERSTileSource::getImageGeometry()
{
if ( !theGeometry )
{
// Check for external geom:
theGeometry = getExternalImageGeometry();
if ( !theGeometry )
{
theGeometry = new ossimImageGeometry;
if(theHdr)
{
ossimKeywordlist kwl;
if ( theHdr->toOssimProjectionGeom(kwl) )
{
theGeometry->loadState(kwl);
}
}
// At this point it is assured theGeometry is set.
//---
// WARNING:
// Must create/set the geometry at this point or the next call to
// ossimImageGeometryRegistry::extendGeometry will put us in an infinite loop
// as it does a recursive call back to ossimImageHandler::getImageGeometry().
//---
// Check for set projection.
if ( !theGeometry->getProjection() )
{
// Try factories for projection.
ossimImageGeometryRegistry::instance()->extendGeometry(this);
}
}
// Set image things the geometry object should know about.
initImageParameters( theGeometry.get() );
}
return theGeometry;
}
bool ossimERSTileSource::loadState(const ossimKeywordlist& kwl,
const char* prefix)
{
const char* lookup = kwl.find(prefix, ossimKeywordNames::FILENAME_KW);
if (lookup)
{
ossimFilename fileName = lookup;
bool result = open(fileName);
ossimImageSource::loadState(kwl, prefix);
return result;
}
return ossimGeneralRasterTileSource::loadState(kwl, prefix);
}
ossimString ossimERSTileSource::getShortName() const
{
return ossimString("ERS");
}
ossimString ossimERSTileSource::getLongName() const
{
return ossimString("ER Mapper Raster");
}
ossimString ossimERSTileSource::className() const
{
return ossimString("ossimERSTileSource");
}