28 #include <QRegularExpression> 47 else if ( std::isnan( z ) )
49 if ( std::isnan( m ) )
54 else if ( std::isnan( m ) )
63 , mZ( std::numeric_limits<double>::quiet_NaN() )
64 , mM( std::numeric_limits<double>::quiet_NaN() )
72 , mZ( std::numeric_limits<double>::quiet_NaN() )
73 , mM( std::numeric_limits<double>::quiet_NaN() )
81 , mZ(
QgsWkbTypes::hasZ( wkbType ) ? z : std::numeric_limits<double>::quiet_NaN() )
82 , mM(
QgsWkbTypes::hasM( wkbType ) ? m : std::numeric_limits<double>::quiet_NaN() )
102 bool equal = pt->
wkbType() == type;
106 equal &=
qgsDoubleNear( pt->
z(), mZ, 1E-8 ) || ( std::isnan( pt->
z() ) && std::isnan( mZ ) );
108 equal &=
qgsDoubleNear( pt->
m(), mM, 1E-8 ) || ( std::isnan( pt->
m() ) && std::isnan( mM ) );
126 auto gridifyValue = [](
double value,
double spacing,
bool extraCondition = true ) ->
double 128 if ( spacing > 0 && extraCondition )
129 return std::round( value / spacing ) * spacing;
135 auto x = gridifyValue( mX, hSpacing );
136 auto y = gridifyValue( mY, vSpacing );
187 QRegularExpression
rx( QStringLiteral(
"\\s" ) );
188 QStringList coordinates = parts.second.split( rx, QString::SkipEmptyParts );
189 if ( coordinates.size() < 2 )
194 else if ( coordinates.size() == 3 && !
is3D() && !
isMeasure() )
200 else if ( coordinates.size() >= 4 && ( !
is3D() || !
isMeasure() ) )
209 mX = coordinates[idx++].toDouble();
210 mY = coordinates[idx++].toDouble();
211 if (
is3D() && coordinates.length() > 2 )
212 mZ = coordinates[idx++].toDouble();
214 mM = coordinates[idx++].toDouble();
227 int binarySize =
sizeof( char ) +
sizeof( quint32 );
228 binarySize += ( 2 +
is3D() +
isMeasure() ) *
sizeof(
double );
231 wkbArray.resize( binarySize );
234 wkb << static_cast<quint32>(
wkbType() );
261 QDomElement elemPoint = doc.createElementNS( ns, QStringLiteral(
"Point" ) );
262 QDomElement elemCoordinates = doc.createElementNS( ns, QStringLiteral(
"coordinates" ) );
265 QString cs = QStringLiteral(
"," );
267 QString ts = QStringLiteral(
" " );
269 elemCoordinates.setAttribute( QStringLiteral(
"cs" ), cs );
270 elemCoordinates.setAttribute( QStringLiteral(
"ts" ), ts );
273 elemCoordinates.appendChild( doc.createTextNode( strCoordinates ) );
274 elemPoint.appendChild( elemCoordinates );
280 QDomElement elemPoint = doc.createElementNS( ns, QStringLiteral(
"Point" ) );
281 QDomElement elemPosList = doc.createElementNS( ns, QStringLiteral(
"pos" ) );
282 elemPosList.setAttribute( QStringLiteral(
"srsDimension" ),
is3D() ? 3 : 2 );
287 elemPosList.appendChild( doc.createTextNode( strCoordinates ) );
288 elemPoint.appendChild( elemPosList );
300 return "{\"type\": \"Point\", \"coordinates\": [" 307 p.drawRect( QRectF( mX - 2, mY - 2, 4, 4 ) );
316 mZ = std::numeric_limits<double>::quiet_NaN();
321 mM = std::numeric_limits<double>::quiet_NaN();
357 if (
id.vertex != 0 )
370 Q_UNUSED( position );
383 Q_UNUSED( position );
400 Q_UNUSED( position );
407 Q_UNUSED( segmentPt );
408 Q_UNUSED( vertexAfter );
507 void QgsPoint::transform(
const QTransform &t,
double zTranslate,
double zScale,
double mTranslate,
double mScale )
511 t.map( mX, mY, &x, &y );
517 mZ = mZ * zScale + zTranslate;
521 mM = mM * mScale + mTranslate;
532 mZ = std::numeric_limits<double>::quiet_NaN();
543 mM = std::numeric_limits<double>::quiet_NaN();
558 mZ = std::numeric_limits<double>::quiet_NaN();
559 mM = std::numeric_limits<double>::quiet_NaN();
564 mM = std::numeric_limits<double>::quiet_NaN();
568 mZ = std::numeric_limits<double>::quiet_NaN();
584 return QPointF( mX, mY );
589 return std::sqrt( ( mX - x ) * ( mX - x ) + ( mY - y ) * ( mY - y ) );
594 return std::sqrt( ( mX - other.
x() ) * ( mX - other.
x() ) + ( mY - other.
y() ) * ( mY - other.
y() ) );
599 return ( mX - x ) * ( mX -
x ) + ( mY - y ) * ( mY -
y );
604 return ( mX - other.
x() ) * ( mX - other.
x() ) + ( mY - other.
y() ) * ( mY - other.
y() );
609 double zDistSquared = 0.0;
610 if (
is3D() || !std::isnan( z ) )
611 zDistSquared = ( mZ -
z ) * ( mZ - z );
613 return std::sqrt( ( mX - x ) * ( mX - x ) + ( mY - y ) * ( mY - y ) + zDistSquared );
618 double zDistSquared = 0.0;
620 zDistSquared = ( mZ - other.
z() ) * ( mZ - other.
z() );
622 return std::sqrt( ( mX - other.
x() ) * ( mX - other.
x() ) + ( mY - other.
y() ) * ( mY - other.
y() ) + zDistSquared );
627 double zDistSquared = 0.0;
628 if (
is3D() || !std::isnan( z ) )
629 zDistSquared = ( mZ -
z ) * ( mZ - z );
631 return ( mX - x ) * ( mX -
x ) + ( mY - y ) * ( mY -
y ) + zDistSquared;
636 double zDistSquared = 0.0;
638 zDistSquared = ( mZ - other.
z() ) * ( mZ - other.
z() );
640 return ( mX - other.
x() ) * ( mX - other.
x() ) + ( mY - other.
y() ) * ( mY - other.
y() ) + zDistSquared;
645 double dx = other.
x() - mX;
646 double dy = other.
y() - mY;
647 return ( std::atan2( dx, dy ) * 180.0 / M_PI );
657 double dz = other.
z() - mZ;
659 return ( std::acos( dz / distance ) * 180.0 / M_PI );
665 double radsXy = azimuth * M_PI / 180.0;
666 double dx = 0.0, dy = 0.0, dz = 0.0;
668 inclination = std::fmod( inclination, 360.0 );
675 dx = distance * std::sin( radsXy );
676 dy = distance * std::cos( radsXy );
680 double radsZ = inclination * M_PI / 180.0;
681 dx = distance * std::sin( radsZ ) * std::sin( radsXy );
682 dy = distance * std::sin( radsZ ) * std::cos( radsXy );
683 dz = distance * std::cos( radsZ );
686 return QgsPoint( mX + dx, mY + dy, mZ + dz, mM, pType );
701 return QStringLiteral(
"Point" );
716 Q_ASSERT( index == 0 );
722 double nan = std::numeric_limits<double>::quiet_NaN();
bool isMeasure() const
Returns true if the geometry contains m values.
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
void draw(QPainter &p) const override
Draws the geometry using the specified QPainter.
A rectangle specified with double values.
double segmentLength(QgsVertexId startVertex) const override
Returns the length of the segment of the geometry which begins at startVertex.
int nCoordinates() const override
Returns the number of nodes contained in the geometry.
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
QPointF toQPointF() const
Returns the point as a QPointF.
bool fromWkb(QgsConstWkbPtr &wkb) override
Sets the geometry from a WKB string.
static QPair< QgsWkbTypes::Type, QString > wktReadBlock(const QString &wkt)
Parses a WKT block of the format "TYPE( contents )" and returns a pair of geometry type to contents (...
int dimension() const override
Returns the inherent dimension of the geometry.
QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
QVector< QgsRingSequence > QgsCoordinateSequence
QgsPoint * toCurveType() const override
Returns the geometry converted to the more generic curve type.
Handles storage of information regarding WKB types and their properties.
double vertexAngle(QgsVertexId vertex) const override
Angle undefined.
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
double azimuth(const QgsPoint &other) const
Calculates azimuth between this point and other one (clockwise in degree, starting from north) ...
A class to represent a 2D point.
bool operator!=(const QgsAbstractGeometry &other) const override
static endian_t endian()
Returns whether this machine uses big or little endian.
bool removeDuplicateNodes(double epsilon=4 *DBL_EPSILON, bool useZValues=false) override
Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerat...
QString asJson(int precision=17) const override
Returns a GeoJSON representation of the geometry.
double inclination(const QgsPoint &other) const
Calculates inclination between this point and other one (starting from zenith = 0 to nadir = 180...
QDomElement asGml2(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML2 representation of the geometry.
void clear() override
Clears the geometry, ie reset it to a null geometry.
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
static Type dropM(Type type)
Drops the m dimension (if present) for a WKB type and returns the new type.
QgsPoint vertexAt(QgsVertexId) const override
Returns the point corresponding to a specified vertex id.
QgsWkbTypes::Type mWkbType
double y() const
Returns the point's y-coordinate.
bool dropZValue() override
Drops any z-dimensions which exist in the geometry.
bool moveVertex(QgsVertexId position, const QgsPoint &newPos) override
Moves a vertex within the geometry.
QString wktTypeStr() const
Returns the WKT type string of the geometry.
Type
The WKB type describes the number of dimensions a geometry has.
bool insertVertex(QgsVertexId position, const QgsPoint &vertex) override
Inserts a vertex into the geometry.
bool dropMValue() override
Drops any measure values which exist in the geometry.
virtual void clearCache() const
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.
Utility class for identifying a unique vertex within a geometry.
double closestSegment(const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf=nullptr, double epsilon=4 *DBL_EPSILON) const override
Searches for the closest segment of the geometry to a given point.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
T qgsgeometry_cast(const QgsAbstractGeometry *geom)
QgsPoint * clone() const override
Clones the geometry by performing a deep copy.
QgsPoint * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership...
double & rx()
Returns a reference to the x-coordinate of this point.
Abstract base class for all geometries.
bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const override
Returns next vertex id and coordinates.
double distanceSquared3D(double x, double y, double z) const
Returns the 3D squared distance between this point a specified x, y, z coordinate.
void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const override
Returns the vertices adjacent to a specified vertex within a geometry.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
QgsPoint project(double distance, double azimuth, double inclination=90.0) const
Returns a new point which correspond to this point projected by a specified distance with specified a...
Point geometry type, with support for z-dimension and m-values.
int ringCount(int=0) const override
Returns the number of rings of which this geometry is built.
bool operator==(const QgsAbstractGeometry &other) const override
int vertexCount(int=0, int=0) const override
Returns the number of vertices of which this geometry is built.
QVector< QgsPoint > QgsPointSequence
double m() const
Returns the point's m value.
QVector< QgsPointSequence > QgsRingSequence
int partCount() const override
Returns count of parts contained in the geometry.
QDomElement asGml3(QDomDocument &doc, int precision=17, const QString &ns="gml") const override
Returns a GML3 representation of the geometry.
bool fromWkt(const QString &wkt) override
Sets the geometry from a WKT string.
bool isEmpty() const override
Returns true if the geometry is empty.
static Type dropZ(Type type)
Drops the z dimension (if present) for a WKB type and returns the new type.
QByteArray asWkb() const override
Returns a WKB representation of the geometry.
QgsPoint(double x=0.0, double y=0.0, double z=std::numeric_limits< double >::quiet_NaN(), double m=std::numeric_limits< double >::quiet_NaN(), QgsWkbTypes::Type wkbType=QgsWkbTypes::Unknown)
Construct a point with the provided initial coordinate values.
bool convertTo(QgsWkbTypes::Type type) override
Converts the geometry to a specified type.
bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
double z() const
Returns the point's z-coordinate.
QgsCoordinateSequence coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
static bool hasM(Type type)
Tests whether a WKB type contains m values.
QString geometryType() const override
Returns a unique string representing the geometry type.
QgsPoint childPoint(int index) const override
Returns point at index (for geometries without child geometries - i.e.
bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
int childCount() const override
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
double distanceSquared(double x, double y) const
Returns the squared distance between this point a specified x, y coordinate.
static Type flatType(Type type)
Returns the flat type for a WKB type.
QgsWkbTypes::Type readHeader() const
readHeader
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
double ANALYSIS_EXPORT leftOf(const QgsPoint &thepoint, const QgsPoint *p1, const QgsPoint *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'. Negativ values mean left a...
void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) override
Transforms the geometry using a coordinate transform.
double distance3D(double x, double y, double z) const
Returns the 3D distance between this point and a specified x, y, z coordinate.
double x() const
Returns the point's x-coordinate.
QgsPoint * snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0) const override
Makes a new geometry with all the points or vertices snapped to the closest point of the grid...
int vertexNumberFromVertexId(QgsVertexId id) const override
Returns the vertex number corresponding to a vertex id.