OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimERSFileWriter.cpp
Go to the documentation of this file.
1 //----------------------------------------------------------------------------
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Andrew Huang
6 //
7 // Description:
8 //
9 // Class declaration for ossimERSFileWriter. Meta data class for
10 // writing an ERS header file.
11 //
12 //----------------------------------------------------------------------------
13 // $Id: ossimERSFileWriter.cpp 21631 2012-09-06 18:10:55Z dburken $
14 
18 #include <ossim/base/ossimIrect.h>
24 
25 
27  "ossimERSFileWriter",
29 
31  :
33  theHdr()
34 {
35 }
36 
38 {
39 }
40 
42  const char* prefix)
43 {
44  // To pick up output filename.
45  return ossimMetadataFileWriter::loadState(kwl, prefix);
46 }
47 
49 {
50  ossimString tmp;
51 
52  theHdr.theDatasetType = "ERStorage";
53  theHdr.theDatatype = "Raster";
57 
58  ossimByteOrder byteorder = ossim::byteOrder();
59  if (byteorder == OSSIM_BIG_ENDIAN)
60  {
61  theHdr.theByteorder = "MSBFirst";
62  }
63  else
64  {
65  theHdr.theByteorder = "LSBFirst";
66  }
67 
69 
70  // Get the geometry from the input.
71  ossimMapProjection* mapProj = 0;
73  if ( inputGeom.valid() ) mapProj = PTR_CAST(ossimMapProjection, inputGeom->getProjection());
74  if (mapProj)
75  {
76  // Create the projection info.
79 
80  // Set the tie points in the keyword list.
81  ossimKeywordlist kwl;
82  projectionInfo->getGeom(kwl);
83 
84  // Get the projection type.
85  const char* lookup;
86  ossimString projection;
87  lookup = kwl.find(ossimKeywordNames::TYPE_KW);
88  if (lookup)
89  {
90  projection = lookup;
91  }
92  else
93  {
95  << "ossimERSFileWriter::writeFile WARNING:"
96  << "\nNo projection type found!\nReturning..."
97  << std::endl;
98  return false; // Have to have the projection type!
99  }
100 
101  if (projection == "ossimUtmProjection")
102  {
103  ossimString utm;
105  if (lookup)
106  {
107  utm = lookup;
108  utm += "UTM";
109  }
110  else
111  return false;
112 
113  lookup = kwl.find(ossimKeywordNames::ZONE_KW);
114  if (lookup)
115  utm += lookup;
116  else
117  return false;
118 
119  theHdr.theProjection = utm;
120  theHdr.theCoordSysType = "EN";
121 
122 
123  //we get tie points
125  tmp = lookup;
126  if (lookup)
127  {
128  tmp = tmp.trim("(");
129  tmp = tmp.trim(")");
130  ossimString a = tmp.before(",", 0);
131  ossimString b = tmp.after(",", 0);
132  theHdr.theOriginX = a.toDouble();
133  theHdr.theOriginY = b.toDouble();
134  }
135  //set the tie point unit type to meters
137 
138  }
139  else if (projection == "ossimEquDistCylProjection")
140  {
141  theHdr.theProjection = "GEODETIC";
142  theHdr.theCoordSysType = "LL";
143 
144  //we get tie points
146  tmp = lookup;
147  if (lookup)
148  {
149  tmp = tmp.trim("(");
150  tmp = tmp.trim(")");
151  ossimString a = tmp.before(",", 0);
152  ossimString b = tmp.after(",", 0);
153  theHdr.theOriginX = a.toDouble();
154  theHdr.theOriginY = b.toDouble();
155  }
156  //set the tie point unit type to degrees
158 
159  }
160  else
161  {
163  << "ossimERSFileWriter::writeFile WARNING:"
164  << "\nOnly LatLon and UTM supported!\nReturning..."
165  << std::endl;
166  return false;
167  }
168 
169  // Get the datum.
170  ossimString datum = "WGS-84";
171  lookup = kwl.find(ossimKeywordNames::DATUM_KW);
172  if (lookup)
173  {
174  ossimString os = lookup;
175  if (os == "WGE")
176  {
177  theHdr.theDatum = "WGS84";
178  }
179  else
180  {
182  << "ossimERSFileWriter::writeFile WARNING:"
183  << "\nOnly WGS84 supported!\nReturning..."
184  << std::endl;
185  return false; // Datum has to be WGS84 for now...
186  }
187  }
188 
189  //get cell size
191  tmp = lookup;
192  if (lookup)
193  {
194  tmp = tmp.trim("(");
195  tmp = tmp.trim(")");
196  ossimString a = tmp.before(",", 0);
197  ossimString b = tmp.after(",", 0);
198 
201  }
202 
203  //get pixel is area or point
205  {
208  }
209  }
210 
211  return theHdr.writeFile(theFilename);
212 }
213 
215  std::vector<ossimString>& metadatatypeList) const
216 {
217  metadatatypeList.push_back(ossimString("ers_header"));
218 }
219 
221  const ossimString& metadataType)const
222 {
223  return (metadataType == "ers_header");
224 }
double theOriginX
Definition: ossimERS.h:66
ossimString before(const ossimString &str, std::string::size_type pos=0) const
METHOD: before(str, pos) Returns string beginning at pos and ending one before the token str If strin...
virtual bool writeFile()
Write out the file.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Initializes the state of the writer.
static const char * DATUM_KW
ossimUnitType theTieUnitType
Definition: ossimERS.h:56
ossimString theCoordSysType
Definition: ossimERS.h:52
Represents serializable keyword/value map.
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
ossim_uint32 height() const
Definition: ossimIrect.h:487
ossimString theDatum
Definition: ossimERS.h:50
ossimString theByteorder
Definition: ossimERS.h:46
OSSIM_DLL ossimByteOrder byteOrder()
Definition: ossimCommon.cpp:54
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Load state method:
static const char * TYPE_KW
ossimScalarType theCelltype
Definition: ossimERS.h:58
double theCellSizeX
Definition: ossimERS.h:62
static const char * PIXEL_SCALE_XY_KW
static const char * ZONE_KW
ossim_int32 theBands
Definition: ossimERS.h:68
Class for writing a "ERS" style header.
virtual void getMetadatatypeList(std::vector< ossimString > &metadatatypeList) const
Satisfies pure virtual from ossimMetadataWriter base.
static const char * TIE_POINT_XY_KW
ossimMetadataFileWriter
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
double toDouble() const
#define PTR_CAST(T, p)
Definition: ossimRtti.h:321
ossimERSFileWriter()
default constructor
ossimByteOrder
double theCellSizeY
Definition: ossimERS.h:63
ossim_uint32 width() const
Definition: ossimIrect.h:500
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if not defined...
void getGeom(ossimKeywordlist &kwl, const char *prefix=0) const
Adds tie point to keyword list.
virtual bool hasMetadataType(const ossimString &metadataType) const
Satisfies pure virtual from ossimMetadataWriter base.
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
double theOriginY
Definition: ossimERS.h:67
static const char * HEMISPHERE_KW
ossimString theDatatype
Definition: ossimERS.h:45
ossim_int32 theSample
Definition: ossimERS.h:65
bool writeFile(const ossimFilename &file)
Definition: ossimERS.cpp:411
virtual ~ossimERSFileWriter()
virtual destructor
ossimImageSource * theInputConnection
ossimString theProjection
Definition: ossimERS.h:51
ossim_int32 theLine
Definition: ossimERS.h:64
ossimString after(const ossimString &str, std::string::size_type pos=0) const
METHOD: after(str, pos) Returns string immediately after the token str.
ossimString theDatasetType
Definition: ossimERS.h:44
RTTI_DEF1(ossimERSFileWriter, "ossimERSFileWriter", ossimMetadataFileWriter) ossimERSFileWriter
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)