QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
qgsbearingutils.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsbearingutils.cpp
3
-------------------
4
begin : October 2016
5
copyright : (C) 2016 by Nyall Dawson
6
email : nyall dot dawson at gmail dot com
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
15
* *
16
***************************************************************************/
17
18
#include "
qgsbearingutils.h
"
19
20
#include "
qgscoordinatereferencesystem.h
"
21
#include "
qgscoordinatetransform.h
"
22
#include "
qgscoordinatetransformcontext.h
"
23
#include "
qgsexception.h
"
24
#include "
qgspointxy.h
"
25
26
#include "moc_qgsbearingutils.cpp"
27
28
double
QgsBearingUtils::bearingTrueNorth
(
const
QgsCoordinateReferenceSystem
&crs,
const
QgsCoordinateTransformContext
&transformContext,
const
QgsPointXY
&point )
29
{
30
const
QgsCoordinateReferenceSystem
geographicCrs = crs.
toGeographicCrs
();
31
if
( !geographicCrs.
isValid
() )
32
return
0.0;
33
34
const
QgsCoordinateTransform
transform( crs, geographicCrs, transformContext );
35
36
if
( !transform.
isValid
() )
37
{
38
//raise
39
throw
QgsException
( QObject::tr(
"Could not create transform to calculate true north"
) );
40
}
41
42
if
( transform.
isShortCircuited
() )
43
return
0.0;
44
45
const
QgsPointXY
p1 = transform.
transform
( point );
46
47
// shift point a tiny bit north
48
QgsPointXY
p2 = p1;
49
p2.
setY
( p2.
y
() + 0.000001 );
50
51
//transform back
52
const
QgsPointXY
p3 = transform.
transform
( p2,
Qgis::TransformDirection::Reverse
);
53
54
// find bearing from point to p3
55
return
point.
azimuth
( p3 );
56
}
Qgis::TransformDirection::Reverse
@ Reverse
Reverse/inverse transform (from destination to source).
Definition
qgis.h:2884
QgsBearingUtils::bearingTrueNorth
static Q_INVOKABLE double bearingTrueNorth(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &transformContext, const QgsPointXY &point)
Returns the direction to true north from a specified point and for a specified coordinate reference s...
Definition
qgsbearingutils.cpp:28
QgsCoordinateReferenceSystem
Represents a coordinate reference system (CRS).
Definition
qgscoordinatereferencesystem.h:216
QgsCoordinateReferenceSystem::isValid
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Definition
qgscoordinatereferencesystem.cpp:1024
QgsCoordinateReferenceSystem::toGeographicCrs
QgsCoordinateReferenceSystem toGeographicCrs() const
Returns the geographic CRS associated with this CRS object.
Definition
qgscoordinatereferencesystem.cpp:3079
QgsCoordinateTransformContext
Contains information about the context in which a coordinate transform is executed.
Definition
qgscoordinatetransformcontext.h:61
QgsCoordinateTransform
Handles coordinate transforms between two coordinate systems.
Definition
qgscoordinatetransform.h:63
QgsCoordinateTransform::transform
QgsPointXY transform(const QgsPointXY &point, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const
Transform the point from the source CRS to the destination CRS.
Definition
qgscoordinatetransform.cpp:304
QgsCoordinateTransform::isShortCircuited
bool isShortCircuited() const
Returns true if the transform short circuits because the source and destination are equivalent.
Definition
qgscoordinatetransform.cpp:1310
QgsCoordinateTransform::isValid
bool isValid() const
Returns true if the coordinate transform is valid, ie both the source and destination CRS have been s...
Definition
qgscoordinatetransform.cpp:1305
QgsException
Defines a QGIS exception class.
Definition
qgsexception.h:34
QgsPointXY
Represents a 2D point.
Definition
qgspointxy.h:62
QgsPointXY::setY
void setY(double y)
Sets the y value of the point.
Definition
qgspointxy.h:132
QgsPointXY::azimuth
double azimuth(const QgsPointXY &other) const
Calculates azimuth between this point and other one (clockwise in degree, starting from north).
Definition
qgspointxy.cpp:85
QgsPointXY::y
double y
Definition
qgspointxy.h:66
qgsbearingutils.h
qgscoordinatereferencesystem.h
qgscoordinatetransform.h
qgscoordinatetransformcontext.h
qgsexception.h
qgspointxy.h
Generated on
for QGIS API Documentation by
1.17.0