33 : mFeaturePool( pool )
35 , mGeometry( feature.geometry() )
36 , mMapCrs( useMapCrs )
47 QgsDebugError( QStringLiteral(
"Shrug. What shall we do with a geometry that cannot be converted?" ) );
59 return mFeaturePool->crs();
64 return mFeaturePool->layerPtr();
69 return mFeaturePool->layerId();
79 return QStringLiteral(
"%1:%2" ).arg( mFeaturePool->layerName() ).arg( mFeature.id() );
84 return layerId() == other.
layerId() && mFeature.id() == other.mFeature.
id();
89 return layerId() != other.
layerId() || mFeature.id() != other.mFeature.
id();
99 nextLayerFeature(
true );
103 : mLayerIt( rh.mLayerIt )
104 , mFeatureIt( rh.mFeatureIt )
105 , mParent( rh.mParent )
106 , mCurrentFeature( std::make_unique<
LayerFeature>( *rh.mCurrentFeature.get() ) )
127 Q_ASSERT( mCurrentFeature );
128 return *mCurrentFeature;
133 return mLayerIt != other.mLayerIt || mFeatureIt != other.mFeatureIt;
138 nextLayerFeature(
false );
141bool QgsGeometryCheckerUtils::LayerFeatures::iterator::nextLayerFeature(
bool begin )
143 if ( !
begin && nextFeature(
false ) )
147 while ( nextLayer(
begin ) )
150 if ( nextFeature(
true ) )
156 mFeatureIt = QgsFeatureIds::const_iterator();
157 mCurrentFeature.reset();
161bool QgsGeometryCheckerUtils::LayerFeatures::iterator::nextLayer(
bool begin )
169 if ( mLayerIt == mParent->mLayerIds.end() )
173 if ( mParent->mGeometryTypes.contains( mParent->mFeaturePools[*mLayerIt]->geometryType() ) )
175 mFeatureIt = mParent->mFeatureIds[*mLayerIt].constBegin();
183bool QgsGeometryCheckerUtils::LayerFeatures::iterator::nextFeature(
bool begin )
186 const QgsFeatureIds &featureIds = mParent->mFeatureIds[*mLayerIt];
193 if ( mFeatureIt == featureIds.end() )
197 if ( mParent->mFeedback )
198 mParent->mFeedback->setProgress( mParent->mFeedback->progress() + 1.0 );
202 mCurrentFeature = std::make_unique<LayerFeature>( featurePool, feature, mParent->mContext, mParent->mUseMapCrs );
213 : mFeaturePools( featurePools )
214 , mFeatureIds( featureIds )
215 , mLayerIds( featurePools.keys() )
216 , mGeometryTypes( geometryTypes )
217 , mFeedback( feedback )
218 , mContext( context )
219 , mUseMapCrs( useMapCrs )
223 : mFeaturePools( featurePools )
224 , mLayerIds( layerIds )
226 , mGeometryTypes( geometryTypes )
227 , mContext( context )
230 for (
const QString &layerId : layerIds )
233 if ( geometryTypes.contains( featurePool->
geometryType() ) )
247 return iterator( mLayerIds.constBegin(),
this );
252 return iterator( mLayerIds.end(),
this );
261 return collection->geometryN( partIdx );
270 return collection->geometryN( partIdx );
277 QList<const QgsLineString *> rings;
280 rings.append( exterior );
282 for (
int iInt = 0, nInt = polygon->
numInteriorRings(); iInt < nInt; ++iInt )
286 rings.append( interior );
296 for (
int nParts = geom->
partCount(), iPart = nParts - 1; iPart >= 0; --iPart )
298 if ( !qgsgeometry_cast<QgsSurface *>( geomCollection->geometryN( iPart ) ) )
300 geomCollection->removeGeometry( iPart );
308 const double nom = std::fabs( ( p2.
y() - p1.
y() ) * q.
x() - ( p2.
x() - p1.
x() ) * q.
y() + p2.
x() * p1.
y() - p2.
y() * p1.
x() );
309 const double dx = p2.
x() - p1.
x();
310 const double dy = p2.
y() - p1.
y();
311 return nom / std::sqrt( dx * dx + dy * dy );
317 for (
int i = 0 + excludeExtremities; i < nVerts - 1 - excludeExtremities; ++i )
332 QList<QgsPoint> intersections;
334 bool intersection =
false;
335 for (
int i = 0, n = line1->
vertexCount() - 1; i < n; ++i )
337 for (
int j = 0, m = line2->
vertexCount() - 1; j < m; ++j )
345 intersections.append( inter );
349 return intersections;
357 for (
int iPart1 = 0, nParts1 = geom1->
partCount(); iPart1 < nParts1; ++iPart1 )
359 for (
int iRing1 = 0, nRings1 = geom1->
ringCount( iPart1 ); iRing1 < nRings1; ++iRing1 )
361 for (
int iVert1 = 0, jVert1 = 1, nVerts1 = geom1->
vertexCount( iPart1, iRing1 ); jVert1 < nVerts1; iVert1 = jVert1++ )
365 const double lambdap1 = 0.;
378 for (
int iPart2 = 0, nParts2 = geom2->
partCount(); iPart2 < nParts2; ++iPart2 )
380 for (
int iRing2 = 0, nRings2 = geom2->
ringCount( iPart2 ); iRing2 < nRings2; ++iRing2 )
382 for (
int iVert2 = 0, jVert2 = 1, nVerts2 = geom2->
vertexCount( iPart2, iRing2 ); jVert2 < nVerts2; iVert2 = jVert2++ )
391 double lambdaq1 =
QgsVector( q1.
x() - p1.
x(), q1.
y() - p1.
y() ) * d;
392 double lambdaq2 =
QgsVector( q2.
x() - p1.
x(), q2.
y() - p1.
y() ) * d;
393 if ( lambdaq1 > lambdaq2 )
395 std::swap( lambdaq1, lambdaq2 );
397 const double lambda1 = std::max( lambdaq1, lambdap1 );
398 const double lambda2 = std::min( lambdaq2, lambdap2 );
399 len += std::max( 0., lambda2 - lambda1 );
@ Reverse
Reverse/inverse transform (from destination to source)
Abstract base class for all geometries.
virtual int ringCount(int part=0) const =0
Returns the number of rings of which this geometry is built.
virtual int vertexCount(int part=0, int ring=0) const =0
Returns the number of vertices of which this geometry is built.
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
virtual int partCount() const =0
Returns count of parts contained in the geometry.
This class represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
Custom exception class for Coordinate Reference System related exceptions.
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
int vertexCount(int part=0, int ring=0) const override
Returns the number of vertices of which this geometry is built.
QgsPoint vertexAt(QgsVertexId id) const override
Returns the point corresponding to a specified vertex id.
Defines a QGIS exception class.
A feature pool is based on a vector layer and caches features.
Qgis::GeometryType geometryType() const
The geometry type of this layer.
QgsCoordinateReferenceSystem crs() const
The coordinate reference system of this layer.
QgsFeatureIds getIntersects(const QgsRectangle &rect) const
Gets all feature ids in the bounding box rect.
bool getFeature(QgsFeatureId id, QgsFeature &feature)
Retrieves the feature with the specified id into feature.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Base configuration for geometry checks.
const QgsCoordinateTransformContext transformContext
The coordinate transform context with which transformations will be done.
const QgsCoordinateReferenceSystem mapCrs
The coordinate system in which calculations should be done.
A layer feature combination to uniquely identify and access a feature in a set of layers.
LayerFeature(const QgsFeaturePool *pool, const QgsFeature &feature, const QgsGeometryCheckContext *context, bool useMapCrs)
Create a new layer/feature combination.
QString layerId() const
The layer id.
QgsGeometry geometry() const
Returns the geometry of this feature.
QString id() const
Returns a combination of the layerId and the feature id.
bool operator==(const QgsGeometryCheckerUtils::LayerFeature &other) const
QgsFeature feature() const
Returns the feature.
QPointer< QgsVectorLayer > layer() const
The layer.
bool operator!=(const QgsGeometryCheckerUtils::LayerFeature &other) const
bool useMapCrs() const
Returns if the geometry is reprojected to the map CRS or not.
QgsCoordinateReferenceSystem layerCrs() const
The layer CRS.
An iterator over all features in a QgsGeometryCheckerUtils::LayerFeatures.
const iterator & operator++()
Increments the item the iterator currently points to by one and returns the new iterator.
const QgsGeometryCheckerUtils::LayerFeature & operator*() const
Dereferences the item at the current iterator location.
iterator(const QStringList::const_iterator &layerIt, const LayerFeatures *parent)
Creates a new iterator.
bool operator!=(const iterator &other) const
Contains a set of layers and feature ids in those layers to pass to a geometry check.
iterator end() const
One after the last feature to stop iterating.
LayerFeatures(const QMap< QString, QgsFeaturePool * > &featurePools, const QMap< QString, QgsFeatureIds > &featureIds, const QList< Qgis::GeometryType > &geometryTypes, QgsFeedback *feedback, const QgsGeometryCheckContext *context, bool useMapCrs=false)
Creates a new set of layer and features.
iterator begin() const
The first feature to start iterating.
static void filter1DTypes(QgsAbstractGeometry *geom)
static QList< const QgsLineString * > polygonRings(const QgsPolygon *polygon)
static QgsAbstractGeometry * getGeomPart(QgsAbstractGeometry *geom, int partIdx)
static double sharedEdgeLength(const QgsAbstractGeometry *geom1, const QgsAbstractGeometry *geom2, double tol)
static QList< QgsPoint > lineIntersections(const QgsLineString *line1, const QgsLineString *line2, double tol)
static bool pointOnLine(const QgsPoint &p, const QgsLineString *line, double tol, bool excludeExtremities=false)
static bool segmentIntersection(const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q1, const QgsPoint &q2, QgsPoint &intersectionPoint, bool &isIntersection, double tolerance=1e-8, bool acceptImproperIntersection=false)
Compute the intersection between two segments.
static Q_DECL_DEPRECATED double sqrDistance2D(double x1, double y1, double x2, double y2)
Returns the squared 2D distance between (x1, y1) and (x2, y2).
A geometry is the spatial representation of a feature.
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.
Line string geometry type, with support for z-dimension and m-values.
Point geometry type, with support for z-dimension and m-values.
A rectangle specified with double values.
A class to represent a vector.
QgsVector normalized() const
Returns the vector's normalized (or "unit") vector (ie same angle but length of 1....
QSet< QgsFeatureId > QgsFeatureIds
double pointLineDist(const QgsPoint &p1, const QgsPoint &p2, const QgsPoint &q)
#define QgsDebugError(str)
Utility class for identifying a unique vertex within a geometry.