120 #include <android/log.h>
124 #define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, "GtApp", __VA_ARGS__))
143 using namespace MSP::CCS;
180 EllipsoidLibraryImplementation::deleteInstance();
190 int EllipsoidLibraryImplementation::instanceCount = 0;
205 void EllipsoidLibraryImplementation::removeInstance()
212 if( --instanceCount < 1 )
219 void EllipsoidLibraryImplementation::deleteInstance()
233 EllipsoidLibraryImplementation::EllipsoidLibraryImplementation():
234 _datumLibraryImplementation( 0 )
245 int size = el.ellipsoidList.size();
246 for(
int i = 0; i < size; i++ )
247 ellipsoidList.push_back(
new Ellipsoid( *( el.ellipsoidList[i] ) ) );
249 _datumLibraryImplementation = el._datumLibraryImplementation;
255 std::vector<Ellipsoid*>::iterator iter = ellipsoidList.begin();
256 while( iter != ellipsoidList.end() )
261 ellipsoidList.clear();
263 _datumLibraryImplementation = 0;
272 int size = el.ellipsoidList.size();
273 for(
int i = 0; i < size; i++ )
274 ellipsoidList[i] =
new Ellipsoid( *( el.ellipsoidList[i] ) );
276 _datumLibraryImplementation = el._datumLibraryImplementation;
299 long code_length = 0;
300 char *PathName = NULL;
305 long numEllipsoids = ellipsoidList.size();
306 double inv_f = 1 / flattening;
309 __android_log_print(ANDROID_LOG_VERBOSE,
"GtApp",
"numEllipsoid %d ", numEllipsoids );
313 bool isNewEllipsoidCode =
true;
319 isNewEllipsoidCode =
false;
327 if ( !isNewEllipsoidCode )
330 code_length = strlen( code );
334 if( semiMajorAxis <= 0.0 )
336 if( (inv_f < 250 ) || ( inv_f > 350 ) )
341 strcpy( ellipsoid_code, code );
343 for(
int i = 0; i < code_length; i++ )
344 ellipsoid_code[i] = (
char )toupper( ellipsoid_code[i] );
346 double semiMinorAxis = semiMajorAxis * ( 1 - flattening );
347 double eccentricitySquared = 2.0 * flattening - flattening * flattening;
348 ellipsoidList.push_back(
new Ellipsoid( index, ellipsoid_code, (
char* )name,
349 semiMajorAxis, semiMinorAxis, flattening, eccentricitySquared,
true ) );
356 PathName = getenv(
"MSPCCS_DATA" );
357 if( PathName != NULL )
359 strcpy( FileName, PathName );
360 strcat( FileName,
"/" );
364 strcpy( FileName,
"../../data/" );
366 strcat( FileName,
"ellips.dat" );
368 if( ( fp = fopen( FileName,
"w" ) ) == NULL )
375 while( index < numEllipsoids )
377 if( ellipsoidList[index]->userDefined() )
379 fprintf( fp,
"*%-28s %-2s %11.9f %12.9f %13.13f \n",
380 ellipsoidList[index]->name(),
381 ellipsoidList[index]->code(),
382 ellipsoidList[index]->semiMajorAxis(),
383 ellipsoidList[index]->semiMinorAxis(),
384 1 / ellipsoidList[index]->flattening() );
388 fprintf( fp,
"%-29s %-2s %11.9f %12.9f %13.13f \n",
389 ellipsoidList[index]->name(),
390 ellipsoidList[index]->code(),
391 ellipsoidList[index]->semiMajorAxis(),
392 ellipsoidList[index]->semiMinorAxis(),
393 1 / ellipsoidList[index]->flattening() );
417 char *PathName = NULL;
422 if( ellipsoidList[index]->userDefined() )
424 if( _datumLibraryImplementation )
433 ellipsoidList.erase( ellipsoidList.begin() + index );
435 int numEllipsoids = ellipsoidList.size();
440 PathName = getenv(
"MSPCCS_DATA" );
441 if( PathName != NULL )
443 strcpy( FileName, PathName );
444 strcat( FileName,
"/" );
448 strcpy( FileName,
"../../data/" );
450 strcat( FileName,
"ellips.dat" );
451 if( ( fp = fopen( FileName,
"w" ) ) == NULL )
457 while( index < numEllipsoids )
459 if( ellipsoidList[index]->userDefined() )
461 fprintf(fp,
"*%-28s %-2s %11.3f %12.4f %13.9f \n",
462 ellipsoidList[index]->name(),
463 ellipsoidList[index]->code(),
464 ellipsoidList[index]->semiMajorAxis(),
465 ellipsoidList[index]->semiMinorAxis(),
466 1 / ellipsoidList[index]->flattening() );
470 fprintf(fp,
"*%-29s %-2s %11.3f %12.4f %13.9f \n",
471 ellipsoidList[index]->name(),
472 ellipsoidList[index]->code(),
473 ellipsoidList[index]->semiMajorAxis(),
474 ellipsoidList[index]->semiMinorAxis(),
475 1 / ellipsoidList[index]->flattening() );
495 *count = ellipsoidList.size();
518 temp_code[j] = ( char )toupper(code[j]);
523 int numEllipsoids = ellipsoidList.size();
526 __android_log_print(ANDROID_LOG_VERBOSE,
"GtApp",
"ellipsoid code %s %d ", code, numEllipsoids );
529 while( ( i < numEllipsoids )
530 && strcmp( temp_code, ellipsoidList[i]->code() ) )
535 if( i == numEllipsoids )
539 if ( strcmp( temp_code, ellipsoidList[i]->code() ) )
561 if ( ( index < 0 ) || ( index >= ellipsoidList.size() ) )
564 strcpy( code, ellipsoidList[index]->code() );
583 if( ( index < 0 ) || ( index >= ellipsoidList.size() ) )
586 strcpy( name, ellipsoidList[index]->name() );
606 if( ( index < 0 ) || ( index >= ellipsoidList.size() ) )
610 Ellipsoid* ellipsoid = ellipsoidList[index];
629 *eccentricitySquared = 0;
631 if( ( index < 0 ) || ( index >= ellipsoidList.size() ) )
634 *eccentricitySquared = ellipsoidList[index]->eccentricitySquared();
653 if( ( index < 0 ) || ( index >= ellipsoidList.size() ) )
656 *result = ellipsoidList[index]->userDefined();
670 _datumLibraryImplementation = __datumLibraryImplementation;
679 void EllipsoidLibraryImplementation::loadEllipsoids()
687 char* PathName = NULL;
699 PathName =
"/data/data/com.baesystems.msp.geotrans/lib/";
700 FileName =
new char[ 80 ];
701 strcpy( FileName, PathName );
702 strcat( FileName,
"libellipsdat.so" );
704 PathName = getenv(
"MSPCCS_DATA" );
705 if (PathName != NULL)
707 FileName =
new char[ strlen( PathName ) + 12 ];
708 strcpy( FileName, PathName );
709 strcat( FileName,
"/" );
713 FileName =
new char[ 22 ];
714 strcpy( FileName,
"../../data/" );
716 strcat( FileName,
"ellips.dat" );
721 if( ( fp = fopen( FileName,
"r" ) ) == NULL )
726 if (NULL == PathName)
743 double semiMajorAxis;
744 double semiMinorAxis;
747 sscanf( buffer,
"%30c %s %lf %lf %lf", name, code, &semiMajorAxis, &semiMinorAxis, &recpF );
749 bool userDefined =
false;
759 double flattening = 1 / recpF;
760 double eccentricitySquared = 2.0 * flattening - flattening * flattening;
764 __android_log_print(ANDROID_LOG_VERBOSE,
"GtApp",
"name %s", name);
765 __android_log_print(ANDROID_LOG_VERBOSE,
"GtApp",
"code %s", code);
766 __android_log_print(ANDROID_LOG_VERBOSE,
"GtApp",
"major %f", semiMajorAxis);
767 __android_log_print(ANDROID_LOG_VERBOSE,
"GtApp",
"minor %f", semiMinorAxis);
768 __android_log_print(ANDROID_LOG_VERBOSE,
"GtApp",
"recpF %f", recpF);
771 ellipsoidList.push_back(
new Ellipsoid( index, code, name, semiMajorAxis, semiMinorAxis, flattening, eccentricitySquared, userDefined ) );