00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 #include <math.h>
00089 #include "LambertConformalConic.h"
00090 #include "Neys.h"
00091 #include "NeysParameters.h"
00092 #include "MapProjectionCoordinates.h"
00093 #include "GeodeticCoordinates.h"
00094 #include "CoordinateConversionException.h"
00095 #include "ErrorMessages.h"
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 using namespace MSP::CCS;
00109
00110
00111
00112
00113
00114
00115
00116 const double PI = 3.14159265358979323e0;
00117 const double PI_OVER_2 = (PI / 2.0);
00118 const double PI_OVER_180 = (PI / 180.0);
00119 const double TWO_PI = (2.0 * PI);
00120 const double SEVENTY_ONE = (71.0 * PI_OVER_180);
00121 const double SEVENTY_FOUR = (74.0 * PI_OVER_180);
00123 const double MAX_LAT = (89.999444444444444 * PI_OVER_180);
00124
00125
00126
00127
00128
00129
00130
00131 Neys::Neys( double ellipsoidSemiMajorAxis, double ellipsoidFlattening, double centralMeridian, double originLatitude, double standardParallel, double falseEasting, double falseNorthing ) :
00132 CoordinateSystem(),
00133 lambertConformalConic2( 0 ),
00134 Neys_Std_Parallel_1( SEVENTY_ONE ),
00135 Neys_Std_Parallel_2( MAX_LAT ),
00136 Neys_Origin_Long( 0.0 ),
00137 Neys_Origin_Lat( 80.0 * PI_OVER_180 ),
00138 Neys_False_Easting( 0.0 ),
00139 Neys_False_Northing( 0.0 ),
00140 Neys_Delta_Easting( 400000000.0 ),
00141 Neys_Delta_Northing( 400000000.0 )
00142 {
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 double epsilon = 1.0e-10;
00159 double inv_f = 1 / ellipsoidFlattening;
00160 char errorStatus[500] = "";
00161
00162 if (ellipsoidSemiMajorAxis <= 0.0)
00163 {
00164 strcat( errorStatus, ErrorMessages::semiMajorAxis );
00165 }
00166 if ((inv_f < 250) || (inv_f > 350))
00167 {
00168 strcat( errorStatus, ErrorMessages::ellipsoidFlattening );
00169 }
00170 if ((originLatitude < -MAX_LAT) || (originLatitude > MAX_LAT))
00171 {
00172 strcat( errorStatus, ErrorMessages::originLatitude );
00173 }
00174 if ((fabs(standardParallel - SEVENTY_ONE) > epsilon) && (fabs(standardParallel - SEVENTY_FOUR) > epsilon))
00175 {
00176 strcat( errorStatus, ErrorMessages::standardParallel1 );
00177 }
00178 if ((centralMeridian < -PI) || (centralMeridian > TWO_PI))
00179 {
00180 strcat( errorStatus, ErrorMessages::centralMeridian );
00181 }
00182
00183 if( strlen( errorStatus ) > 0)
00184 throw CoordinateConversionException( errorStatus );
00185
00186 semiMajorAxis = ellipsoidSemiMajorAxis;
00187 flattening = ellipsoidFlattening;
00188
00189 Neys_Origin_Lat = originLatitude;
00190 if (Neys_Origin_Lat >= 0)
00191 {
00192 Neys_Std_Parallel_1 = standardParallel;
00193 Neys_Std_Parallel_2 = MAX_LAT;
00194 }
00195 else
00196 {
00197 Neys_Std_Parallel_1 = -standardParallel;
00198 Neys_Std_Parallel_2 = -MAX_LAT;
00199 }
00200
00201 if (centralMeridian > PI)
00202 centralMeridian -= TWO_PI;
00203 Neys_Origin_Long = centralMeridian;
00204 Neys_False_Easting = falseEasting;
00205 Neys_False_Northing = falseNorthing;
00206
00207 lambertConformalConic2 = new LambertConformalConic( semiMajorAxis, flattening, Neys_Origin_Long, Neys_Origin_Lat,
00208 Neys_Std_Parallel_1, Neys_Std_Parallel_2,
00209 Neys_False_Easting, Neys_False_Northing );
00210 }
00211
00212
00213 Neys::Neys( const Neys &n )
00214 {
00215 lambertConformalConic2 = new LambertConformalConic( *( n.lambertConformalConic2 ) );
00216 semiMajorAxis = n.semiMajorAxis;
00217 flattening = n.flattening;
00218 Neys_Std_Parallel_1 = n.Neys_Std_Parallel_1;
00219 Neys_Std_Parallel_2 = n.Neys_Std_Parallel_2;
00220 Neys_Origin_Long = n.Neys_Origin_Long;
00221 Neys_Origin_Lat = n.Neys_Origin_Lat;
00222 Neys_False_Easting = n.Neys_False_Easting;
00223 Neys_False_Northing = n.Neys_False_Northing;
00224 Neys_Delta_Easting = n.Neys_Delta_Easting;
00225 Neys_Delta_Northing = n.Neys_Delta_Northing;
00226 }
00227
00228
00229 Neys::~Neys()
00230 {
00231 delete lambertConformalConic2;
00232 lambertConformalConic2 = 0;
00233 }
00234
00235
00236 Neys& Neys::operator=( const Neys &n )
00237 {
00238 if( this != &n )
00239 {
00240 lambertConformalConic2->operator=( *n.lambertConformalConic2 );
00241 semiMajorAxis = n.semiMajorAxis;
00242 flattening = n.flattening;
00243 Neys_Std_Parallel_1 = n.Neys_Std_Parallel_1;
00244 Neys_Std_Parallel_2 = n.Neys_Std_Parallel_2;
00245 Neys_Origin_Long = n.Neys_Origin_Long;
00246 Neys_Origin_Lat = n.Neys_Origin_Lat;
00247 Neys_False_Easting = n.Neys_False_Easting;
00248 Neys_False_Northing = n.Neys_False_Northing;
00249 Neys_Delta_Easting = n.Neys_Delta_Easting;
00250 Neys_Delta_Northing = n.Neys_Delta_Northing;
00251 }
00252
00253 return *this;
00254 }
00255
00256
00257 NeysParameters* Neys::getParameters() const
00258 {
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272 return new NeysParameters( CoordinateType::neys, Neys_Origin_Long, Neys_Origin_Lat, Neys_Std_Parallel_1, Neys_False_Easting, Neys_False_Northing );
00273 }
00274
00275
00276 MSP::CCS::MapProjectionCoordinates* Neys::convertFromGeodetic( MSP::CCS::GeodeticCoordinates* geodeticCoordinates )
00277 {
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 char errorStatus[50] = "";
00292
00293 double longitude = geodeticCoordinates->longitude();
00294 double latitude = geodeticCoordinates->latitude();
00295
00296 if ((latitude < -PI_OVER_2) || (latitude > PI_OVER_2))
00297 {
00298 strcat( errorStatus, ErrorMessages::latitude );
00299 }
00300 if ((longitude < -PI) || (longitude > TWO_PI))
00301 {
00302 strcat( errorStatus, ErrorMessages::longitude );
00303 }
00304
00305 if( strlen( errorStatus ) > 0)
00306 throw CoordinateConversionException( errorStatus );
00307
00308 MapProjectionCoordinates* mapProjectionCoordinates = lambertConformalConic2->convertFromGeodetic( geodeticCoordinates );
00309 double easting = mapProjectionCoordinates->easting();
00310 double northing = mapProjectionCoordinates->northing();
00311 delete mapProjectionCoordinates;
00312
00313 return new MapProjectionCoordinates( CoordinateType::neys, easting, northing );
00314 }
00315
00316
00317 MSP::CCS::GeodeticCoordinates* Neys::convertToGeodetic( MSP::CCS::MapProjectionCoordinates* mapProjectionCoordinates )
00318 {
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 char errorStatus[50] = "";
00333
00334 double easting = mapProjectionCoordinates->easting();
00335 double northing = mapProjectionCoordinates->northing();
00336
00337 if ((easting < (Neys_False_Easting - Neys_Delta_Easting))
00338 ||(easting > (Neys_False_Easting + Neys_Delta_Easting)))
00339 {
00340 strcat( errorStatus, ErrorMessages::easting );
00341 }
00342 if ((northing < (Neys_False_Northing - Neys_Delta_Northing))
00343 || (northing > (Neys_False_Northing + Neys_Delta_Northing)))
00344 {
00345 strcat( errorStatus, ErrorMessages::northing );
00346 }
00347
00348 if( strlen( errorStatus ) > 0)
00349 throw CoordinateConversionException( errorStatus );
00350
00351 GeodeticCoordinates* geodeticCoordinates = lambertConformalConic2->convertToGeodetic( mapProjectionCoordinates );
00352 double longitude = geodeticCoordinates->longitude();
00353 double latitude = geodeticCoordinates->latitude();
00354 delete geodeticCoordinates;
00355
00356 return new GeodeticCoordinates( CoordinateType::geodetic, longitude, latitude );
00357 }
00358
00359
00360
00361