QgsDistanceArea::QgsDistanceArea() { // init with default settings mEllipsoidalMode = false; setSourceCrs( GEOCRS_ID ); // WGS 84 setEllipsoid( GEO_NONE ); }
QgsDistanceArea::QgsDistanceArea() { // init with default settings mEllipsoidalMode = false; mCoordTransform = new QgsCoordinateTransform; setSourceCrs( GEOCRS_ID ); // WGS 84 setEllipsoid( GEO_NONE ); }
QgsDistanceArea::QgsDistanceArea() { // init with default settings mProjectionsEnabled = false; mCoordTransform = new QgsCoordinateTransform; setSourceCrs( GEOCRS_ID ); // WGS 84 setEllipsoid( "WGS84" ); }
void GeoLocation::reset( GeoLocation *g ) { indexEllipsoid = g->ellipsoid(); setEllipsoid ( indexEllipsoid ); setLong( g->lng()->Degrees() ); setLat( g->lat()->Degrees() ); Name = g->name(); Province = g->province(); Country = g->country(); TimeZone = g->TZ(); TZrule = g->tzrule(); Height = g->height(); }
GeoLocation::GeoLocation( double x, double y, double z, QString name, QString province, QString country, double TZ, TimeZoneRule *tzrule, int iEllips ) { PosCartX = x; PosCartY = y; PosCartZ = z; Name = name; Province = province; Country = country; TimeZone = TZ; TZrule = tzrule; indexEllipsoid = iEllips; setEllipsoid ( indexEllipsoid ); cartToGeod(); }
GeoLocation::GeoLocation( GeoLocation *g ) { Longitude = g->Longitude; Latitude = g->Latitude; Name = g->Name; Province = g->Province; Country = g->Country; TimeZone = g->TimeZone; TZrule = g->TZrule; Height = g->Height; indexEllipsoid = g->indexEllipsoid; setEllipsoid ( indexEllipsoid ); geodToCart(); }
GeoLocation::GeoLocation( const GeoLocation &g ) { Longitude = g.Longitude; Latitude = g.Latitude; Name = g.Name; Province = g.Province; Country = g.Country; TimeZone = g.TimeZone; TZrule = g.TZrule; Height = g.Height; indexEllipsoid = g.indexEllipsoid; setEllipsoid ( indexEllipsoid ); geodToCart(); }
GeoLocation::GeoLocation( double lng, double lat, QString name, QString province, QString country, double tz, TimeZoneRule *tzrule, int iEllips, double hght ) { Longitude.set( lng ); Latitude.set( lat ); Name = name; Province = province; Country = country; TimeZone = tz; TZrule = tzrule; Height = hght; indexEllipsoid = iEllips; setEllipsoid ( indexEllipsoid ); geodToCart(); }
GeoLocation::GeoLocation( dms lng, dms lat, const QString &name, const QString &province, const QString &country, double tz, TimeZoneRule *tzrule, int iEllips, double hght ) { Longitude = lng; Latitude = lat; Name = name; Province = province; Country = country; TimeZone = tz; TZrule = tzrule; Height = hght; indexEllipsoid = iEllips; setEllipsoid ( indexEllipsoid ); geodToCart(); }
bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid ) { QString radius, parameter2; // // SQLITE3 stuff - get parameters for selected ellipsoid // sqlite3 *myDatabase; const char *myTail; sqlite3_stmt *myPreparedStatement; int myResult; // Shortcut if ellipsoid is none. if ( ellipsoid == GEO_NONE ) { mEllipsoid = GEO_NONE; return true; } // Check if we have a custom projection, and set from text string. // Format is "PARAMETER:<semi-major axis>:<semi minor axis> // Numbers must be with (optional) decimal point and no other separators (C locale) // Distances in meters. Flattening is calculated. if ( ellipsoid.startsWith( "PARAMETER" ) ) { QStringList paramList = ellipsoid.split( ':' ); bool semiMajorOk, semiMinorOk; double semiMajor = paramList[1].toDouble( & semiMajorOk ); double semiMinor = paramList[2].toDouble( & semiMinorOk ); if ( semiMajorOk && semiMinorOk ) { return setEllipsoid( semiMajor, semiMinor ); } else { return false; } } // Continue with PROJ.4 list of ellipsoids. //check the db is available myResult = sqlite3_open_v2( QgsApplication::srsDbFilePath().toUtf8().data(), &myDatabase, SQLITE_OPEN_READONLY, nullptr ); if ( myResult ) { QgsMessageLog::logMessage( QObject::tr( "Can't open database: %1" ).arg( sqlite3_errmsg( myDatabase ) ) ); // XXX This will likely never happen since on open, sqlite creates the // database if it does not exist. return false; } // Set up the query to retrieve the projection information needed to populate the ELLIPSOID list QString mySql = "select radius, parameter2 from tbl_ellipsoid where acronym='" + ellipsoid + '\''; myResult = sqlite3_prepare( myDatabase, mySql.toUtf8(), mySql.toUtf8().length(), &myPreparedStatement, &myTail ); // XXX Need to free memory from the error msg if one is set if ( myResult == SQLITE_OK ) { if ( sqlite3_step( myPreparedStatement ) == SQLITE_ROW ) { radius = QString( reinterpret_cast< const char * >( sqlite3_column_text( myPreparedStatement, 0 ) ) ); parameter2 = QString( reinterpret_cast< const char * >( sqlite3_column_text( myPreparedStatement, 1 ) ) ); } } // close the sqlite3 statement sqlite3_finalize( myPreparedStatement ); sqlite3_close( myDatabase ); // row for this ellipsoid wasn't found? if ( radius.isEmpty() || parameter2.isEmpty() ) { QgsDebugMsg( QString( "setEllipsoid: no row in tbl_ellipsoid for acronym '%1'" ).arg( ellipsoid ) ); return false; } // get major semiaxis if ( radius.left( 2 ) == "a=" ) mSemiMajor = radius.mid( 2 ).toDouble(); else { QgsDebugMsg( QString( "setEllipsoid: wrong format of radius field: '%1'" ).arg( radius ) ); return false; } // get second parameter // one of values 'b' or 'f' is in field parameter2 // second one must be computed using formula: invf = a/(a-b) if ( parameter2.left( 2 ) == "b=" ) { mSemiMinor = parameter2.mid( 2 ).toDouble(); mInvFlattening = mSemiMajor / ( mSemiMajor - mSemiMinor ); } else if ( parameter2.left( 3 ) == "rf=" ) { mInvFlattening = parameter2.mid( 3 ).toDouble(); mSemiMinor = mSemiMajor - ( mSemiMajor / mInvFlattening ); } else { QgsDebugMsg( QString( "setEllipsoid: wrong format of parameter2 field: '%1'" ).arg( parameter2 ) ); return false; } QgsDebugMsg( QString( "setEllipsoid: a=%1, b=%2, 1/f=%3" ).arg( mSemiMajor ).arg( mSemiMinor ).arg( mInvFlattening ) ); // get spatial ref system for ellipsoid QString proj4 = "+proj=longlat +ellps=" + ellipsoid + " +no_defs"; QgsCoordinateReferenceSystem destCRS; destCRS.createFromProj4( proj4 ); //TODO: createFromProj4 used to save to the user database any new CRS // this behavior was changed in order to separate creation and saving. // Not sure if it necessary to save it here, should be checked by someone // familiar with the code (should also give a more descriptive name to the generated CRS) if ( destCRS.srsid() == 0 ) { QString myName = QString( " * %1 (%2)" ) .arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ), destCRS.toProj4() ); destCRS.saveAsUserCRS( myName ); } // // set transformation from project CRS to ellipsoid coordinates mCoordTransform->setDestCRS( destCRS ); mEllipsoid = ellipsoid; // precalculate some values for area calculations computeAreaInit(); return true; }
void GeoLocation::changeEllipsoid(int index) { setEllipsoid(index); cartToGeod(); }
bool QgsDistanceArea::setEllipsoid( const QString& ellipsoid ) { // Shortcut if ellipsoid is none. if ( ellipsoid == GEO_NONE ) { mEllipsoid = GEO_NONE; return true; } // Check if we have a custom projection, and set from text string. // Format is "PARAMETER:<semi-major axis>:<semi minor axis> // Numbers must be with (optional) decimal point and no other separators (C locale) // Distances in meters. Flattening is calculated. if ( ellipsoid.startsWith( "PARAMETER" ) ) { QStringList paramList = ellipsoid.split( ":" ); bool semiMajorOk, semiMinorOk; double semiMajor = paramList[1].toDouble( & semiMajorOk ); double semiMinor = paramList[2].toDouble( & semiMinorOk ); if ( semiMajorOk && semiMinorOk ) { return setEllipsoid( semiMajor, semiMinor ); } else { return false; } } // Continue with PROJ.4 list of ellipsoids. QgsEllipsoidCache::Params params = QgsEllipsoidCache::instance()->getParams( ellipsoid ); // row for this ellipsoid wasn't found? if ( params.radius.isEmpty() || params.parameter2.isEmpty() ) { QgsDebugMsg( QString( "setEllipsoid: no row in tbl_ellipsoid for acronym '%1'" ).arg( ellipsoid ) ); return false; } // get major semiaxis if ( params.radius.left( 2 ) == "a=" ) mSemiMajor = params.radius.mid( 2 ).toDouble(); else { QgsDebugMsg( QString( "setEllipsoid: wrong format of radius field: '%1'" ).arg( params.radius ) ); return false; } // get second parameter // one of values 'b' or 'f' is in field parameter2 // second one must be computed using formula: invf = a/(a-b) if ( params.parameter2.left( 2 ) == "b=" ) { mSemiMinor = params.parameter2.mid( 2 ).toDouble(); mInvFlattening = mSemiMajor / ( mSemiMajor - mSemiMinor ); } else if ( params.parameter2.left( 3 ) == "rf=" ) { mInvFlattening = params.parameter2.mid( 3 ).toDouble(); mSemiMinor = mSemiMajor - ( mSemiMajor / mInvFlattening ); } else { QgsDebugMsg( QString( "setEllipsoid: wrong format of parameter2 field: '%1'" ).arg( params.parameter2 ) ); return false; } QgsDebugMsg( QString( "setEllipsoid: a=%1, b=%2, 1/f=%3" ).arg( mSemiMajor ).arg( mSemiMinor ).arg( mInvFlattening ) ); // get spatial ref system for ellipsoid QString proj4 = "+proj=longlat +ellps=" + ellipsoid + " +no_defs"; QgsCoordinateReferenceSystem destCRS = QgsCRSCache::instance()->crsByProj4( proj4 ); //TODO: createFromProj4 used to save to the user database any new CRS // this behavior was changed in order to separate creation and saving. // Not sure if it necessary to save it here, should be checked by someone // familiar with the code (should also give a more descriptive name to the generated CRS) if ( destCRS.srsid() == 0 ) { QString myName = QString( " * %1 (%2)" ) .arg( QObject::tr( "Generated CRS", "A CRS automatically generated from layer info get this prefix for description" ) ) .arg( destCRS.toProj4() ); destCRS.saveAsUserCRS( myName ); } // // set transformation from project CRS to ellipsoid coordinates mCoordTransform->setDestCRS( destCRS ); mEllipsoid = ellipsoid; // precalculate some values for area calculations computeAreaInit(); return true; }