OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimWorldFileWriter.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2003 Storage Area Networks, Inc.
3 //
4 // License: See top level LICENSE.txt file.
5 //
6 // Author: Kenneth Melero (kmelero@sanz.com)
7 //
8 //*******************************************************************
9 // $Id: ossimWorldFileWriter.cpp 21631 2012-09-06 18:10:55Z dburken $
10 
13 #include <ossim/base/ossimTrace.h>
19 // #include <ossim/projection/ossimStatePlaneProjectionFactory.h>
24 
25 
27  "ossimWorldFileWriter",
29 
30 static ossimTrace traceDebug("ossimWorldFileWriter:debug");
31 
33  :
35  theUnits(OSSIM_METERS)
36 {
37 }
38 
40 {
41 }
42 
44  const char* prefix)
45 {
46  const char* lookup = kwl.find(prefix, "linear_units");
47  if(lookup)
48  {
50  getEntryNumber(lookup, true);
51  if ( (units == OSSIM_METERS) ||
52  (units == OSSIM_FEET) ||
53  (units == OSSIM_US_SURVEY_FEET) )
54  {
55  theUnits = units;
56  }
57  }
58 
59  return ossimMetadataFileWriter::loadState(kwl, prefix);
60 }
61 
62 //**************************************************************************************************
63 // Outputs projection information to the output file. Returns TRUE if successful.
64 //**************************************************************************************************
66 {
68  return false;
69 
70  std::ofstream out(theFilename.c_str(), ios_base::out);
71  if (!out)
72  return false;
73 
74  // Fetch the map projection of the input image if it exists:
75  const ossimMapProjection* mapProj = 0;
77  if( imgGeom.valid() )
78  {
79  const ossimProjection* proj = imgGeom->getProjection();
80  mapProj = PTR_CAST(ossimMapProjection, proj);
81  }
82  if (!mapProj)
83  {
84  out.close();
85  return false;
86  }
87 
88  // Convert projection info to proper units:
89  ossimDpt gsd = mapProj->getMetersPerPixel();
90  ossimDpt ul = mapProj->getUlEastingNorthing();
91 
92  // ESH 05/2008 -- If the pcs code has been given, we
93  // make use of the implied units.
94  theUnits = mapProj->getProjectionUnits();
95  if (theUnits == OSSIM_FEET)
96  {
101  }
102  else if (theUnits == OSSIM_US_SURVEY_FEET)
103  {
108  }
109 
110  // output projection info to file:
111  out << setiosflags(ios::fixed) << setprecision(15)
112  << gsd.x << endl
113  << 0.0 << endl // rotation value X
114  << 0.0 << endl // rotation value y
115  << -gsd.y << endl
116  << ul.x << endl
117  << ul.y << endl;
118 
119  out.close();
120  return true;
121 }
122 
123 //**************************************************************************************************
125  std::vector<ossimString>& metadatatypeList) const
126 {
127  metadatatypeList.push_back(ossimString("tiff_world_file"));
128  metadatatypeList.push_back(ossimString("jpeg_world_file"));
129 }
130 
132  const ossimString& metadataType)const
133 {
134  if ( (metadataType == "tiff_world_file") ||
135  (metadataType == "jpeg_world_file") )
136  {
137  return true;
138  }
139 
140  return false;
141 }
142 
144 {
145  if ( (units == OSSIM_UNIT_UNKNOWN) ||
146  (units == OSSIM_METERS) ||
147  (units == OSSIM_FEET) ||
148  (units == OSSIM_US_SURVEY_FEET) )
149  {
150  theUnits = units;
151  }
152  else
153  {
155  << "ossimWorldFileWriter::setLinearUnits WARNING!"
156  << "\nUnsupported units passed to method: "
158  << "\nUnits unchanged..."
159  << std::endl;
160  }
161 }
ossimWorldFileWriter()
default constructor
virtual bool hasMetadataType(const ossimString &metadataType) const
Satisfies pure virtual from ossimMetadataWriter base.
ossimUnitType
Represents serializable keyword/value map.
virtual ~ossimWorldFileWriter()
default constructor
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
virtual ossimString getEntryString(ossim_int32 entry_number) const
double y
Definition: ossimDpt.h:165
ossimWorldFileWriter
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Load state method:
ossimMetadataFileWriter
virtual void getMetadatatypeList(std::vector< ossimString > &metadatatypeList) const
Satisfies pure virtual from ossimMetadataWriter base.
#define PTR_CAST(T, p)
Definition: ossimRtti.h:321
virtual bool writeFile()
Write out the file.
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if not defined...
void setLinearUnits(ossimUnitType units)
Sets the linear units of the output file to either feet, us_survey_feet, or meters.
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
ossimUnitType getProjectionUnits() const
OSSIM considers all map projection coordinates (including false eastings and northings) to be in mete...
double x
Definition: ossimDpt.h:164
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
std::basic_ofstream< char > ofstream
Class for char output file streams.
Definition: ossimIosFwd.h:47
ossimImageSource * theInputConnection
virtual const ossimDpt & getUlEastingNorthing() const
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
virtual ossimDpt getMetersPerPixel() const
static ossimUnitTypeLut * instance()
Returns the static instance of an ossimUnitTypeLut object.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Load state method: