| 
    QGIS API Documentation
    3.26.3-Buenos Aires (65e4edfdad)
    
   | 
 
 
 
 
Go to the documentation of this file.
   31 #include <QRegularExpression> 
   40   const bool automatic = project->
readBoolEntry( QStringLiteral( 
"PositionPrecision" ), QStringLiteral( 
"/Automatic" ) );
 
   45     const QString format = project->
readEntry( QStringLiteral( 
"PositionPrecision" ), QStringLiteral( 
"/DegreeFormat" ), QStringLiteral( 
"MU" ) );
 
   47     const bool formatGeographic = format == QLatin1String( 
"D" ) || format == QLatin1String( 
"DM" ) || format == QLatin1String( 
"DMS" );
 
   59         dp = 
static_cast<int>( std::ceil( -1.0 * std::log10( mapUnitsPerPixel ) ) );
 
   76     dp = project->
readNumEntry( QStringLiteral( 
"PositionPrecision" ), QStringLiteral( 
"/DecimalPlaces" ) );
 
   93   const bool automatic = prj->
readBoolEntry( QStringLiteral( 
"PositionPrecision" ), QStringLiteral( 
"/Automatic" ) );
 
   96     return prj->
readNumEntry( QStringLiteral( 
"PositionPrecision" ), QStringLiteral( 
"/DecimalPlaces" ), 6 );
 
  115   const QString format = project->
readEntry( QStringLiteral( 
"PositionPrecision" ), QStringLiteral( 
"/DegreeFormat" ), QStringLiteral( 
"MU" ) );
 
  119   const bool formatGeographic = format == QLatin1String( 
"D" ) || format == QLatin1String( 
"DM" ) || format == QLatin1String( 
"DMS" );
 
  122   if ( formatGeographic )
 
  134         geo = ct.transform( point );
 
  145     format->setNumberDecimalPlaces( 
precision );
 
  149     const QString formattedX = format->formatDouble( geo.
x(), context );
 
  151     const QString formattedY = format->formatDouble( geo.
y(), context );
 
  176   return QStringLiteral( 
"%1 : %2" ).arg( QgsCoordinateUtils::formatCoordinateForProject( project, p1, destCrs, 
precision ),
 
  177                                           QgsCoordinateUtils::formatCoordinateForProject( project, p2, destCrs, 
precision ) );
 
  180 double QgsCoordinateUtils::degreeToDecimal( 
const QString &
string, 
bool *ok, 
bool *isEasting )
 
  182   const QString negative( QStringLiteral( 
"swSW" ) );
 
  183   const QString easting( QStringLiteral( 
"eEwW" ) );
 
  185   bool okValue = 
false;
 
  196   const QLocale locale;
 
  197   QRegularExpression degreeWithSuffix( QStringLiteral( 
"^\\s*([-]?\\d{1,3}(?:[\\.\\%1]\\d+)?)\\s*([NSEWnsew])\\s*$" )
 
  198                                        .arg( locale.decimalPoint() ) );
 
  199   QRegularExpressionMatch match = degreeWithSuffix.match( 
string );
 
  200   if ( match.hasMatch() )
 
  202     const QString suffix = match.captured( 2 );
 
  203     value = std::abs( match.captured( 1 ).toDouble( ok ) );
 
  206       value = std::abs( locale.toDouble( match.captured( 1 ), ok ) );
 
  210       value *= ( negative.contains( suffix ) ? -1 : 1 );
 
  213         *isEasting = easting.contains( suffix );
 
  220 double QgsCoordinateUtils::dmsToDecimal( 
const QString &
string, 
bool *ok, 
bool *isEasting )
 
  222   const QString negative( QStringLiteral( 
"swSW-" ) );
 
  223   const QString easting( QStringLiteral( 
"eEwW" ) );
 
  225   bool okValue = 
false;
 
  236   const QLocale locale;
 
  237   const QRegularExpression dms( QStringLiteral( 
"^\\s*(?:([-+nsew])\\s*)?(\\d{1,3})(?:[^0-9.]+([0-5]?\\d))?[^0-9.]+([0-5]?\\d(?:[\\.\\%1]\\d+)?)[^0-9.,]*?([-+nsew])?\\s*$" )
 
  238                                 .arg( locale.decimalPoint() ), QRegularExpression::CaseInsensitiveOption );
 
  239   const QRegularExpressionMatch match = dms.match( 
string.trimmed() );
 
  240   if ( match.hasMatch() )
 
  242     const QString dms1 = match.captured( 2 );
 
  243     const QString dms2 = match.captured( 3 );
 
  244     const QString dms3 = match.captured( 4 );
 
  246     double v = dms3.toDouble( ok );
 
  249       v = locale.toDouble( dms3, ok );
 
  254     if ( !dms2.isEmpty() )
 
  256       v = dms2.toInt( ok ) + v / 60.0;
 
  260     v = dms1.toInt( ok ) + v / 60.0;
 
  264     const QString sign1 = match.captured( 1 );
 
  265     const QString sign2 = match.captured( 5 );
 
  267     if ( sign1.isEmpty() )
 
  269       value = !sign2.isEmpty() && negative.contains( sign2 ) ? -v : v;
 
  272         *isEasting = easting.contains( sign2 );
 
  275     else if ( sign2.isEmpty() )
 
  277       value = !sign1.isEmpty() && negative.contains( sign1 ) ? -v : v;
 
  280         *isEasting = easting.contains( sign2 );
 
  
@ Latitude
Latitude values.
 
const QgsCoordinateReferenceSystem & crs
 
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
 
static QgsProject * instance()
Returns the QgsProject singleton instance.
 
const QgsProjectDisplaySettings * displaySettings() const
Returns the project's display settings, which settings and properties relating to how a QgsProject sh...
 
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.
 
DistanceUnit
Units of distance.
 
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.
 
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
 
const QgsGeographicCoordinateNumericFormat * geographicCoordinateFormat() const
Returns the project's geographic coordinate format, which controls how geographic coordinates associa...
 
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
 
static Qgis::CoordinateOrder defaultCoordinateOrderForCrs(const QgsCoordinateReferenceSystem &crs)
Returns the default coordinate order to use for the specified crs.
 
@ Default
Respect the default axis ordering for the CRS, as defined in the CRS's parameters.
 
Custom exception class for Coordinate Reference System related exceptions.
 
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
 
@ Longitude
Longitude values.
 
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
 
@ XY
Easting/Northing (or Longitude/Latitude for geographic CRS)
 
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
 
#define BUILTIN_UNREACHABLE
 
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
 
This class represents a coordinate reference system (CRS).
 
A class to represent a 2D point.
 
QgsUnitTypes::DistanceUnit mapUnits
 
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
 
@ YX
Northing/Easting (or Latitude/Longitude for geographic CRS)
 
T qgsEnumKeyToValue(const QString &key, const T &defaultValue, bool tryValueAsKey=true, bool *returnOk=nullptr)
Returns the value corresponding to the given key of an enum.
 
void setInterpretation(Interpretation interpretation)
Sets the interpretation of the numbers being converted.
 
CoordinateOrder
Order of coordinates.
 
A context for numeric formats.
 
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
Reads an integer from the specified scope and key.