18 #include <QStringList>
23 double currentDist = 0;
36 if ( currentDist <= minDist )
38 minDist = currentDist;
39 minDistPoint = vertex;
40 id.part = vertexId.
part;
41 id.ring = vertexId.
ring;
42 id.vertex = vertexId.
vertex;
51 bool polygonType = ( geom.
dimension() == 2 );
56 if ( coords.
size() <= atVertex.
part )
79 else if ( atVertex.
vertex == 0 )
82 if ( polygonType && ring.
size() > 3 )
107 return ( pt1.
x() - pt2.
x() ) * ( pt1.
x() - pt2.
x() ) + ( pt1.
y() - pt2.
y() ) * ( pt1.
y() - pt2.
y() );
114 double ny = -( x2 - x1 );
117 t = ( ptX * ny - ptY * nx - x1 * ny + y1 * nx ) / (( x2 - x1 ) * ny - ( y2 - y1 ) * nx );
131 minDistX = x1 + t * ( x2 - x1 );
132 minDistY = y1 + t * ( y2 - y1 );
135 double dist = ( minDistX - ptX ) * ( minDistX - ptX ) + ( minDistY - ptY ) * ( minDistY - ptY );
154 return f1*f2 - f3*f4;
159 double dx = directionPoint.
x() - startPoint.
x();
160 double dy = directionPoint.
y() - startPoint.
y();
161 double length = sqrt( dx * dx + dy * dy );
168 double scaleFactor = distance / length;
169 return QgsPointV2( startPoint.
x() + dx * scaleFactor, startPoint.
y() + dy * scaleFactor );
174 double angle = atan2( dy, dx ) * 180 /
M_PI;
179 else if ( angle > 360 )
188 double temp, bc, cd, det;
195 radius = sqrt( pow( pt2.
x() - pt1.
x(), 2.0 ) + pow( pt2.
y() - pt1.
y(), 2.0 ) );
199 temp = pt2.
x() * pt2.
x() + pt2.
y() * pt2.
y();
200 bc = ( pt1.
x() * pt1.
x() + pt1.
y() * pt1.
y() - temp ) / 2.0;
201 cd = ( temp - pt3.
x() * pt3.
x() - pt3.
y() * pt3.
y() ) / 2.0;
202 det = ( pt1.
x() - pt2.
x() ) * ( pt2.
y() - pt3.
y() ) - ( pt2.
x() - pt3.
x() ) * ( pt1.
y() - pt2.
y() );
212 centerX = ( bc * ( pt2.
y() - pt3.
y() ) - cd * ( pt1.
y() - pt2.
y() ) ) * det;
213 centerY = (( pt1.
x() - pt2.
x() ) * cd - ( pt2.
x() - pt3.
x() ) * bc ) * det;
214 radius = sqrt(( centerX - pt1.
x() ) * ( centerX - pt1.
x() ) + ( centerY - pt1.
y() ) * ( centerY - pt1.
y() ) );
219 if ( angle3 >= angle1 )
221 if ( angle2 > angle1 && angle2 < angle3 )
232 if ( angle2 > angle1 || angle2 < angle3 )
247 if ( angle2 < angle1 )
249 return ( angle <= angle1 && angle >= angle2 );
253 return ( angle <= angle1 || angle >= angle2 );
258 if ( angle2 > angle1 )
260 return ( angle >= angle1 && angle <= angle2 );
264 return ( angle >= angle1 || angle <= angle2 );
277 double centerX, centerY, radius;
279 double length =
M_PI / 180.0 * radius *
sweepAngle( centerX, centerY, x1, y1, x2, y2, x3, y3 );
293 if ( p3Angle >= p1Angle )
295 if ( p2Angle > p1Angle && p2Angle < p3Angle )
297 return( p3Angle - p1Angle );
301 return ( - ( p1Angle + ( 360 - p3Angle ) ) );
306 if ( p2Angle < p1Angle && p2Angle > p3Angle )
308 return( -( p1Angle - p3Angle ) );
312 return( p3Angle + ( 360 - p1Angle ) );
319 QgsPointV2 midPoint(( p1.
x() + p2.
x() ) / 2.0, ( p1.
y() + p2.
y() ) / 2.0 );
321 if ( radius < midDist )
325 double centerMidDist = sqrt( radius * radius - midDist * midDist );
326 double dist = radius - centerMidDist;
328 double midDx = midPoint.
x() - p1.
x();
329 double midDy = midPoint.
y() - p1.
y();
340 int minDistIndex = -1;
341 for (
int i = 0; i < possibleMidPoints.
size(); ++i )
343 double currentDist =
sqrDistance2D( mousePos, possibleMidPoints.
at( i ) );
344 if ( currentDist < minDist )
347 minDist = currentDist;
351 if ( minDistIndex == -1 )
356 result = possibleMidPoints.
at( minDistIndex );
362 int dim = 2 + is3D + isMeasure;
364 foreach (
const QString& pointCoordinates, wktCoordinateList.
split(
",", QString::SkipEmptyParts ) )
366 QStringList coordinates = pointCoordinates.
split(
" ", QString::SkipEmptyParts );
367 if ( coordinates.
size() < dim )
371 double x = coordinates[idx++].toDouble();
372 double y = coordinates[idx++].toDouble();
374 double z = is3D ? coordinates[idx++].toDouble() : 0.;
375 double m = isMeasure ? coordinates[idx++].toDouble() : 0.;
400 wkb << static_cast<quint32>( points.
size() );
403 wkb << point.
x() << point.
y();
443 if ( strCoordinates.
endsWith(
" " ) )
444 strCoordinates.
chop( 1 );
447 return elemCoordinates;
453 elemPosList.
setAttribute(
"srsDimension", is3D ? 3 : 2 );
462 if ( strCoordinates.
endsWith(
" " ) )
463 strCoordinates.
chop( 1 );
488 QRegExp cooRegEx(
"^[^\\(]*\\((.*)\\)[^\\)]*$" );
490 return qMakePair( wkbType, contents );
498 for (
int i = 0, n = wkt.
length(); i < n; ++i )
500 if ( wkt[i].isSpace() && level == 0 )
503 if ( wkt[i] ==
',' && level == 0 )
508 block.
prepend( defaultType +
" " );
516 else if ( wkt[i] ==
')' )
523 block.
prepend( defaultType +
" " );
static QgsPointV2 pointOnLineWithDistance(const QgsPointV2 &startPoint, const QgsPointV2 &directionPoint, double distance)
Returns a point a specified distance toward a second point.
QString cap(int nth) const
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 (...
static bool circleAngleBetween(double angle, double angle1, double angle2, bool clockwise)
Returns true if, in a circle, angle is between angle1 and angle2.
static double ccwAngle(double dy, double dx)
Returns the counter clockwise angle between a line with components dx, dy and the line with dx > 0 an...
QDomNode appendChild(const QDomNode &newChild)
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QString & prepend(QChar ch)
static QString pointsToWKT(const QList< QgsPointV2 > &points, int precision, bool is3D, bool isMeasure)
Returns a WKT coordinate list.
const T & at(int i) const
static QString pointsToJSON(const QList< QgsPointV2 > &points, int precision)
Returns a geoJSON coordinates string.
static void circleCenterRadius(const QgsPointV2 &pt1, const QgsPointV2 &pt2, const QgsPointV2 &pt3, double &radius, double ¢erX, double ¢erY)
Returns radius and center of the circle through pt1, pt2, pt3.
Abstract base class for all geometries.
static QStringList wktGetChildBlocks(const QString &wkt, const QString &defaultType="")
Parses a WKT string and returns of list of blocks contained in the WKT.
static QgsPointV2 closestVertex(const QgsAbstractGeometryV2 &geom, const QgsPointV2 &pt, QgsVertexId &id)
Returns the closest vertex to a geometry for a specified point.
static double leftOfLine(double x, double y, double x1, double y1, double x2, double y2)
Returns < 0 if point(x/y) is left of the line x1,y1 -> x2,y2.
static double circleLength(double x1, double y1, double x2, double y2, double x3, double y3)
Length of a circular string segment defined by pt1, pt2, pt3.
QDomElement createElementNS(const QString &nsURI, const QString &qName)
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
int indexIn(const QString &str, int offset, CaretMode caretMode) const
static bool circleClockwise(double angle1, double angle2, double angle3)
Returns true if circle is ordered clockwise.
void append(const T &value)
static void adjacentVertices(const QgsAbstractGeometryV2 &geom, const QgsVertexId &atVertex, QgsVertexId &beforeVertex, QgsVertexId &afterVertex)
Returns vertices adjacent to a specified vertex within a geometry.
static double sqrDistance2D(const QgsPointV2 &pt1, const QgsPointV2 &pt2)
Returns the squared 2D distance between two points.
Utility class for identifying a unique vertex within a geometry.
void setAttribute(const QString &name, const QString &value)
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
static bool angleOnCircle(double angle, double angle1, double angle2, double angle3)
Returns true if an angle is between angle1 and angle3 on a circle described by angle1, angle2 and angle3.
virtual bool nextVertex(QgsVertexId &id, QgsPointV2 &vertex) const =0
Returns next vertex id and coordinates.
QDomText createTextNode(const QString &value)
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
static QDomElement pointsToGML3(const QList< QgsPointV2 > &points, QDomDocument &doc, int precision, const QString &ns, bool is3D)
Returns a gml::posList DOM element.
QString qgsDoubleToString(const double &a, const int &precision=17)
static bool segmentMidPoint(const QgsPointV2 &p1, const QgsPointV2 &p2, QgsPointV2 &result, double radius, const QgsPointV2 &mousePos)
Calculates midpoint on circle passing through p1 and p2, closest to given coordinate.
static double sweepAngle(double centerX, double centerY, double x1, double y1, double x2, double y2, double x3, double y3)
Calculates angle of a circular string part defined by pt1, pt2, pt3.
virtual int dimension() const =0
Returns the inherent dimension of the geometry.
static QList< QgsPointV2 > pointsFromWKT(const QString &wktCoordinateList, bool is3D, bool isMeasure)
Returns a list of points contained in a WKT string.
virtual void coordinateSequence(QList< QList< QList< QgsPointV2 > > > &coord) const =0
Retrieves the sequence of geometries, rings and nodes.
static double sqrDistToLine(double ptX, double ptY, double x1, double y1, double x2, double y2, double &minDistX, double &minDistY, double epsilon)
Returns the squared distance between a point and a line.
static Type parseType(const QString &wktStr)
static void pointsToWKB(QgsWkbPtr &wkb, const QList< QgsPointV2 > &points, bool is3D, bool isMeasure)
Returns a LinearRing { uint32 numPoints; Point points[numPoints]; }.
static QDomElement pointsToGML2(const QList< QgsPointV2 > &points, QDomDocument &doc, int precision, const QString &ns)
Returns a gml::coordinates DOM element.