OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Private Member Functions | Private Attributes | List of all members
ossimSrtmSupportData Class Reference

#include <ossimSrtmSupportData.h>

Inheritance diagram for ossimSrtmSupportData:
ossimObject ossimReferenced

Public Member Functions

 ossimSrtmSupportData ()
 default constructor More...
 
virtual ~ossimSrtmSupportData ()
 destructor More...
 
bool setFilename (const ossimFilename &srtmFile, bool scanForMinMax=false)
 Initializes object from file. More...
 
ossimFilename getFilename () const
 
ossim_uint32 getNumberOfLines () const
 
ossim_uint32 getNumberOfSamples () const
 
virtual bool getImageGeometry (ossimKeywordlist &kwl, const char *prefix=0)
 Populates the keyword list with image geometry information. More...
 
ossimRefPtr< ossimProjectiongetProjection () const
 Gets the projection for srtm cell. More...
 
virtual bool saveState (ossimKeywordlist &kwl, const char *prefix=0) const
 Method to save the state of the object to a keyword list. More...
 
virtual bool loadState (const ossimKeywordlist &kwl, const char *prefix=0)
 Method to the load (recreate) the state of the object from a keyword list. More...
 
ossim_float64 getSouthwestLatitude () const
 
ossim_float64 getSouthwestLongitude () const
 
ossim_float64 getLatitudeSpacing () const
 
ossim_float64 getLongitudeSpacing () const
 
ossim_float64 getMinPixelValue () const
 
ossim_float64 getMaxPixelValue () const
 
ossimScalarType getScalarType () const
 
virtual std::ostream & print (std::ostream &out) const
 Prints data members for debug. More...
 
- Public Member Functions inherited from ossimObject
 ossimObject ()
 
virtual ~ossimObject ()
 
virtual ossimObjectdup () const
 
virtual ossimString getShortName () const
 
virtual ossimString getLongName () const
 
virtual ossimString getDescription () const
 
virtual ossimString getClassName () const
 
virtual RTTItypeid getType () const
 
virtual bool canCastTo (ossimObject *obj) const
 
virtual bool canCastTo (const RTTItypeid &id) const
 
virtual bool canCastTo (const ossimString &parentClassName) const
 
virtual bool isEqualTo (const ossimObject &obj, ossimCompareType compareType=OSSIM_COMPARE_FULL) const
 
virtual void accept (ossimVisitor &visitor)
 
- Public Member Functions inherited from ossimReferenced
 ossimReferenced ()
 
 ossimReferenced (const ossimReferenced &)
 
ossimReferencedoperator= (const ossimReferenced &)
 
void ref () const
 increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void unref () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unref_nodelete () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
int referenceCount () const
 

Private Member Functions

bool loadOmd (const ossimKeywordlist &kwl, const char *prefix=0)
 This is a loadState called by setFilename that does not reset "theFile". More...
 
void clear ()
 Sets all data members to an unitialized state. More...
 
bool setCornerPoints ()
 Sets corner points from "theFile". More...
 
bool setSize ()
 Sets lines and samples from "theFile" size. More...
 
bool computeMinMax ()
 Scans file for min and max pixels. More...
 
template<class T >
bool computeMinMaxTemplate (T dummy, double defaultNull)
 

Private Attributes

ossimFilename m_file
 
ossim_uint32 m_numberOfLines
 
ossim_uint32 m_numberOfSamples
 
ossim_float64 m_southwestLatitude
 
ossim_float64 m_southwestLongitude
 
ossim_float64 m_latSpacing
 
ossim_float64 m_lonSpacing
 
ossim_float64 m_minPixelValue
 
ossim_float64 m_maxPixelValue
 
ossimScalarType m_scalarType
 
std::shared_ptr< ossim::istreamm_str
 

Additional Inherited Members

- Protected Member Functions inherited from ossimReferenced
virtual ~ossimReferenced ()
 

Detailed Description

Definition at line 35 of file ossimSrtmSupportData.h.

Constructor & Destructor Documentation

◆ ossimSrtmSupportData()

ossimSrtmSupportData::ossimSrtmSupportData ( )

default constructor

Definition at line 45 of file ossimSrtmSupportData.cpp.

46  :
47  m_file(),
48  m_numberOfLines(0),
54  m_minPixelValue(DEFAULT_MIN),
55  m_maxPixelValue(DEFAULT_MAX),
57  m_str(0)
58 {
59 }
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
ossimScalarType m_scalarType
ossim_float64 m_southwestLatitude
ossim_float64 m_southwestLongitude
std::shared_ptr< ossim::istream > m_str

◆ ~ossimSrtmSupportData()

ossimSrtmSupportData::~ossimSrtmSupportData ( )
virtual

destructor

Definition at line 61 of file ossimSrtmSupportData.cpp.

62 {
63 }

Member Function Documentation

◆ clear()

void ossimSrtmSupportData::clear ( )
private

Sets all data members to an unitialized state.

Definition at line 537 of file ossimSrtmSupportData.cpp.

References m_file, m_latSpacing, m_lonSpacing, m_minPixelValue, m_numberOfLines, m_numberOfSamples, m_southwestLatitude, m_southwestLongitude, ossim::nan(), and ossimFilename::NIL.

538 {
540  m_numberOfLines = 0;
541  m_numberOfSamples = 0;
546  m_minPixelValue = DEFAULT_MIN;
547  m_maxPixelValue = DEFAULT_MAX;
548 }
static const ossimFilename NIL
This was taken from Wx widgets for performing touch and access date stamps.
Definition: ossimFilename.h:40
double nan()
Method to return ieee floating point double precision NAN.
Definition: ossimCommon.h:135
ossim_float64 m_southwestLatitude
ossim_float64 m_southwestLongitude

