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::dmsToDecimal( 
const QString &
string, 
bool *ok, 
bool *isEasting )
 
  147   const QString negative( QStringLiteral( 
"swSW-" ) );
 
  148   const QString easting( QStringLiteral( 
"eEwW" ) );
 
  150   bool okValue = 
false;
 
  161   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 );
 
  162   const QRegularExpressionMatch match = dms.match( 
string.trimmed() );
 
  163   if ( match.hasMatch() )
 
  165     const QString dms1 = match.captured( 2 );
 
  166     const QString dms2 = match.captured( 3 );
 
  167     const QString dms3 = match.captured( 4 );
 
  169     double v = dms3.toDouble( ok );
 
  173     if ( !dms2.isEmpty() )
 
  175       v = dms2.toInt( ok ) + v / 60.0;
 
  179     v = dms1.toInt( ok ) + v / 60.0;
 
  183     const QString sign1 = match.captured( 1 );
 
  184     const QString sign2 = match.captured( 5 );
 
  186     if ( sign1.isEmpty() )
 
  188       value = !sign2.isEmpty() && negative.contains( sign2 ) ? -v : v;
 
  191         *isEasting = easting.contains( sign2 );
 
  194     else if ( sign2.isEmpty() )
 
  196       value = !sign1.isEmpty() && negative.contains( sign1 ) ? -v : v;
 
  199         *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