OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimRadarSat2TiffReader.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: See top level LICENSE.txt file
4 //
5 // Author: John Stastny
6 //
7 // Description: Image handelr for RadarSAT-2 data that is TIFF based.
8 //
9 //----------------------------------------------------------------------------
10 // $Id$
11 
12 #include <cstdlib>
13 
16 #include <ossimRadarSat2Model.h>
21 #include <ossim/base/ossimTrace.h>
22 #include <ossim/base/ossimNotify.h>
27 
28 // Keyword constants:
29 static const char PRODUCT_XML_FILE_KW[] = "product_xml_filename";
30 
31 namespace ossimplugins
32 {
33 RTTI_DEF1(ossimRadarSat2TiffReader,
34  "ossimRadarSat2TiffReader",
36 }
37 
38 #ifdef OSSIM_ID_ENABLED
39  static const char OSSIM_ID[] = "$Id$";
40 #endif
41 
42 static ossimTrace traceDebug("ossimRadarSat2TiffReader:degug");
43 
45  :
47 {
48  if (traceDebug())
49  {
51  << "ossimplugins::ossimRadarSat2TiffReader::ossimRadarSat2TiffReader entered...\n";
52 #ifdef OSSIM_ID_ENABLED
54  << "OSSIM_ID: " << OSSIM_ID << std::endl;
55 #endif
56  }
57 }
58 
60 {
61 }
62 
64  ossimKeywordlist& kwl, const char* prefix) const
65 {
66  static const char MODULE[] = "ossimplugins::ossimRadarSat2TiffReader::saveState";
67 
68  if (traceDebug())
69  {
71  << MODULE << " entered...\n";
72  }
73 
74  // Save our state:
75  kwl.add(prefix, PRODUCT_XML_FILE_KW, theProductXmlFile.c_str());
76 
77  // Save the base:
78  return ossimTiffTileSource::saveState(kwl, prefix);
79 }
80 
82  const ossimKeywordlist& kwl, const char* prefix)
83 {
84  static const char MODULE[] = "ossimplugins::ossimRadarSat2TiffReader::loadState";
85 
86  if (traceDebug())
87  {
89  << MODULE << " entered...\n";
90  }
91 
92  bool result = false;
93 
94  // Get the product.xml file name.
95  const char* lookup = kwl.find(prefix, PRODUCT_XML_FILE_KW);
96  if (lookup)
97  {
98  theProductXmlFile = lookup;
99  if ( isRadarSat2ProductFile(theProductXmlFile) )
100  {
101  //---
102  // Although we can open any tiff here we only do if we have matching
103  // RS2 product.xml.
104  //---
105  result = ossimTiffTileSource::loadState(kwl, prefix);
106  }
107  }
108 
109  if (!result)
110  {
111  theProductXmlFile.clear();
112  }
113 
114  if (traceDebug())
115  {
117  << MODULE << " exit status = " << (result?"true":"false\n")
118  << std::endl;
119  }
120 
121  return result;
122 }
123 
125 {
126  return ossimString("ossim_radarsat2_tiff_reader");
127 }
128 
130 {
131  return ossimString("ossim RadarSAT-2 tiff reader");
132 }
133 
135 {
136  static const char MODULE[] = "ossimplugins::ossimRadarSat2TiffReader::open";
137 
138  if (traceDebug())
139  {
141  << MODULE << " entered...\n"
142  << "file: " << file << "\n";
143  }
144 
145  bool result = false;
146 
147  if ( isOpen() )
148  {
149  close();
150  }
151 
152  // Check extension to see if it's xml.
153  if ( file.ext().downcase() == "xml" )
154  {
155  ossimXmlDocument* xdoc = new ossimXmlDocument();
156  if ( xdoc->openFile(file) )
157  {
158  // See if it's a TerraSAR-X product xml file.
159  if ( isRadarSat2ProductFile(xdoc) )
160  {
161  ossimString s;
163 
164  if ( helper.getImageFile(xdoc, s) )
165  {
166  ossimFilename imageFile = file.expand().path();
167  imageFile = imageFile.dirCat(s);
168 
169  setFilename(imageFile);
170 
171  result = ossimTiffTileSource::open();
172  if (result)
173  {
174  theProductXmlFile = file;
175  completeOpen();
176  }
177  }
178  }
179  }
180  delete xdoc;
181  xdoc = 0;
182 
183  } // matches: if ( file.ext().downcase() == "xml" )
184 
185  if (traceDebug())
186  {
188  << MODULE << " exit status = " << (result?"true":"false\n")
189  << std::endl;
190  }
191 
192  return result;
193 }
194 
196 {
197  theProductXmlFile.clear();
199 }
200 
202 {
203  if ( !theGeometry )
204  {
205  //---
206  // Check for external geom:
207  //---
208  theGeometry = getExternalImageGeometry();
209 
210  if ( !theGeometry )
211  {
212  // Check the internal geometry first to avoid a factory call.
213  theGeometry = getInternalImageGeometry();
214 
215  // At this point it is assured theGeometry is set.
216 
217  //---
218  // WARNING:
219  // Must create/set theGeometry at this point or the next call to
220  // ossimImageGeometryRegistry::extendGeometry will put us in an infinite loop
221  // as it does a recursive call back to ossimImageHandler::getImageGeometry().
222  //---
223 
224  // Check for set projection.
225  if ( !theGeometry->getProjection() )
226  {
227  // Try factories for projection.
229  }
230  }
231 
232  // Set image things the geometry object should know about.
233  initImageParameters( theGeometry.get() );
234  }
235 
236  return theGeometry;
237 }
238 
241 {
242  static const char MODULE[] = "ossimplugins::ossimRadarSat2TiffReader::getInternalImageGeometry";
243  if (traceDebug())
244  {
245  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entered...\n";
246  }
247 
249 
250  ossimXmlDocument* xdoc = new ossimXmlDocument();
251  if ( xdoc->openFile(theProductXmlFile) )
252  {
254 
255  if ( model->open(theProductXmlFile) )
256  {
257  // Assign the model to our ossimImageGeometry object.
258  geom->setProjection( model.get() );
259  }
260  else
261  {
262  if (traceDebug())
263  {
264  ossimNotify(ossimNotifyLevel_DEBUG) << "WARNING: Unhandled projection: " << std::endl;
265  }
266  }
267  } // matches: if ( xdoc->openFile(theProductXmlFile) )
268 
269  delete xdoc;
270  xdoc = 0;
271 
272  if (traceDebug())
273  {
274  ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " exited..." << std::endl;
275  }
276 
277  return geom;
278 }
279 
281  const ossimFilename& file) const
282 {
283  bool result = false;
284 
285  // Check extension to see if it's xml.
286  if ( file.ext().downcase() == "xml" )
287  {
288  ossimXmlDocument* xdoc = new ossimXmlDocument();
289 
290  if ( xdoc->openFile(file) )
291  {
292  result = isRadarSat2ProductFile(xdoc);
293  }
294 
295  delete xdoc;
296  xdoc = 0;
297  }
298 
299  return result;
300 }
301 
303  const ossimXmlDocument* xdoc) const
304 {
305  bool result = false;
306 
307  if (xdoc)
308  {
310 
311  // See if it's a TerraSAR-X product xml file.
312  result = helper.isRadarSat2(xdoc);
313  }
314 
315  return result;
316 }
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.
bool open(const ossimFilename &file)
Method to intantial model from a file.
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.
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)
Represents serializable keyword/value map.
const char * find(const char *key) const
ossimFilename expand() const
Method to do file name expansion.
Class to encapsulate parsing RadarSat2 product.xml file.
bool getImageFile(const ossimXmlDocument *xdoc, ossimString &s) const
virtual bool extendGeometry(ossimImageHandler *handler) const
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
bool isRadarSat2(const ossimXmlDocument *xdoc) const
Checks for node /product/sourceAttributes/satellite containing RADARSAT-2.
bool openFile(const ossimFilename &filename)
bool isRadarSat2ProductFile(const ossimFilename &file) const
Method to check file to see if it&#39;s a RS2 product xml file.
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...
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
This class allows for direct localisation and indirect localisation using the RadarSat2 sensor model...
ossimFilename dirCat(const ossimFilename &file) const
ossimString ext() const
virtual ossimRefPtr< ossimImageGeometry > getInternalImageGeometry() const
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if non defined...
ossimFilename path() const
virtual ~ossimRadarSat2TiffReader()
virtual destructor
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.