OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimTerraSarTiffReader.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: See top level LICENSE.txt file
4 //
5 // Author: David Burken
6 //
7 // Description: Image handelr for TerraSar-X data that is TIFF based.
8 //
9 //----------------------------------------------------------------------------
10 // $Id$
11 
14 #include <ossimTerraSarModel.h>
19 #include <ossim/base/ossimTrace.h>
20 #include <ossim/base/ossimNotify.h>
26 
27 // Keyword constants:
28 static const char PRODUCT_XML_FILE_KW[] = "product_xml_filename";
29 
30 namespace ossimplugins
31 {
32 RTTI_DEF1(ossimTerraSarTiffReader,
33  "ossimTerraSarTiffReader",
35 }
36 
37 #ifdef OSSIM_ID_ENABLED
38  static const char OSSIM_ID[] = "$Id$";
39 #endif
40 
41 static ossimTrace traceDebug("ossimTerraSarTiffReader:degug");
42 
44  :
46 {
47  if (traceDebug())
48  {
50  << "ossimplugins::ossimTerraSarTiffReader::ossimTerraSarTiffReader entered...\n";
51 #ifdef OSSIM_ID_ENABLED
53  << "OSSIM_ID: " << OSSIM_ID << std::endl;
54 #endif
55  }
56 }
57 
59 {
60 }
61 
63  ossimKeywordlist& kwl, const char* prefix) const
64 {
65  static const char MODULE[] = "ossimplugins::ossimTerraSarTiffReader::saveState";
66 
67  if (traceDebug())
68  {
70  << MODULE << " entered...\n";
71  }
72 
73  // Save our state:
74  kwl.add(prefix, PRODUCT_XML_FILE_KW, theProductXmlFile.c_str());
75 
76  // Save the base:
77  return ossimTiffTileSource::saveState(kwl, prefix);
78 }
79 
81  const ossimKeywordlist& kwl, const char* prefix)
82 {
83  static const char MODULE[] = "ossimplugins::ossimTerraSarTiffReader::loadState";
84 
85  if (traceDebug())
86  {
88  << MODULE << " entered...\n";
89  }
90 
91  bool result = false;
92 
93  // Get the product.xml file name.
94  const char* lookup = kwl.find(prefix, PRODUCT_XML_FILE_KW);
95  if (lookup)
96  {
97  theProductXmlFile = lookup;
98  if ( isTerraSarProductFile(theProductXmlFile) )
99  {
100  //---
101  // Although we can open any tiff here we only do if we have matching
102  // TerraSAR-X product.xml.
103  //---
104  result = ossimTiffTileSource::loadState(kwl, prefix);
105  }
106  }
107 
108  if (!result)
109  {
110  theProductXmlFile.clear();
111  }
112 
113  if (traceDebug())
114  {
116  << MODULE << " exit status = " << (result?"true":"false\n")
117  << std::endl;
118  }
119 
120  return result;
121 }
122 
124 {
125  return ossimString("ossim_terrasar_tiff_reader");
126 }
127 
129 {
130  return ossimString("ossim TerraSAR-X tiff reader");
131 }
132 
134 {
135  return ossimString("ossimTerraSarTiffReader");
136 }
137 
139 {
140  static const char MODULE[] = "ossimplugins::ossimTerraSarTiffReader::open";
141 
142  if (traceDebug())
143  {
145  << MODULE << " entered...\n"
146  << "file: " << file << "\n";
147  }
148 
149  bool result = false;
150 
151  if ( isOpen() )
152  {
153  close();
154  }
155 
156  // Check extension to see if it's xml.
157  if ( file.ext().downcase() == "xml" )
158  {
160  if ( xdoc->openFile(file) )
161  {
162  // See if it's a TerraSAR-X product xml file.
163  if ( isTerraSarProductFile( xdoc.get() ) )
164  {
165  ossimString s;
167 
168  if ( helper.getImageFile(xdoc.get(), s) )
169  {
170  ossimFilename imageFile = file.expand().path();
171  imageFile = imageFile.dirCat(s);
172 
173  setFilename(imageFile);
174 
175  result = ossimTiffTileSource::open();
176  if (result)
177  {
178  theProductXmlFile = file;
179 
180  completeOpen();
181  }
182  }
183  }
184  }
185 
186  } // matches: if ( file.ext().downcase() == "xml" )
187 
188  if (traceDebug())
189  {
191  << MODULE << " exit status = " << (result?"true":"false\n")
192  << std::endl;
193  }
194 
195  return result;
196 }
197 
199 {
200  theProductXmlFile.clear();
202 }
203 
205 {
206  if ( !theGeometry )
207  {
208  // Check for external geom:
209  theGeometry = getExternalImageGeometry();
210 
211  if ( !theGeometry )
212  {
213  // Check the internal geometry first to avoid a factory call.
214  theGeometry = getInternalImageGeometry();
215 
216  // At this point it is assured theGeometry is set.
217 
218  //---
219  // WARNING:
220  // Must create/set theGeometry at this point or the next call to
221  // ossimImageGeometryRegistry::extendGeometry will put us in an infinite loop
222  // as it does a recursive call back to ossimImageHandler::getImageGeometry().
223  //---
224 
225  // Check for set projection.
226  if ( !theGeometry->getProjection() )
227  {
228  // Try factories for projection.
230  }
231  }
232 
233  // Set image things the geometry object should know about.
234  initImageParameters( theGeometry.get() );
235  }
236 
237  return theGeometry;
238 }
239 
242 {
243  static const char MODULE[] = "ossimplugins::ossimTerraSarTiffReader::getInternalImageGeometry";
244  if (traceDebug())
245  {
246  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n";
247  }
248 
250 
252  if ( xdoc->openFile(theProductXmlFile) )
253  {
255  ossimString s;
256  if ( helper.getProjection(xdoc.get(), s) )
257  {
258  s.upcase();
259  if ( s == "GROUNDRANGE" )
260  {
262  new ossimTerraSarModel();
263  if ( model->open(theProductXmlFile) )
264  {
265  // Assign the model to our ossimImageGeometry object.
266  geom->setProjection( model.get() );
267  }
268  }
269  else if ( (s == "MAP") && theTiffPtr )
270  {
271  ossimGeoTiff geotiff;
272 
273  //---
274  // Note: must pass false to readTags so it doesn't close our
275  // tiff pointer.
276  //---
277  geotiff.readTags(theTiffPtr, getCurrentEntry(), false);
278  ossimKeywordlist kwl;
279  if(geotiff.addImageGeometry(kwl))
280  {
283  createProjection(kwl);
284 
285  if ( proj.valid() )
286  {
287  // Assign projection to our ossimImageGeometry object.
288  geom->setProjection( proj.get() );
289  }
290  }
291  }
292  else
293  {
294  if (traceDebug())
295  {
297  << "WARNING: Unhandled projection: " << s << std::endl;
298 
299  }
300  }
301  }
302 
303  } // matches: if ( xdoc->openFile(theProductXmlFile) )
304 
305  if (traceDebug())
306  {
307  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " exited..." << std::endl;
308  }
309 
310  return geom;
311 }
312 
314  const ossimFilename& file) const
315 {
316  bool result = false;
317 
318  // Check extension to see if it's xml.
319  if ( file.ext().downcase() == "xml" )
320  {
322  if ( xdoc->openFile(file) )
323  {
324  result = isTerraSarProductFile( xdoc.get() );
325  }
326  }
327 
328  return result;
329 }
330 
332  const ossimXmlDocument* xdoc) const
333 {
334  bool result = false;
335 
336  if (xdoc)
337  {
339 
340  // See if it's a TerraSAR-X product xml file.
341  result = helper.isTerraSarX(xdoc);
342  }
343 
344  return result;
345 }
Class to encapsulate parsing TerraSAR product xml file.
static ossimImageGeometryRegistry * instance()
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
void setProjection(ossimProjection *projection)
Sets the projection to be used for local-to-world coordinate transformation.
bool open()
Returns true if no errors initializing object.
static ossimString upcase(const ossimString &aString)
Definition: ossimString.cpp:34
bool getProjection(const ossimXmlDocument *xdoc, ossimString &s) const
bool isTerraSarProductFile(const ossimFilename &file) const
Method to check file to see if it&#39;s a TerraSAR-X product xml file.
bool isTerraSarX(const ossimXmlDocument *xdoc) const
Checks for node /level1Product/generalHeader/mission containing "TSX-1".
bool addImageGeometry(ossimKeywordlist &kwl, const char *prefix=0) const
Add geometry info from tags to keword list.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
RTTI_DEF1(ossimAlosPalsarModel, "ossimAlosPalsarModel", ossimGeometricSarSensorModel)
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if non defined...
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
virtual ossimRefPtr< ossimImageGeometry > getInternalImageGeometry() const
ossimFilename expand() const
Method to do file name expansion.
This class allows for direct localisation and indirect localisation using the TerraSar sensor model...
virtual bool extendGeometry(ossimImageHandler *handler) const
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
bool openFile(const ossimFilename &filename)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
virtual void close()
Deletes the overview and clears the valid image vertices.
Container class that holds both 2D transform and 3D projection information for an image Only one inst...
bool open(const ossimFilename &file)
Method to intantial model from a file.
static ossimProjectionFactoryRegistry * instance()
bool getImageFile(const ossimXmlDocument *xdoc, ossimString &s) const
ossimFilename dirCat(const ossimFilename &file) const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
ossimString ext() const
bool readTags(const ossimFilename &file, ossim_uint32 entryIdx=0)
Reads tags.
virtual ~ossimTerraSarTiffReader()
virtual destructor
ossimFilename path() const
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)