◆ computeMinMax()

bool ossimSrtmSupportData::computeMinMax ( )
private

Scans file for min and max pixels.

true on success, false on error.

Definition at line 820 of file ossimSrtmSupportData.cpp.

References computeMinMaxTemplate(), m_scalarType, and OSSIM_FLOAT32.

821 {
823  {
825  -32768.0);
826  }
828  -32768.0);
829 }
float ossim_float32
32 bit floating point
bool computeMinMaxTemplate(T dummy, double defaultNull)
signed short ossim_sint16
ossimScalarType m_scalarType

◆ computeMinMaxTemplate()

template<class T >
bool ossimSrtmSupportData::computeMinMaxTemplate ( dummy,
double  defaultNull 
)
private

Definition at line 832 of file ossimSrtmSupportData.cpp.

References ossim::byteOrder(), ossim::StreamFactoryRegistry::createIstream(), ossim::defaultNull(), FLT_EPSILON, ossim::StreamFactoryRegistry::instance(), m_file, m_maxPixelValue, m_minPixelValue, m_numberOfLines, m_numberOfSamples, m_str, OSSIM_LITTLE_ENDIAN, and ossimEndian::swap().

Referenced by computeMinMax().

834 {
835 
836  if(!m_str)
837  {
838  m_str =
840  m_file);
841  }
842 
843  if (!m_str)
844  {
845  return false;
846  }
847 
848  if(m_str->fail())
849  {
850  return false;
851  }
852 
853  const size_t BYTES_IN_LINE = m_numberOfSamples * 2;
854  const T NULL_PIX = (T)defaultNull;
855 
856  double minValue = 1.0/FLT_EPSILON;
857  double maxValue = -1.0/FLT_EPSILON;
858  T* line_buf = new T[m_numberOfSamples];
859  char* char_buf = (char*)line_buf;
860  ossimEndian swapper;
861 
862  ossimByteOrder endianType = ossim::byteOrder();
863  for (ossim_uint32 line = 0; line < m_numberOfLines; ++line)
864  {
865  m_str->read(char_buf, (std::streamsize)BYTES_IN_LINE);
866  if(endianType == OSSIM_LITTLE_ENDIAN)
867  {
868  swapper.swap(line_buf, m_numberOfSamples);
869  }
870  for (ossim_uint32 sample = 0; sample < m_numberOfSamples; ++sample)
871  {
872  if (line_buf[sample] == NULL_PIX) continue;
873  if (line_buf[sample] > maxValue) maxValue = line_buf[sample];
874  if (line_buf[sample] < minValue) minValue = line_buf[sample];
875  }
876  }
877  delete [] line_buf;
878  m_minPixelValue = minValue;
879  m_maxPixelValue = maxValue;
880 
881  m_str = 0;
882  return true;
883 }
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
static StreamFactoryRegistry * instance()
#define FLT_EPSILON
OSSIM_DLL double defaultNull(ossimScalarType scalarType)
unsigned int ossim_uint32
ossimByteOrder
std::shared_ptr< ossim::istream > m_str
virtual std::shared_ptr< ossim::istream > createIstream(const std::string &connectionString, const ossimKeywordlist &options=ossimKeywordlist(), std::ios_base::openmode mode=std::ios_base::in|std::ios_base::binary) const
Will try to creates an istream interface to the connectionString passed in.
void swap(ossim_sint8 &)
Definition: ossimEndian.h:26

◆ getFilename()

ossimFilename ossimSrtmSupportData::getFilename ( ) const
Returns
Returns the srtm file name.

Definition at line 182 of file ossimSrtmSupportData.cpp.

References m_file.

183 {
184  return m_file;
185 }

◆ getImageGeometry()

bool ossimSrtmSupportData::getImageGeometry ( ossimKeywordlist kwl,
const char *  prefix = 0 
)
virtual

Populates the keyword list with image geometry information.

This method is used to relay projection information to users.

Parameters
kwlKeyword list that will be initialized with geometry info. Returns true if geometry info is present, false if not.
prefixThe prefix is added to the resulting keyword list keywords. So is you if you pass in a prefix of "image01.", the keyword ul_lat will be like: "image01.ul_lat: -40.00000"

Definition at line 197 of file ossimSrtmSupportData.cpp.

References ossimKeywordlist::add(), ossimKeywordNames::CENTRAL_MERIDIAN_KW, ossimKeywordNames::DATUM_KW, ossimKeywordNames::DECIMAL_DEGREES_PER_PIXEL_LAT, ossimKeywordNames::DECIMAL_DEGREES_PER_PIXEL_LON, ossimDatumFactory::instance(), m_file, m_latSpacing, m_lonSpacing, m_numberOfLines, m_numberOfSamples, m_southwestLatitude, m_southwestLongitude, ossimFilename::NIL, ossimKeywordNames::NUMBER_LINES_KW, ossimKeywordNames::NUMBER_SAMPLES_KW, ossimKeywordNames::ORIGIN_LATITUDE_KW, ossimKeywordNames::TIE_POINT_LAT_KW, ossimKeywordNames::TIE_POINT_LON_KW, and ossimKeywordNames::TYPE_KW.

