Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
Projections.h
Go to the documentation of this file.
1 //
2 // Projections.h
3 //
4 // Copyright (c) 2001-2007 Virtual Terrain Project
5 // Free for all uses, see license.txt for details.
6 //
7 // Derived from public-domain USGS software.
8 //
11 #ifndef PROJECTIONSH
12 #define PROJECTIONSH
13 
14 //
15 // Earth's diameter: 12756 km
16 // approximate circumference: 40074 km
17 // each degree of latitude: 111.3 km
18 //
19 #define EARTH_RADIUS 6378000.0f // in meters
20 #define METERS_PER_LATITUDE 111317.1f
21 
22 // Some class names are just too long!
23 #define OCT OGRCoordinateTransformation
24 
25 // Do not change the order of this enumeration
26 enum LinearUnits
27 {
28  LU_DEGREES,
29  LU_METERS,
30  LU_FEET_INT, // International Foot
31  LU_FEET_US, // U.S. Survey Foot
32  LU_UNITEDGE, // Unit Edges: Dymaxion Projection
33  LU_UNKNOWN
34 };
35 
36 // Define a few common datums for convenience
37 #define EPSG_DATUM_OLD_HAWAIIAN 6135
38 #define EPSG_DATUM_PUERTO_RICO 6139
39 #define EPSG_DATUM_NAD27 6267
40 #define EPSG_DATUM_NAD83 6269
41 #define EPSG_DATUM_WGS72 6322
42 #define EPSG_DATUM_WGS84 6326
43 
44 #include "ogr_spatialref.h"
45 #include "MathTypes.h"
46 
48 
56 class vtProjection : public OGRSpatialReference
57 {
58 public:
59  vtProjection();
60  ~vtProjection();
61 
62  // Assignment
63  vtProjection &operator=(const vtProjection &ref);
64 
65  // Equality
66  bool operator==(const vtProjection &ref) const;
67  bool operator!=(const vtProjection &ref) const;
68 
69  void SetUTMZone(int iZone);
70  int GetUTMZone() const;
71  OGRErr SetDatum(int iDatum);
72  int GetDatum() const;
73  LinearUnits GetUnits() const;
74  int GuessEPSGCode() const;
75 
76  OGRErr SetGeogCSFromDatum(int iDatum);
77 
78  bool SetProjectionSimple(bool bUTM, int iUTMZone, int iDatum);
79  void SetSpatialReference(OGRSpatialReference *pRef);
80 
81  const char *GetProjectionName() const;
82  const char *GetProjectionNameShort() const;
83 
84  bool GetTextDescription(char *type, char *value) const;
85  bool SetTextDescription(const char *type, const char *value);
86 
87  bool ReadProjFile(const char *filename);
88  bool WriteProjFile(const char *filename) const;
89 
90  static double GeodesicDistance(const DPoint2 &in, const DPoint2 &out, bool bQuick = false);
91 
92  void SetDymaxion(bool bTrue) { m_bDymaxion = bTrue; }
93  bool IsDymaxion() const { return m_bDymaxion; }
94 
95 protected:
96  bool m_bDymaxion;
97 
98  // Useful for debugging
99  void LogDescription() const;
100 };
101 
103 {
104  const char *name;
105  bool bNAD27;
106  bool bNAD83;
107  int usgs_code;
108 };
109 
110 class Geodesic
111 {
112 public:
113  void CalculateInverse();
114 
115  double a;
116  double lam1, phi1;
117  double lam2, phi2;
118  double S;
119  double onef, f, f2, f4, f64;
120 };
121 
122 
124 // Helper functions
125 
126 const char *DatumToString(int d);
127 const char *DatumToStringShort(int d);
128 struct EPSGDatum
129 {
130  bool bCommon;
131  int iCode;
132  const char *szName;
133  const char *szShortName;
134 };
135 extern vtArray<EPSGDatum> g_EPSGDatums;
136 void SetupEPSGDatums();
137 
138 StatePlaneInfo *GetStatePlaneTable();
139 int GetNumStatePlanes();
140 void CreateSimilarGeographicProjection(const vtProjection &source, vtProjection &geo);
141 OCT *CreateConversionIgnoringDatum(const vtProjection *pSource, vtProjection *pTarget);
142 OCT *CreateCoordTransform(const vtProjection *pSource,
143  const vtProjection *pTarget, bool bLog = false);
144 
149 double EstimateDegreesToMeters(double latitude);
150 
154 double GetMetersPerUnit(LinearUnits lu);
155 
159 const char *GetLinearUnitName(LinearUnits lu);
160 
164 double MetersPerLongitude(double latitude);
165 
170 bool ReadAssociatedWorldFile(const char *filename_base, double params[6]);
171 
173 
174 // Stick this here for now, although it really belongs in its own module
175 
177 {
178 public:
179  GDALInitResult() { hasGDAL_DATA = false; hasPROJ_LIB = false; hasPROJSO = false; }
180 
181  bool hasGDAL_DATA;
182  bool hasPROJ_LIB;
183  bool hasPROJSO;
184 
185  bool Success() { return hasGDAL_DATA && hasPROJ_LIB && hasPROJSO; }
186 };
187 
189 {
190 public:
191  GDALWrapper();
192  ~GDALWrapper();
193 
194  void RequestGDALFormats();
195  void RequestOGRFormats();
196  bool Init();
197  GDALInitResult* GetInitResult() { return &m_initResult; }
198  bool TestPROJ4();
199 
200 protected:
201  bool FindGDALData();
202  bool FindPROJ4Data();
203  bool FindPROJ4SO();
204 
205  bool m_bGDALFormatsRegistered;
206  bool m_bOGRFormatsRegistered;
207  GDALInitResult m_initResult;
208 };
209 
210 extern GDALWrapper g_GDALWrapper;
211 
212 #ifdef WIN32
213  #define DEFAULT_LOCATION_GDAL_DATA "../../GDAL-data/"
214  #define DEFAULT_LOCATION_PROJ_LIB "../../PROJ4-data/"
215 #elif __APPLE__
216  #define DEFAULT_LOCATION_GDAL_DATA "Shared/share/gdal/"
217  #define DEFAULT_LOCATION_PROJ_LIB "Shared/share/proj/"
218  #define DEFAULT_LOCATION_PROJSO "Shared/lib/"
219 #else // other unixes
220  #define DEFAULT_LOCATION_GDAL_DATA "/usr/local/share/gdal/"
221  #define DEFAULT_LOCATION_PROJ_LIB "/usr/local/share/proj/"
222 # if _LP64
223 # define DEFAULT_LOCATION_PROJSO "/usr/local/lib64/"
224 # else
225 # define DEFAULT_LOCATION_PROJSO "/usr/local/lib/"
226 # endif
227 #endif
228 
229 #endif // PROJECTIONSH