OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimERSTileSource.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: LGPL
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: Chong-Ket Chuah
9 //
10 // Description:
11 //
12 // Implementation for the class "ossimERSTileSource". ossimERSTileSource
13 // is used for reading ER Mapper raster file format. The format consists
14 // of a raster file with no extension and a header file with the same name
15 // as the raster file but with an .ers extension.
16 //
17 //*******************************************************************
18 // $Id: ossimERSTileSource.cpp 21512 2012-08-22 11:53:57Z dburken $
19 
22 
24 #include <ossim/base/ossimTrace.h>
27 
29 
30 //*******************************************************************
31 // Public Constructor:
32 //*******************************************************************
35  theHdr(NULL)
36 {
37 }
38 
39 //*******************************************************************
40 // Public Constructor:
41 //*******************************************************************
43  const char* prefix)
45  theHdr(NULL)
46 {
47  if (loadState(kwl, prefix) == false)
48  {
50  }
51 }
52 
53 //*******************************************************************
54 // Destructor:
55 //*******************************************************************
57 {
58  if (theHdr)
59  {
60  delete theHdr;
61  theHdr = NULL;
62  }
63 }
64 
66 {
67  // Open and parse the header file
68  theHdr = new ossimERS(fileName);
69 
70 // theHdr->dump(cout);
71 
73  {
74  delete theHdr;
75  theHdr = NULL;
76  return false;
77  }
78  else
79  {
80  vector<ossimFilename> f;
81  ossimFilename fne;
82  ossimFilename fpath = fileName.path();
83  if (fpath.empty())
84  fne = fileName.fileNoExtension();
85  else
86  fne = fpath+"/"+fileName.fileNoExtension();
87  f.push_back(fne);
88  ossimGeneralRasterInfo genRasterInfo(f,
90  OSSIM_BIL,
92  theHdr->theLine,
94  0,
96  0);
98  {
99  ossim_uint32 i = 0;
100  ossim_uint32 bands = static_cast<ossim_uint32>(theHdr->theBands);
101  for(i = 0; i < bands; ++i)
102  {
103  genRasterInfo.getImageMetaData().setNullPix(i, theHdr->theNullCell);
104  }
105  }
106  ossimFilename metadataFile = fne;
107  metadataFile = metadataFile + ".omd";
108 
109  if(metadataFile.exists())
110  {
111  ossimKeywordlist kwl;
112 
113  kwl.addFile(metadataFile.c_str());
114 
115  theMetaData.loadState(kwl);
116  ossim_uint32 i = 0;
117  ossim_uint32 bands = static_cast<ossim_uint32>(theHdr->theBands);
118  for(i = 0; i < bands; ++i)
119  {
121  {
122  genRasterInfo.getImageMetaData().setMinPix(i, theMetaData.getMinPix(i));
123  }
125  {
126  genRasterInfo.getImageMetaData().setMaxPix(i, theMetaData.getMaxPix(i));
127  }
129  {
130  genRasterInfo.getImageMetaData().setNullPix(i, theMetaData.getNullPix(i));
131  }
132  }
133  }
135  << "general raster info is\n";
136  genRasterInfo.print(ossimNotify(ossimNotifyLevel_INFO));
137  ossimGeneralRasterTileSource::open(genRasterInfo);
138  }
139 
140  return true;
141 }
142 
143 
145 {
146  if ( !theGeometry )
147  {
148  // Check for external geom:
150 
151  if ( !theGeometry )
152  {
153 
155 
156  if(theHdr)
157  {
158  ossimKeywordlist kwl;
159  if ( theHdr->toOssimProjectionGeom(kwl) )
160  {
161  theGeometry->loadState(kwl);
162  }
163  }
164 
165  // At this point it is assured theGeometry is set.
166 
167  //---
168  // WARNING:
169  // Must create/set the geometry at this point or the next call to
170  // ossimImageGeometryRegistry::extendGeometry will put us in an infinite loop
171  // as it does a recursive call back to ossimImageHandler::getImageGeometry().
172  //---
173 
174  // Check for set projection.
175  if ( !theGeometry->getProjection() )
176  {
177  // Try factories for projection.
179  }
180  }
181 
182  // Set image things the geometry object should know about.
184  }
185  return theGeometry;
186 }
187 
189  const char* prefix)
190 {
191  const char* lookup = kwl.find(prefix, ossimKeywordNames::FILENAME_KW);
192 
193  if (lookup)
194  {
195  ossimFilename fileName = lookup;
196 
197  bool result = open(fileName);
198  ossimImageSource::loadState(kwl, prefix);
199  return result;
200  }
201 
202  return ossimGeneralRasterTileSource::loadState(kwl, prefix);
203 }
204 
206 {
207  return ossimString("ERS");
208 }
209 
211 {
212  return ossimString("ER Mapper Raster");
213 }
214 
216 {
217  return ossimString("ossimERSTileSource");
218 }
219 
bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
static ossimImageGeometryRegistry * instance()
ossimRefPtr< ossimImageGeometry > theGeometry
virtual bool open()
Pure virtual open.
double getMinPix(ossim_uint32 band) const
bool getMinValuesValidFlag() const
Represents serializable keyword/value map.
bool addFile(const char *file)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Attempts to initialize a transform and a projection given the KWL.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
const char * find(const char *key) const
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if not defined...
double getMaxPix(ossim_uint32 band) const
static const ossimErrorCode OSSIM_ERROR
bool toOssimProjectionGeom(ossimKeywordlist &kwl, const char *prefix=NULL) const
Definition: ossimERS.cpp:531
bool getNullValuesValidFlag() const
double getNullPix(ossim_uint32 band) const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
virtual bool extendGeometry(ossimImageHandler *handler) const
virtual ossimString getLongName() const
ossimScalarType theCelltype
Definition: ossimERS.h:58
virtual std::ostream & print(std::ostream &out) const
Generic print method.
void push_back(char c)
Equivalent to insert(end(), c).
Definition: ossimString.h:905
void setMinPix(ossim_uint32 band, double pix)
bool theHasNullCells
Definition: ossimERS.h:60
double theNullCell
Definition: ossimERS.h:61
ossim_int32 theBands
Definition: ossimERS.h:68
bool exists() const
RTTI_DEF1(ossimERSTileSource, "ossimERSTileSource", ossimGeneralRasterTileSource)
unsigned int ossim_uint32
virtual ossimString getShortName() const
void initImageParameters(ossimImageGeometry *geom) const
Convenience method to set things needed in the image geometry from the image handler.
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
virtual ossimRefPtr< ossimImageGeometry > getExternalImageGeometry() const
Returns the image geometry object associated with this tile source or NULL if non defined...
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
ossimImageMetaData theMetaData
ossim_int32 errorStatus() const
Definition: ossimERS.h:79
bool getMaxValuesValidFlag() const
ossimFilename fileNoExtension() const
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
bool empty() const
Definition: ossimString.h:411
const ossimImageMetaData & getImageMetaData() const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=NULL)
Method to the load (recreate) the state of an object from a keyword list.
ossim_int32 theSample
Definition: ossimERS.h:65
ossim_int32 theLine
Definition: ossimERS.h:64
virtual ossimString className() const
static const char * FILENAME_KW
ossimFilename path() const
void setMaxPix(ossim_uint32 band, double pix)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
void setNullPix(ossim_uint32 band, double pix)