199 {
200  if (m_file == ossimFilename::NIL)
201  {
202  return false;
203  }
204 
205  kwl.add(prefix,
207  "ossimEquDistCylProjection",
208  true);
209 
210  kwl.add(prefix,
212  0.0,
213  true);
214 
215  kwl.add(prefix,
218  true);
219 
220  kwl.add(prefix,
222  (m_southwestLatitude+1.0),
223  true);
224 
225  kwl.add(prefix,
228  true);
229 
230  // Add the pixel scale.
231  kwl.add(prefix,
233  m_latSpacing,
234  true);
235 
236  kwl.add(prefix,
238  m_lonSpacing,
239  true);
240 
241  // Add the datum. (always WGS-84 per spec)
242  kwl.add(prefix,
244  ossimDatumFactory::instance()->wgs84()->code(),
245  true);
246 
247  // Add the number of lines and samples.
248  kwl.add(prefix,
251  true);
252 
253  kwl.add(prefix,
256  true);
257 
258  return true;
259 }
static const char * DECIMAL_DEGREES_PER_PIXEL_LAT
static const char * DATUM_KW
static const ossimFilename NIL
This was taken from Wx widgets for performing touch and access date stamps.
Definition: ossimFilename.h:40
static const char * CENTRAL_MERIDIAN_KW
static const char * NUMBER_LINES_KW
static const char * TIE_POINT_LON_KW
static const char * TYPE_KW
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
static ossimDatumFactory * instance()
static const char * DECIMAL_DEGREES_PER_PIXEL_LON
static const char * ORIGIN_LATITUDE_KW
ossim_float64 m_southwestLatitude
ossim_float64 m_southwestLongitude
static const char * TIE_POINT_LAT_KW
static const char * NUMBER_SAMPLES_KW

◆ getLatitudeSpacing()

ossim_float64 ossimSrtmSupportData::getLatitudeSpacing ( ) const
Returns
Returns the latitude spacing in decimal degrees. Returns OSSIM_DBL_NAN if not initialized or file was invalid.

Definition at line 527 of file ossimSrtmSupportData.cpp.

References m_latSpacing.

Referenced by ossimSrtmHandler::open().

528 {
529  return m_latSpacing;
530 }

◆ getLongitudeSpacing()

ossim_float64 ossimSrtmSupportData::getLongitudeSpacing ( ) const
Returns
Returns the longitude spacing in decimal degrees. Returns OSSIM_DBL_NAN if not initialized or file was invalid.

Definition at line 532 of file ossimSrtmSupportData.cpp.

References m_lonSpacing.

Referenced by ossimSrtmHandler::open().

533 {
534  return m_lonSpacing;
535 }

◆ getMaxPixelValue()

ossim_float64 ossimSrtmSupportData::getMaxPixelValue ( ) const
Returns
Returns the maximum pixel value. This is also the minimum height above sea level. Returns OSSIM_SSHORT_NAN if not initialized or file was invalid.

Definition at line 890 of file ossimSrtmSupportData.cpp.

References m_maxPixelValue.

891 {
892  return m_maxPixelValue;
893 }

◆ getMinPixelValue()

ossim_float64 ossimSrtmSupportData::getMinPixelValue ( ) const
Returns
Returns the minimum pixel value. This is also the minimum height above sea level. Returns OSSIM_SSHORT_NAN if not initialized or file was invalid.

Definition at line 885 of file ossimSrtmSupportData.cpp.

References m_minPixelValue.

886 {
887  return m_minPixelValue;
888 }

◆ getNumberOfLines()

ossim_uint32 ossimSrtmSupportData::getNumberOfLines ( ) const
Returns
Returns the number of lines or rows. Returns OSSIM_UINT_NAN if not initialized or file was invalid.

Definition at line 187 of file ossimSrtmSupportData.cpp.

References m_numberOfLines.

Referenced by ossimSrtmHandler::open().

188 {
189  return m_numberOfLines;
190 }

◆ getNumberOfSamples()

ossim_uint32 ossimSrtmSupportData::getNumberOfSamples ( ) const
Returns
Returns the number of samples or columns. Returns OSSIM_UINT_NAN if not initialized or file was invalid.

Definition at line 192 of file ossimSrtmSupportData.cpp.

References m_numberOfSamples.

Referenced by ossimSrtmHandler::open().

193 {
194  return m_numberOfSamples;
195 }

◆ getProjection()

ossimRefPtr< ossimProjection > ossimSrtmSupportData::getProjection ( ) const

Gets the projection for srtm cell.

Returns
The projection for srtm cell.

Definition at line 261 of file ossimSrtmSupportData.cpp.

References ossimDatum::ellipsoid(), ossimRefPtr< T >::get(), ossimDatumFactory::instance(), m_latSpacing, m_lonSpacing, m_southwestLatitude, m_southwestLongitude, ossimMapProjection::setDecimalDegreesPerPixel(), ossimMapProjection::setUlTiePoints(), and ossimDatumFactory::wgs84().

262 {
263  //---
264  // Make an Equidistant Cylindrical projection with a origin at the equator
265  // since the DTED post spacing is considered to be square.
266  //---
267  const ossimDatum* datum = ossimDatumFactory::instance()->wgs84();
269 
270  //---
271  // Set the tie point.
272  // NOTE: Latitude southwest corner we need northwest; hence, the +1.
273  //---
275 
276  // Set the scale:
278 
279  ossimRefPtr<ossimProjection> proj = eq.get();
280 
281  return proj;
282 }
virtual void setDecimalDegreesPerPixel(const ossimDpt &gsd)
virtual const ossimEllipsoid * ellipsoid() const
Definition: ossimDatum.h:60
static ossimDatumFactory * instance()
ossim_float64 m_southwestLatitude
ossim_float64 m_southwestLongitude
virtual void setUlTiePoints(const ossimGpt &gpt)
const ossimDatum * wgs84() const

◆ getScalarType()

ossimScalarType ossimSrtmSupportData::getScalarType ( ) const

Definition at line 895 of file ossimSrtmSupportData.cpp.

References m_scalarType.

Referenced by ossimSrtmHandler::open().

896 {
897  return m_scalarType;
898 }
ossimScalarType m_scalarType

◆ getSouthwestLatitude()

ossim_float64 ossimSrtmSupportData::getSouthwestLatitude ( ) const
Returns
Returns the Southwest latitude in decimal degrees. Returns OSSIM_DBL_NAN if not initialized or file was invalid.

Definition at line 518 of file ossimSrtmSupportData.cpp.

References m_southwestLatitude.

Referenced by ossimSrtmHandler::open().

519 {
520  return m_southwestLatitude;
521 }
ossim_float64 m_southwestLatitude

◆ getSouthwestLongitude()

ossim_float64 ossimSrtmSupportData::getSouthwestLongitude ( ) const
Returns
Returns the Southwest longitude in decimal degrees. Returns OSSIM_DBL_NAN if not initialized or file was invalid.

Definition at line 523 of file ossimSrtmSupportData.cpp.

References m_southwestLongitude.

Referenced by ossimSrtmHandler::open().

524 {
525  return m_southwestLongitude;
526 }
ossim_float64 m_southwestLongitude

◆ loadOmd()

bool ossimSrtmSupportData::loadOmd ( const ossimKeywordlist kwl,
const char *  prefix = 0 
)
private

This is a loadState called by setFilename that does not reset "theFile".

Definition at line 418 of file ossimSrtmSupportData.cpp.

References ossimKeywordlist::findKey(), ossimLookUpTable::getEntryNumber(), ossimScalarTypeLut::instance(), m_latSpacing, m_lonSpacing, m_maxPixelValue, m_minPixelValue, m_numberOfLines, m_numberOfSamples, m_scalarType, m_southwestLatitude, m_southwestLongitude, ossimKeywordNames::MAX_VALUE_KW, ossimKeywordNames::MIN_VALUE_KW, ossimLookUpTable::NOT_FOUND, ossimKeywordNames::NUMBER_LINES_KW, ossimKeywordNames::NUMBER_SAMPLES_KW, OSSIM_FLOAT32, OSSIM_SINT16, ossimString::size(), ossimString::string(), ossimKeywordNames::TIE_POINT_LAT_KW, ossimKeywordNames::TIE_POINT_LON_KW, ossimString::toFloat64(), and ossimString::toUInt32().

Referenced by loadState().

420 {
421  std::string pfx;
422  std::string bandPrefix;
423 
424  if (prefix) // Cannot give null to std::string.
425  {
426  pfx = prefix;
427  bandPrefix = prefix;
428  }
429  bandPrefix += "band1.";
430 
431  ossimString value;
432 
433  //---
434  // Look for the min and max first since they could have been populated by
435  // "cmm" (compute min max). Min and Max are not required by this method
436  // as they are handled elsewhere if they are not found here.
437  //---
438 
439  // Not an error if not present.
440  value.string() = kwl.findKey(bandPrefix, std::string(ossimKeywordNames::MIN_VALUE_KW));
441  if ( value.size() )
442  {
443  m_minPixelValue = value.toFloat64();
444  }
445 
446  // Not an error if not present.
447  value.string() = kwl.findKey(bandPrefix.c_str(), std::string(ossimKeywordNames::MAX_VALUE_KW));
448  if ( value.size() )
449  {
450  m_maxPixelValue = value.toFloat64();
451  }
452 
453  value.string() = kwl.findKey(pfx, std::string(ossimKeywordNames::NUMBER_LINES_KW));
454  if ( value.size() )
455  {
456  m_numberOfLines = value.toUInt32();
457  }
458  else
459  {
460  return false;
461  }
462 
463  value.string() = kwl.findKey(pfx, std::string(ossimKeywordNames::NUMBER_SAMPLES_KW));
464  if ( value.size() )
465  {
466  m_numberOfSamples = value.toUInt32();
467  }
468  else
469  {
470  return false;
471  }
472 
473  //---
474  // Special case the tie point was stored as the upper left so we must
475  // subtract one.
476  //---
477  value.string() = kwl.findKey(pfx, std::string(ossimKeywordNames::TIE_POINT_LAT_KW));
478  if ( value.size() )
479  {
480  m_southwestLatitude = value.toFloat64() - 1.0;
481  }
482  else
483  {
484  return false;
485  }
486 
487  value.string() = kwl.findKey(pfx, std::string(ossimKeywordNames::TIE_POINT_LON_KW));
488  if ( value.size() )
489  {
491  }
492  else
493  {
494  return false;
495  }
496 
497  int scalar = ossimScalarTypeLut::instance()->getEntryNumber(kwl, prefix);
498 
499  if (scalar != ossimLookUpTable::NOT_FOUND)
500  {
501  m_scalarType = (ossimScalarType)scalar;
503  {
504  return false;
505  }
506  }
507  else
508  {
509  return false;
510  }
511 
512  m_latSpacing = 1.0 / (m_numberOfLines - 1);
513  m_lonSpacing = 1.0 / (m_numberOfSamples - 1);
514 
515  return true;
516 }
static const char * MIN_VALUE_KW
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
static const char * MAX_VALUE_KW
static const char * NUMBER_LINES_KW
static const char * TIE_POINT_LON_KW
16 bit signed integer
ossim_uint32 toUInt32() const
32 bit floating point
virtual ossim_int32 getEntryNumber(const char *entry_string, bool case_insensitive=true) const
static ossimScalarTypeLut * instance()
Returns the static instance of an ossimScalarTypeLut object.
std::string::size_type size() const
Definition: ossimString.h:405
ossim_float64 toFloat64() const
ossimScalarType m_scalarType
ossimScalarType
ossim_float64 m_southwestLatitude
ossim_float64 m_southwestLongitude
static const char * TIE_POINT_LAT_KW
static const char * NUMBER_SAMPLES_KW
const std::string & string() const
Definition: ossimString.h:414

