22using namespace Qt::StringLiterals;
26QString QgsExtractByExtentAlgorithm::name()
const
28 return u
"extractbyextent"_s;
31QString QgsExtractByExtentAlgorithm::displayName()
const
33 return QObject::tr(
"Extract/clip by extent" );
36QStringList QgsExtractByExtentAlgorithm::tags()
const
38 return QObject::tr(
"clip,extract,intersect,intersection,mask,extent" ).split(
',' );
41QString QgsExtractByExtentAlgorithm::group()
const
43 return QObject::tr(
"Vector overlay" );
46QString QgsExtractByExtentAlgorithm::groupId()
const
48 return u
"vectoroverlay"_s;
50void QgsExtractByExtentAlgorithm::initAlgorithm(
const QVariantMap & )
58QString QgsExtractByExtentAlgorithm::shortHelpString()
const
60 return QObject::tr(
"This algorithm creates a new vector layer that only contains features which fall within a specified extent. "
61 "Any features which intersect the extent will be included.\n\n"
62 "Optionally, feature geometries can also be clipped to the extent. If this option is selected, then the output "
63 "geometries will automatically be converted to multi geometries to ensure uniform output geometry types." );
66QString QgsExtractByExtentAlgorithm::shortDescription()
const
68 return QObject::tr(
"Creates a vector layer that only contains features which intersect a specified extent." );
71QgsExtractByExtentAlgorithm *QgsExtractByExtentAlgorithm::createInstance()
const
73 return new QgsExtractByExtentAlgorithm();
78 std::unique_ptr<QgsFeatureSource> featureSource( parameterAsSource( parameters, u
"INPUT"_s, context ) );
83 feedback->
pushWarning( QObject::tr(
"No spatial index exists for input layer, performance will be severely degraded" ) );
85 const QgsRectangle extent = parameterAsExtent( parameters, u
"EXTENT"_s, context, featureSource->sourceCrs() );
86 const bool clip = parameterAsBoolean( parameters, u
"CLIP"_s, context );
92 std::unique_ptr<QgsFeatureSink> sink( parameterAsSink( parameters, u
"OUTPUT"_s, context, dest, featureSource->fields(), outType, featureSource->sourceCrs() ) );
97 const QgsGeometry clipGeom = parameterAsExtentGeometry( parameters, u
"EXTENT"_s, context, featureSource->sourceCrs() );
99 const double step = featureSource->featureCount() > 0 ? 100.0 / featureSource->featureCount() : 1;
133 outputs.insert( u
"OUTPUT"_s, dest );
@ NotPresent
No spatial index exists for the source.
@ ExactIntersect
Use exact geometry intersection (slower) instead of bounding boxes.
WkbType
The WKB type describes the number of dimensions a geometry has.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Wraps a request for features to a vector layer (or directly its vector data provider).
@ FastInsert
Use faster inserts, at the cost of updating the passed features to reflect changes made at the provid...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
bool isCanceled() const
Tells whether the operation has been canceled already.
void setProgress(double progress)
Sets the current progress for the feedback object.
A geometry is the spatial representation of a feature.
QgsGeometry intersection(const QgsGeometry &geometry, const QgsGeometryParameters ¶meters=QgsGeometryParameters()) const
Returns a geometry representing the points shared by this geometry and other.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
Contains information about the context in which a processing algorithm is executed.
Custom exception class for processing related exceptions.
Base class for providing feedback from a processing algorithm.
virtual void pushWarning(const QString &warning)
Pushes a warning informational message from the algorithm.
A boolean parameter for processing algorithms.
A rectangular map extent parameter for processing algorithms.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
A rectangle specified with double values.
static Qgis::WkbType promoteNonPointTypesToMulti(Qgis::WkbType type)
Promotes a WKB geometry type to its multi-type equivalent, with the exception of point geometry types...