QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
32 bool automatic = project->
readBoolEntry( QStringLiteral(
"PositionPrecision" ), QStringLiteral(
"/Automatic" ) );
37 QString format = project->
readEntry( QStringLiteral(
"PositionPrecision" ), QStringLiteral(
"/DegreeFormat" ), QStringLiteral(
"MU" ) );
38 bool formatGeographic = ( format == QLatin1String(
"DM" ) || format == QLatin1String(
"DMS" ) || format == QLatin1String(
"D" ) );
50 dp =
static_cast<int>( std::ceil( -1.0 * std::log10( mapUnitsPerPixel ) ) );
54 if ( format == QLatin1String(
"D" ) )
61 dp = project->
readNumEntry( QStringLiteral(
"PositionPrecision" ), QStringLiteral(
"/DecimalPlaces" ) );
75 QString format = project->
readEntry( QStringLiteral(
"PositionPrecision" ), QStringLiteral(
"/DegreeFormat" ), QStringLiteral(
"MU" ) );
78 if ( format == QLatin1String(
"DM" ) || format == QLatin1String(
"DMS" ) || format == QLatin1String(
"D" ) )
87 geo = ct.transform( point );
95 if ( format == QLatin1String(
"DM" ) )
97 else if ( format == QLatin1String(
"DMS" ) )
109 double QgsCoordinateUtils::dmsToDecimal(
const QString &
string,
bool *ok )
111 const QString negative( QStringLiteral(
"swSW-" ) );
113 bool okValue =
false;
124 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 );
125 QRegularExpressionMatch match = dms.match(
string.trimmed() );
126 if ( match.hasMatch() )
128 QString dms1 = match.captured( 2 );
129 QString dms2 = match.captured( 3 );
130 QString dms3 = match.captured( 4 );
132 double v = dms3.toDouble( ok );
136 if ( !dms2.isEmpty() )
138 v = dms2.toInt( ok ) + v / 60.0;
142 v = dms1.toInt( ok ) + v / 60.0;
146 QString sign1 = match.captured( 1 );
147 QString sign2 = match.captured( 5 );
149 if ( sign1.isEmpty() )
151 value = !sign2.isEmpty() && negative.contains( sign2 ) ? -v : v;
153 else if ( sign2.isEmpty() )
155 value = !sign1.isEmpty() && negative.contains( sign1 ) ? -v : v;
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.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Custom exception class for Coordinate Reference System related exceptions.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
This class represents a coordinate reference system (CRS).
A class to represent a 2D point.
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
Reads an integer from the specified scope and key.