◆ loadState()

bool ossimSrtmSupportData::loadState ( const ossimKeywordlist kwl,
const char *  prefix = 0 
)
virtual

Method to the load (recreate) the state of the object from a keyword list.

Return true if ok or false on error.

Reimplemented from ossimObject.

Definition at line 381 of file ossimSrtmSupportData.cpp.

References ossimKeywordNames::FILENAME_KW, ossimKeywordlist::find(), ossimKeywordNames::IMAGE_FILE_KW, loadOmd(), and m_file.

383 {
384  ossimString bandPrefix;
385  if (prefix)
386  {
387  bandPrefix = prefix;
388  }
389  bandPrefix += "band1.";
390 
391  ossimString s; // For numeric conversions.
392 
393  const char* lookup;
394 
395  // Look for "filename" then look for deprecated "image_file" next.
396  lookup = kwl.find(prefix, ossimKeywordNames::FILENAME_KW);
397  if (lookup)
398  {
399  m_file = lookup;
400  }
401  else
402  {
403  // Deprecated...
404  lookup = kwl.find(prefix, ossimKeywordNames::IMAGE_FILE_KW);
405  if (lookup)
406  {
407  m_file = lookup;
408  }
409  else
410  {
411  return false;
412  }
413  }
414 
415  return loadOmd(kwl, prefix);
416 }
const char * find(const char *key) const
bool loadOmd(const ossimKeywordlist &kwl, const char *prefix=0)
This is a loadState called by setFilename that does not reset "theFile".
static const char * IMAGE_FILE_KW
static const char * FILENAME_KW

◆ print()

std::ostream & ossimSrtmSupportData::print ( std::ostream &  out) const
virtual

Prints data members for debug.

Returns
std::ostream&

Reimplemented from ossimObject.

Definition at line 900 of file ossimSrtmSupportData.cpp.

References m_file, m_latSpacing, m_lonSpacing, m_maxPixelValue, m_minPixelValue, m_numberOfLines, m_numberOfSamples, m_southwestLatitude, and m_southwestLongitude.

901 {
902  out << std::setprecision(15) << "ossimSrtmSupportData data members:"
903  << "\nFile: " << m_file
904  << "\nLines: " << m_numberOfLines
905  << "\nSamples: " << m_numberOfSamples
906  << "\nSouth West Latitude: " << m_southwestLatitude
907  << "\nSouth West Longitude: " << m_southwestLongitude
908  << "\nLatitude spacing: " << m_latSpacing
909  << "\nLongitude spacing: " << m_lonSpacing
910  << "\nMin post value: " << m_minPixelValue
911  << "\nMax post value: " << m_maxPixelValue
912  << std::endl;
913  return out;
914 }
ossim_float64 m_southwestLatitude
ossim_float64 m_southwestLongitude

◆ saveState()

bool ossimSrtmSupportData::saveState ( ossimKeywordlist kwl,
const char *  prefix = 0 
) const
virtual

Method to save the state of the object to a keyword list.

Return true if ok or false on error.

Reimplemented from ossimObject.

Definition at line 284 of file ossimSrtmSupportData.cpp.

References ossimKeywordlist::add(), ossimString::c_str(), ossimKeywordNames::DECIMAL_DEGREES_PER_PIXEL_LAT, ossimKeywordNames::DECIMAL_DEGREES_PER_PIXEL_LON, ossimKeywordNames::FILENAME_KW, m_file, m_latSpacing, m_lonSpacing, m_minPixelValue, m_numberOfLines, m_numberOfSamples, m_southwestLatitude, m_southwestLongitude, ossimFilename::NIL, ossimKeywordNames::NUMBER_BANDS_KW, ossimKeywordNames::NUMBER_LINES_KW, ossimKeywordNames::NUMBER_SAMPLES_KW, ossimKeywordNames::TIE_POINT_LAT_KW, and ossimKeywordNames::TIE_POINT_LON_KW.

