QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
3d
qgscrosssection.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgscrosssection.cpp
3
---------------------
4
begin : January 2026
5
copyright : (C) 2026 by Dominik Cindrić
6
email : viper dot miniq at gmail dot com
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
16
#include "
qgscrosssection.h
"
17
18
#include "
qgscoordinatetransform.h
"
19
#include "
qgslinestring.h
"
20
#include "
qgspolygon.h
"
21
22
QgsCrossSection::QgsCrossSection
(
const
QgsPoint
&p1,
const
QgsPoint
&p2,
double
halfWidth
)
23
: mStartPoint( p1 )
24
, mEndPoint( p2 )
25
, mHalfWidth(
halfWidth
)
26
{}
27
28
QgsGeometry
QgsCrossSection::asGeometry
(
const
QgsCoordinateTransform
*ct )
const
29
{
30
if
( !
isValid
() )
31
return
QgsGeometry
();
32
33
QgsVector
vec( mEndPoint - mStartPoint );
34
vec = vec.
normalized
().
perpVector
();
35
36
QgsGeometry
geom;
37
if
( mHalfWidth == 0.0 )
38
{
39
QVector<QgsPointXY> points = { mStartPoint, mEndPoint };
40
geom =
QgsGeometry
(
new
QgsLineString
( points ) );
41
}
42
else
43
{
44
// clang-format off
45
QVector<QgsPointXY> points = {
46
mStartPoint + vec * mHalfWidth,
47
mEndPoint + vec * mHalfWidth,
48
mEndPoint - vec * mHalfWidth,
49
mStartPoint - vec * mHalfWidth
50
};
51
// clang-format on
52
geom =
QgsGeometry
(
new
QgsPolygon
(
new
QgsLineString
( points ) ) );
53
}
54
55
if
( ct )
56
{
57
try
58
{
59
geom.
transform
( *ct,
Qgis::TransformDirection::Reverse
);
60
}
61
catch
(
const
QgsCsException
& )
62
{
63
geom =
QgsGeometry
();
64
}
65
}
66
return
geom;
67
}
68
69
void
QgsCrossSection::nudgeLeft
(
double
distance )
70
{
71
nudge( distance );
72
}
73
74
void
QgsCrossSection::nudgeRight
(
double
distance )
75
{
76
nudge( -distance );
77
}
78
79
void
QgsCrossSection::nudge(
double
distance )
80
{
81
if
( !
isValid
() )
82
return
;
83
84
QgsVector
vec( mEndPoint - mStartPoint );
85
vec = vec.normalized().perpVector();
86
87
const
QgsVector
offset = vec * distance;
88
mStartPoint += offset;
89
mEndPoint += offset;
90
}
91
92
bool
QgsCrossSection::isValid
()
const
93
{
94
return
( mStartPoint != mEndPoint ) && ( mHalfWidth > 0.0 );
95
}
Qgis::TransformDirection::Reverse
@ Reverse
Reverse/inverse transform (from destination to source).
Definition
qgis.h:2884
QgsCoordinateTransform
Handles coordinate transforms between two coordinate systems.
Definition
qgscoordinatetransform.h:63
QgsCrossSection::halfWidth
double halfWidth() const
Returns the half-width of the cross section.
Definition
qgscrosssection.h:54
QgsCrossSection::QgsCrossSection
QgsCrossSection()=default
Constructs an invalid cross section.
QgsCrossSection::asGeometry
QgsGeometry asGeometry(const QgsCoordinateTransform *ct=nullptr) const
Returns the cross section extent as a geometry (Polygon or LineString).
Definition
qgscrosssection.cpp:28
QgsCrossSection::nudgeRight
void nudgeRight(double distance)
Nudges the cross section to the right by the specified distance.
Definition
qgscrosssection.cpp:74
QgsCrossSection::isValid
bool isValid() const
Returns cross section validity.
Definition
qgscrosssection.cpp:92
QgsCrossSection::nudgeLeft
void nudgeLeft(double distance)
Nudges the cross section to the left by the specified distance.
Definition
qgscrosssection.cpp:69
QgsCsException
Custom exception class for Coordinate Reference System related exceptions.
Definition
qgsexception.h:60
QgsGeometry
A geometry is the spatial representation of a feature.
Definition
qgsgeometry.h:267
QgsGeometry::transform
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
Definition
qgsgeometry.cpp:4177
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition
qgslinestring.h:49
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition
qgspoint.h:53
QgsPolygon
Polygon geometry type.
Definition
qgspolygon.h:37
QgsVector
Represent a 2-dimensional vector.
Definition
qgsvector.h:34
QgsVector::normalized
QgsVector normalized() const
Returns the vector's normalized (or "unit") vector (ie same angle but length of 1....
Definition
qgsvector.cpp:33
QgsVector::perpVector
QgsVector perpVector() const
Returns the perpendicular vector to this vector (rotated 90 degrees counter-clockwise).
Definition
qgsvector.h:163
qgscoordinatetransform.h
qgscrosssection.h
qgslinestring.h
qgspolygon.h
Generated on
for QGIS API Documentation by
1.17.0