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 auto gridifyValue = [](
double value,
double spacing,
bool extraCondition = true ) ->
double 104 if ( spacing > 0 && extraCondition )
105 return std::round( value / spacing ) * spacing;
111 auto x = gridifyValue( mX, hSpacing );
112 auto y = gridifyValue( mY, vSpacing );
163 QRegularExpression
rx( QStringLiteral(
"\\s" ) );
164 QStringList coordinates = parts.second.split( rx, QString::SkipEmptyParts );
165 if ( coordinates.size() < 2 )
170 else if ( coordinates.size() == 3 && !
is3D() && !
isMeasure() )
176 else if ( coordinates.size() >= 4 && ( !
is3D() || !
isMeasure() ) )
185 mX = coordinates[idx++].toDouble();
186 mY = coordinates[idx++].toDouble();
187 if (
is3D() && coordinates.length() > 2 )
188 mZ = coordinates[idx++].toDouble();
190 mM = coordinates[idx++].toDouble();
203 int binarySize =
sizeof( char ) +
sizeof( quint32 );
204 binarySize += ( 2 +
is3D() +
isMeasure() ) *
sizeof(
double );
207 wkbArray.resize( binarySize );
210 wkb << static_cast<quint32>(
wkbType() );
237 QDomElement elemPoint = doc.createElementNS( ns, QStringLiteral(
"Point" ) );
238 QDomElement elemCoordinates = doc.createElementNS( ns, QStringLiteral(
"coordinates" ) );
241 QString cs = QStringLiteral(
"," );
243 QString ts = QStringLiteral(
" " );
245 elemCoordinates.setAttribute( QStringLiteral(
"cs" ), cs );
246 elemCoordinates.setAttribute( QStringLiteral(
"ts" ), ts );
248 QString strCoordinates;
249 if ( axisOrder == QgsAbstractGeometry::AxisOrder::XY )
253 elemCoordinates.appendChild( doc.createTextNode( strCoordinates ) );
254 elemPoint.appendChild( elemCoordinates );
260 QDomElement elemPoint = doc.createElementNS( ns, QStringLiteral(
"Point" ) );
261 QDomElement elemPosList = doc.createElementNS( ns, QStringLiteral(
"pos" ) );
262 elemPosList.setAttribute( QStringLiteral(
"srsDimension" ),
is3D() ? 3 : 2 );
263 QString strCoordinates;
264 if ( axisOrder == QgsAbstractGeometry::AxisOrder::XY )
271 elemPosList.appendChild( doc.createTextNode( strCoordinates ) );
272 elemPoint.appendChild( elemPosList );
284 return "{\"type\": \"Point\", \"coordinates\": [" 291 p.drawRect( QRectF( mX - 2, mY - 2, 4, 4 ) );
300 mZ = std::numeric_limits<double>::quiet_NaN();
305 mM = std::numeric_limits<double>::quiet_NaN();
341 if (
id.vertex != 0 )
354 Q_UNUSED( position );
367 Q_UNUSED( position );
384 Q_UNUSED( position );
391 Q_UNUSED( segmentPt );
392 Q_UNUSED( vertexAfter );
491 void QgsPoint::transform(
const QTransform &t,
double zTranslate,
double zScale,
double mTranslate,
double mScale )
495 t.map( mX, mY, &x, &y );
501 mZ = mZ * zScale + zTranslate;
505 mM = mM * mScale + mTranslate;
516 mZ = std::numeric_limits<double>::quiet_NaN();
527 mM = std::numeric_limits<double>::quiet_NaN();
548 mZ = std::numeric_limits<double>::quiet_NaN();
549 mM = std::numeric_limits<double>::quiet_NaN();
554 mM = std::numeric_limits<double>::quiet_NaN();
558 mZ = std::numeric_limits<double>::quiet_NaN();
590 double zDistSquared = 0.0;
591 if (
is3D() || !std::isnan( z ) )
592 zDistSquared = ( mZ -
z ) * ( mZ - z );
594 return std::sqrt( ( mX - x ) * ( mX - x ) + ( mY - y ) * ( mY - y ) + zDistSquared );
599 double zDistSquared = 0.0;
601 zDistSquared = ( mZ - other.
z() ) * ( mZ - other.
z() );
603 return std::sqrt( ( mX - other.
x() ) * ( mX - other.
x() ) + ( mY - other.
y() ) * ( mY - other.
y() ) + zDistSquared );
608 double zDistSquared = 0.0;
609 if (
is3D() || !std::isnan( z ) )
610 zDistSquared = ( mZ -
z ) * ( mZ - z );
612 return ( mX - x ) * ( mX -
x ) + ( mY - y ) * ( mY -
y ) + zDistSquared;
617 double zDistSquared = 0.0;
619 zDistSquared = ( mZ - other.
z() ) * ( mZ - other.
z() );
621 return ( mX - other.
x() ) * ( mX - other.
x() ) + ( mY - other.
y() ) * ( mY - other.
y() ) + zDistSquared;
626 double dx = other.
x() - mX;
627 double dy = other.
y() - mY;
628 return ( std::atan2( dx, dy ) * 180.0 / M_PI );
638 double dz = other.
z() - mZ;
640 return ( std::acos( dz / distance ) * 180.0 / M_PI );
646 double radsXy = azimuth * M_PI / 180.0;
647 double dx = 0.0, dy = 0.0, dz = 0.0;
649 inclination = std::fmod( inclination, 360.0 );
656 dx = distance * std::sin( radsXy );
657 dy = distance * std::cos( radsXy );
661 double radsZ = inclination * M_PI / 180.0;
662 dx = distance * std::sin( radsZ ) * std::sin( radsXy );
663 dy = distance * std::sin( radsZ ) * std::cos( radsXy );
664 dz = distance * std::cos( radsZ );
667 return QgsPoint( mX + dx, mY + dy, mZ + dz, mM, pType );
682 return QStringLiteral(
"Point" );
697 Q_ASSERT( index == 0 );
703 double nan = std::numeric_limits<double>::quiet_NaN();
void swapXy() override
Swaps the x and y coordinates from the geometry.
double closestSegment(const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf=nullptr, double epsilon=4 *std::numeric_limits< double >::epsilon()) const override
Searches for the closest segment of the geometry to a given point.
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.
void transformVertices(const std::function< QgsPoint(const QgsPoint &) > &transform) override
Transforms the vertices from the geometry in place, applying the transform function to every vertex...
bool addZValue(double zValue=0) override
Adds a z-dimension to the geometry, initialized to a preset value.
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.
A class to represent a 2D point.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
void filterVertices(const std::function< bool(const QgsPoint &) > &filter) override
Filters the vertices from the geometry in place, removing any which do not return true for the filter...
double m() const
Returns the point's m value.
static endian_t endian()
Returns whether this machine uses big or little endian.
QString asJson(int precision=17) const override
Returns a GeoJSON 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.
static Type dropM(Type type)
Drops the m dimension (if present) for a WKB type and returns the new type.
double x() const
Returns the point's x-coordinate.
QgsPoint vertexAt(QgsVertexId) const override
Returns the point corresponding to a specified vertex id.
QgsWkbTypes::Type mWkbType
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.
Type
The WKB type describes the number of dimensions a geometry has.
bool isMeasure() const
Returns true if the geometry contains m values.
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.
double azimuth(const QgsPoint &other) const
Calculates azimuth between this point and other one (clockwise in degree, starting from north) ...
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.
QString wktTypeStr() const
Returns the WKT type string of the geometry.
Utility class for identifying a unique vertex within a geometry.
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.
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.
virtual void clearCache() const
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const override
Returns next vertex id and coordinates.
void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const override
Returns the vertices adjacent to a specified vertex within a geometry.
QgsWkbTypes::Type readHeader() const
readHeader
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.
AxisOrder
Axis order for GML generation.
double distance(double x, double y) const
Returns the distance between this point and a specified x, y coordinate.
int vertexCount(int=0, int=0) const override
Returns the number of vertices of which this geometry is built.
QVector< QgsPoint > QgsPointSequence
double z() const
Returns the point's z-coordinate.
QVector< QgsPointSequence > QgsRingSequence
int partCount() const override
Returns count of parts contained in 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.
QDomElement asGml2(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML2 representation of the geometry.
QByteArray asWkb() const override
Returns a WKB 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...
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 is3D() const
Returns true if the geometry is 3D and contains a z-value.
bool convertTo(QgsWkbTypes::Type type) override
Converts the geometry to a specified type.
QgsGeometryConstPartIterator parts() const
Returns Java-style iterator for traversal of parts of the geometry.
bool addMValue(double mValue=0) override
Adds a measure to the geometry, initialized to a preset value.
double y() const
Returns the point's y-coordinate.
QgsCoordinateSequence coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
bool removeDuplicateNodes(double epsilon=4 *std::numeric_limits< double >::epsilon(), bool useZValues=false) override
Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerat...
double distance3D(double x, double y, double z) const
Returns the 3D distance between this point and a specified x, y, z coordinate.
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.
QDomElement asGml3(QDomDocument &doc, int precision=17, const QString &ns="gml", QgsAbstractGeometry::AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const override
Returns a GML3 representation of the geometry.
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 distanceSquared3D(double x, double y, double z) const
Returns the 3D squared distance between this point a specified x, y, z coordinate.
static Type flatType(Type type)
Returns the flat type for a WKB type.
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...
void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) override SIP_THROW(QgsCsException)
Transforms the geometry using a coordinate transform.
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...
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.