286 {
287  if (m_file == ossimFilename::NIL)
288  {
289  return false;
290  }
291 
292  ossimString bandPrefix;
293  if (prefix)
294  {
295  bandPrefix = prefix;
296  }
297  bandPrefix += "band1.";
298 
299  kwl.add(prefix,
301  m_file.c_str(),
302  true);
303 
304  kwl.add(prefix,
306  1,
307  true);
308 
309  kwl.add(prefix,
312  true);
313 
314  kwl.add(prefix,
317  true);
318 
319  //---
320  // Special case, store the tie point as the upper left lat so add one.
321  //---
322  kwl.add(prefix,
324  (m_southwestLatitude + 1.0),
325  true);
326 
327  kwl.add(prefix,
330  true);
331 
332  kwl.add(prefix,
334  m_latSpacing,
335  true);
336 
337  kwl.add(prefix,
339  m_lonSpacing,
340  true);
341 
342  // User can opt out of scanning for this so don't save if it is still nan.
343  if (m_minPixelValue != DEFAULT_MIN)
344  {
345  kwl.add(bandPrefix,
348  true);
349  }
350 
351  // User can opt out of scanning for this so don't save if it is still nan.
352  if (m_maxPixelValue != DEFAULT_MAX)
353  {
354  kwl.add(bandPrefix.c_str(),
357  true);
358  }
359 
360  // constant
361  kwl.add(bandPrefix,
363  "-32768",
364  true);
365 
366  // constant
367  kwl.add(prefix,
369  "big_endian",
370  true);
371 
372  // constant
373  kwl.add(prefix,
375  ossimScalarTypeLut::instance()->getEntryString(m_scalarType),
376  true);
377 
378  return true;
379 }
static const char * BYTE_ORDER_KW
static const char * MIN_VALUE_KW
static const char * DECIMAL_DEGREES_PER_PIXEL_LAT
static const ossimFilename NIL
This was taken from Wx widgets for performing touch and access date stamps.
Definition: ossimFilename.h:40
static const char * MAX_VALUE_KW
static const char * NULL_VALUE_KW
static const char * NUMBER_LINES_KW
static const char * TIE_POINT_LON_KW
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
static ossimScalarTypeLut * instance()
Returns the static instance of an ossimScalarTypeLut object.
static const char * DECIMAL_DEGREES_PER_PIXEL_LON
static const char * NUMBER_BANDS_KW
ossimScalarType m_scalarType
ossim_float64 m_southwestLatitude
ossim_float64 m_southwestLongitude
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
static const char * SCALAR_TYPE_KW
static const char * TIE_POINT_LAT_KW
static const char * FILENAME_KW
static const char * NUMBER_SAMPLES_KW

◆ setCornerPoints()

bool ossimSrtmSupportData::setCornerPoints ( )
private

Sets corner points from "theFile".

Returns
true on success, false on error.

Definition at line 550 of file ossimSrtmSupportData.cpp.

551 {
552  if(traceDebug())
553  {
555  << "ossimSrtmSupportData::setCornerPoints(): entered..." << std::endl;
556  }
557 
559  ossimString regularExp1 = "[N|S][0-9][0-9][E|W][0-9][0-9][0-9]";
560  ossimString regularExp2 = "[E|W][0-9][0-9][0-9][N|S][0-9][0-9]";
561  ossimRegExp regEx;
562  bool latLonOrderFlag = true;
563  bool foundFlag = false;
564  f = f.upcase();
565 
566  regEx.compile(regularExp1.c_str());
567  foundFlag = regEx.find(f.c_str());
568  if(!foundFlag)
569  {
570  regEx.compile(regularExp2.c_str());
571  foundFlag = regEx.find(f.c_str());
572  if(foundFlag)
573  {
574  latLonOrderFlag = false;
575  f = ossimFilename(ossimString(f.begin()+regEx.start(),
576  f.begin()+regEx.end()));
577  }
578  }
579  if(foundFlag)
580  {
581  f = ossimFilename(ossimString(f.begin()+regEx.start(),
582  f.begin()+regEx.end()));
583  }
584  if (f.size() != 7)
585  {
586  return false;
587  }
588 // ossimString s;
589 
590  if(latLonOrderFlag)
591  {
592 
593 // s.push_back(f[1]);
594 // s.push_back(f[2]);
596  f.begin()+3).toDouble();//s.toDouble();
597  // Get the latitude.
598  if (f[static_cast<std::string::size_type>(0)] == 'S')
599  {
600  m_southwestLatitude *= -1;
601  }
602  else if (f[static_cast<std::string::size_type>(0)] != 'N')
603  {
604  return false; // Must be either 's' or 'n'.
605  }
606  // Get the longitude.
607 // s.clear();
608 // s.push_back(f[4]);
609 // s.push_back(f[5]);
610 // s.push_back(f[6]);
612  f.begin()+7).toDouble();//s.toDouble();
613  if (f[static_cast<std::string::size_type>(3)] == 'W')
614  {
615  m_southwestLongitude *= -1;
616  }
617  else if (f[static_cast<std::string::size_type>(3)] != 'E')
618  {
619  return false; // Must be either 'e' or 'w'.
620  }
621  }
622  else
623  {
624  // Get the longitude.
625 // s.clear();
626 // s.push_back(f[1]);
627 // s.push_back(f[2]);
628 // s.push_back(f[3]);
630  f.begin()+4).toDouble();//s.toDouble();
631  if (f[static_cast<std::string::size_type>(0)] == 'W')
632  {
633  m_southwestLongitude *= -1;
634  }
635  else if (f[static_cast<std::string::size_type>(0)] != 'E')
636  {
637  return false; // Must be either 'e' or 'w'.
638  }
639 // s.clear();
640 
641 // s.push_back(f[5]);
642 // s.push_back(f[6]);
644  f.begin()+7).toDouble();//s.toDouble();
645  // Get the latitude.
646  if (f[static_cast<std::string::size_type>(4)] == 'S')
647  {
648  m_southwestLatitude *= -1;
649  }
650  else if (f[static_cast<std::string::size_type>(4)] != 'N')
651  {
652  return false; // Must be either 's' or 'n'.
653  }
654  }
655 
656 
657  if(traceDebug())
658  {
660  << "ossimSrtmSupportData::setCornerPoints(): leaving with true..."
661  << std::endl;
662  }
663  return true;
664 }
static ossimString upcase(const ossimString &aString)
Definition: ossimString.cpp:34
std::string::size_type size() const
Definition: ossimString.h:405
std::string::iterator begin()
Definition: ossimString.h:420
void compile(const char *)
ossim_uint32 start() const
Definition: ossimRegExp.h:209
ossim_uint32 end() const
Definition: ossimRegExp.h:217
ossim_float64 m_southwestLatitude
ossim_float64 m_southwestLongitude
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 find(const char *)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ setFilename()

