26 #include <QRegularExpression> 
   35   const bool automatic = project->
readBoolEntry( QStringLiteral( 
"PositionPrecision" ), QStringLiteral( 
"/Automatic" ) );
 
   40     const QString format = project->
readEntry( QStringLiteral( 
"PositionPrecision" ), QStringLiteral( 
"/DegreeFormat" ), QStringLiteral( 
"MU" ) );
 
   41     const bool formatGeographic = ( format == QLatin1String( 
"DM" ) || format == QLatin1String( 
"DMS" ) || format == QLatin1String( 
"D" ) );
 
   53         dp = 
static_cast<int>( std::ceil( -1.0 * std::log10( mapUnitsPerPixel ) ) );
 
   57       if ( format == QLatin1String( 
"D" ) )
 
   64     dp = project->
readNumEntry( QStringLiteral( 
"PositionPrecision" ), QStringLiteral( 
"/DecimalPlaces" ) );
 
   81   const bool automatic = prj->
readBoolEntry( QStringLiteral( 
"PositionPrecision" ), QStringLiteral( 
"/Automatic" ) );
 
   84     return prj->
readNumEntry( QStringLiteral( 
"PositionPrecision" ), QStringLiteral( 
"/DecimalPlaces" ), 6 );
 
  103   const QString format = project->
readEntry( QStringLiteral( 
"PositionPrecision" ), QStringLiteral( 
"/DegreeFormat" ), QStringLiteral( 
"MU" ) );
 
  106   if ( format == QLatin1String( 
"DM" ) || format == QLatin1String( 
"DMS" ) || format == QLatin1String( 
"D" ) )
 
  115         geo = ct.transform( point );
 
  123     if ( format == QLatin1String( 
"DM" ) )
 
  125     else if ( format == QLatin1String( 
"DMS" ) )
 
  141   return QStringLiteral( 
"%1 : %2" ).arg( QgsCoordinateUtils::formatCoordinateForProject( project, p1, destCrs, 
precision ),
 
  142                                           QgsCoordinateUtils::formatCoordinateForProject( project, p2, destCrs, 
precision ) );
 
  145 double QgsCoordinateUtils::degreeToDecimal( 
const QString &
string, 
bool *ok, 
bool *isEasting )
 
  147   const QString negative( QStringLiteral( 
"swSW" ) );
 
  148   const QString easting( QStringLiteral( 
"eEwW" ) );
 
  150   bool okValue = 
false;
 
  161   QRegularExpression degreeWithSuffix( QStringLiteral( 
"^\\s*([0-9\\-\\.]*)\\s*([NSEWnsew])\\s*$" ) );
 
  162   QRegularExpressionMatch match = degreeWithSuffix.match( 
string );
 
  163   if ( match.hasMatch() )
 
  165     const QString suffix = match.captured( 2 );
 
  166     value = std::abs( match.captured( 1 ).toDouble( ok ) );
 
  169       value *= ( negative.contains( suffix ) ? -1 : 1 );
 
  172         *isEasting = easting.contains( suffix );
 
  179 double QgsCoordinateUtils::dmsToDecimal( 
const QString &
string, 
bool *ok, 
bool *isEasting )
 
  181   const QString negative( QStringLiteral( 
"swSW-" ) );
 
  182   const QString easting( QStringLiteral( 
"eEwW" ) );
 
  184   bool okValue = 
false;
 
  195   const QRegularExpression dms( 
"^\\s*(?:([-+nsew])\\s*)?(\\d{1,3})(?:[^0-9.]+([0-5]?\\d))?[^0-9.]+([0-5]?\\d(?:\\.\\d+)?)[^0-9.,]*?([-+nsew])?\\s*$", QRegularExpression::CaseInsensitiveOption );
 
  196   const QRegularExpressionMatch match = dms.match( 
string.trimmed() );
 
  197   if ( match.hasMatch() )
 
  199     const QString dms1 = match.captured( 2 );
 
  200     const QString dms2 = match.captured( 3 );
 
  201     const QString dms3 = match.captured( 4 );
 
  203     double v = dms3.toDouble( ok );
 
  207     if ( !dms2.isEmpty() )
 
  209       v = dms2.toInt( ok ) + v / 60.0;
 
  213     v = dms1.toInt( ok ) + v / 60.0;
 
  217     const QString sign1 = match.captured( 1 );
 
  218     const QString sign2 = match.captured( 5 );
 
  220     if ( sign1.isEmpty() )
 
  222       value = !sign2.isEmpty() && negative.contains( sign2 ) ? -v : v;
 
  225         *isEasting = easting.contains( sign2 );
 
  228     else if ( sign2.isEmpty() )
 
  230       value = !sign1.isEmpty() && negative.contains( sign1 ) ? -v : v;
 
  233         *isEasting = easting.contains( sign2 );
 
This class represents a coordinate reference system (CRS).
 
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
 
Q_GADGET QgsUnitTypes::DistanceUnit mapUnits
 
Custom exception class for Coordinate Reference System related exceptions.
 
A class to represent a 2D point.
 
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
 
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
Reads an integer from the specified scope and key.
 
static QgsProject * instance()
Returns the QgsProject singleton instance.
 
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
Reads a string from the specified scope and key.
 
bool readBoolEntry(const QString &scope, const QString &key, bool def=false, bool *ok=nullptr) const
Reads a boolean from the specified scope and key.
 
A rectangle specified with double values.
 
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
 
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
 
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
 
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
 
DistanceUnit
Units of distance.
 
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
 
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
 
const QgsCoordinateReferenceSystem & crs