bool ossimSrtmSupportData::setFilename ( const ossimFilename srtmFile,
bool  scanForMinMax = false 
)

Initializes object from file.

File is expected to be in a format like N27W081.hgt or n27w081.hgt where "N27" is the South West latitude of the cell and "W081" is the South West longitude of the cell.

Parameters
srtmFileFile to set.
scanForMinMaxIf true and there is no ossim meta data file with the min and max keywords in it, this will call computeMinMax which will scan the file for min and max.
Returns
Returns true if file is deemed to be an srtm, false if not.
Note
This will write an ossim meta data (.omd) if one does not exists.

Definition at line 65 of file ossimSrtmSupportData.cpp.

References m_file.

Referenced by ossimSrtmHandler::open().

67 {
68  m_file = srtmFile;
69 
70  if(traceDebug())
71  {
73  << "ossimSrtmSupportData::setFilename: entered:"
74  << "\nsrtmFile: " << srtmFile
75  << "\nscanForMinMax flag: " << scanForMinMax
76  << std::endl;
77  }
78 
80  createIstream(m_file);
81  if (m_str)
82  {
83  if(m_str->fail())
84  {
85  if(traceDebug())
86  {
88  << m_file << " does not exist: leaving ..." << std::endl;
89  }
90  clear();
91  return false;
92  }
93  }
94  else
95  {
96  return false;
97  }
98 
99  // Start with default.
100  m_minPixelValue = DEFAULT_MIN;
101  m_maxPixelValue = DEFAULT_MAX;
102 
103  // See if we have an ossim metadata file to initialize from.
104  bool outputOmd = false;
105  bool loadedFromOmd = false;
106 
107  ossimFilename omdFile = m_file;
108  omdFile.setExtension(ossimString("omd"));
109  if (omdFile.exists())
110  {
111  //---
112  // The loadOmd is called instead of loadState so m_file is not
113  // overwrote.
114  //---
115  ossimKeywordlist kwl(omdFile);
116  loadedFromOmd = loadOmd(kwl);
117  }
118 
119  if (!loadedFromOmd)
120  {
121  if (!setCornerPoints())
122  {
123  clear();
124  return false;
125  }
126  if (!setSize())
127  {
128  clear();
129  return false;
130  }
131  outputOmd = true;
132  }
133 
134  if (scanForMinMax)
135  {
136  // These could have been picked up in the loadOmd.
137  if ( (m_minPixelValue == DEFAULT_MIN) ||
138  (m_maxPixelValue == DEFAULT_MAX) )
139  {
140  if ( computeMinMax() )
141  {
142  outputOmd = true;
143  }
144  else
145  {
146  if(traceDebug())
147  {
149  << "Unable to compute min max: leaving ..." << std::endl;
150  }
151  clear();
152  return false;
153  }
154  }
155  }
156 
157  //---
158  // NOTE: The outputOmd flag should probably be set if !loadedFromOmd.
159  // Leaving as is for now (only set if scanForMinMax).
160  //---
161  if (outputOmd)
162  {
163  ossimKeywordlist kwl;
164  saveState(kwl);
165  kwl.write(omdFile);
166  }
167 
168  m_str = 0;
169  // if(m_str->is_open())
170  // {
171  // m_str->close();
172  // }
173 
174  if (traceDebug())
175  {
176  ossimNotify(ossimNotifyLevel_DEBUG) << *this << std::endl;
177  }
178 
179  return true;
180 }
bool setCornerPoints()
Sets corner points from "theFile".
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of the object to a keyword list.
Represents serializable keyword/value map.
bool setSize()
Sets lines and samples from "theFile" size.
static StreamFactoryRegistry * instance()
virtual bool write(const char *file, const char *comment=0) const
Methods to dump the ossimKeywordlist to a file on disk.
bool exists() const
void clear()
Sets all data members to an unitialized state.
bool computeMinMax()
Scans file for min and max pixels.
bool loadOmd(const ossimKeywordlist &kwl, const char *prefix=0)
This is a loadState called by setFilename that does not reset "theFile".
std::shared_ptr< ossim::istream > m_str
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ setSize()

bool ossimSrtmSupportData::setSize ( )
private

Sets lines and samples from "theFile" size.

Returns
true on success, false on error.

Definition at line 666 of file ossimSrtmSupportData.cpp.

667 {
668  if(traceDebug())
669  {
671  << "ossimSrtmSupportData::setSize(): entered..." << std::endl;
672  }
673  if(!m_str)
674  {
676  m_file);
677  }
678 
679  if (!m_str)
680  {
681  return false;
682  }
683 
684  if(m_str->fail())
685  {
686  return false;
687  }
688 
689  ossim_float64 size = 0.0;
690  m_str->seekg(0, std::ios::beg);
691 
692 #if 0 /* tmp drb */
693  if(m_str->isCompressed())
694  {
695  ossimFilename tmp = m_file;
696  tmp.setExtension("hgt");
697  if(!tmp.exists())
698  {
699  ossimOFStream out(tmp.c_str(),
700  std::ios::out|std::ios::binary);
701 
702  if(!out.fail())
703  {
704  bool done = false;
705  char buf[1024];
706  while(!done&&!m_str->fail())
707  {
708  m_str->read(buf, 1024);
709  if(m_str->gcount() < 1024)
710  {
711  done = true;
712  }
713  if(m_str->gcount() > 0)
714  {
715  out.write(buf, m_str->gcount());
716  }
717  }
718  out.close();
719  size = tmp.fileSize();
720  tmp.remove();
721  }
722  }
723  }
724  else
725  {
726  size = m_file.fileSize();
727  }
728 #endif /* tmp drb */
729 
730  size = m_file.fileSize();
731  if (!size)
732  {
733  if(traceDebug())
734  {
736  << "ossimSrtmSupportData::setSize(): leaving with false at line "
737  << __LINE__ << std::endl;
738  }
739  return false;
740  }
741 
743 
744  //---
745  // Assuming square for now. Have to check the spec for this.
746  //---
747  if (size == 25934402) // 2 * 3601 * 3601 three arc second
748  {
749  m_numberOfLines = 3601;
750  m_numberOfSamples = 3601;
752  }
753  else if(size == 51868804) // 4*3601*3601
754  {
755  m_numberOfLines = 3601;
756  m_numberOfSamples = 3601;
758  }
759  else if (size == 2884802) // 2 * 1201 * 1201 one arc second
760  {
761  m_numberOfLines = 1201;
762  m_numberOfSamples = 1201;
764  }
765  else if (size == 5769604)
766  {
767  m_numberOfLines = 1201;
768  m_numberOfSamples = 1201;
770  }
771  else // try to get a square width and height
772  {
773  ossim_uint64 lines = (ossim_uint64)sqrt((ossim_float64)(size / 2));
774  ossim_uint64 samples = (ossim_uint64)sqrt((ossim_float64)(size / 2));
775  // check square
776  if(lines*samples*2 == size)
777  {
778  m_numberOfLines = lines;
779  m_numberOfSamples = samples;
781 
782  }
783  else
784  {
785  ossim_uint64 lines = (ossim_uint64)sqrt((ossim_float64)(size / 4));
786  ossim_uint64 samples = (ossim_uint64)sqrt((ossim_float64)(size / 4));
787  // check square
788  if(lines*samples*4 == size)
789  {
790  m_numberOfLines = lines;
791  m_numberOfSamples = samples;
793  }
794  else
795  {
796  if(traceDebug())
797  {
799  << "ossimSrtmSupportData::setSize(): leaving with false at line " << __LINE__ << std::endl;
800  }
801  return false;
802  }
803  }
804  }
805 
806  m_latSpacing = 1.0 / (m_numberOfLines - 1);
807  m_lonSpacing = 1.0 / (m_numberOfSamples - 1);
808  if(traceDebug())
809  {
811  << "ossimSrtmSupportData::setSize(): leaving with true..."
812  << std::endl;
813  }
814 
815  m_str=0;
816 
817  return true;
818 }
static bool remove(const ossimFilename &pathname)
Removes pathname from filesystem if supported by platform.
ossim_int64 fileSize() const
16 bit signed integer
static StreamFactoryRegistry * instance()
32 bit floating point
double ossim_float64
yy_size_t size
bool exists() const
unsigned long long ossim_uint64
ossimScalarType m_scalarType
std::shared_ptr< ossim::istream > m_str
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
virtual std::shared_ptr< ossim::istream > createIstream(const std::string &connectionString, const ossimKeywordlist &options=ossimKeywordlist(), std::ios_base::openmode mode=std::ios_base::in|std::ios_base::binary) const
Will try to creates an istream interface to the connectionString passed in.
ossimFilename & setExtension(const ossimString &e)
Sets the extension of a file name.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

Member Data Documentation

◆ m_file

ossimFilename ossimSrtmSupportData::m_file
private

◆ m_latSpacing

ossim_float64 ossimSrtmSupportData::m_latSpacing
private

◆ m_lonSpacing

ossim_float64 ossimSrtmSupportData::m_lonSpacing
private

◆ m_maxPixelValue

ossim_float64 ossimSrtmSupportData::m_maxPixelValue
private

Definition at line 195 of file ossimSrtmSupportData.h.

Referenced by computeMinMaxTemplate(), getMaxPixelValue(), loadOmd(), and print().

◆ m_minPixelValue

ossim_float64 ossimSrtmSupportData::m_minPixelValue
private

◆ m_numberOfLines

ossim_uint32 ossimSrtmSupportData::m_numberOfLines
private

◆ m_numberOfSamples

ossim_uint32 ossimSrtmSupportData::m_numberOfSamples
private

◆ m_scalarType

ossimScalarType ossimSrtmSupportData::m_scalarType
private

Definition at line 197 of file ossimSrtmSupportData.h.

Referenced by computeMinMax(), getScalarType(), and loadOmd().

◆ m_southwestLatitude

ossim_float64 ossimSrtmSupportData::m_southwestLatitude
private

◆ m_southwestLongitude

ossim_float64 ossimSrtmSupportData::m_southwestLongitude
private

◆ m_str

std::shared_ptr<ossim::istream> ossimSrtmSupportData::m_str
mutableprivate

Definition at line 200 of file ossimSrtmSupportData.h.

Referenced by computeMinMaxTemplate().


The documentation for this class was generated from the following files: