Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[processing] port spatial index algorithm to C++
- Loading branch information
1 parent
7033c31
commit aed17ba
Showing
8 changed files
with
160 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/*************************************************************************** | ||
qgsalgorithmspatialraster.cpp | ||
--------------------- | ||
begin : November 2019 | ||
copyright : (C) 2019 by Alexander Bruy | ||
email : alexander dot bruy at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsalgorithmspatialindex.h" | ||
#include "qgsvectorlayer.h" | ||
#include "qgsvectordataprovider.h" | ||
|
||
///@cond PRIVATE | ||
|
||
QString QgsSpatialIndexAlgorithm::name() const | ||
{ | ||
return QStringLiteral( "createspatialindex" ); | ||
} | ||
|
||
QString QgsSpatialIndexAlgorithm::displayName() const | ||
{ | ||
return QObject::tr( "Create spatial index" ); | ||
} | ||
|
||
QStringList QgsSpatialIndexAlgorithm::tags() const | ||
{ | ||
return QObject::tr( "table,spatial,geometry,index,create,vector" ).split( ',' ); | ||
} | ||
|
||
QString QgsSpatialIndexAlgorithm::group() const | ||
{ | ||
return QObject::tr( "Vector general" ); | ||
} | ||
|
||
QString QgsSpatialIndexAlgorithm::groupId() const | ||
{ | ||
return QStringLiteral( "vectorgeneral" ); | ||
} | ||
|
||
QgsProcessingAlgorithm::Flags QgsSpatialIndexAlgorithm::flags() const | ||
{ | ||
return QgsProcessingAlgorithm::flags() | QgsProcessingAlgorithm::FlagNoThreading; | ||
} | ||
|
||
|
||
QString QgsSpatialIndexAlgorithm::shortHelpString() const | ||
{ | ||
return QObject::tr( "Creates an index to speed up access to the features " | ||
"in a layer based on their spatial location. Support " | ||
"for spatial index creation is dependent on the layer's " | ||
"data provider." ); | ||
} | ||
|
||
QgsSpatialIndexAlgorithm *QgsSpatialIndexAlgorithm::createInstance() const | ||
{ | ||
return new QgsSpatialIndexAlgorithm(); | ||
} | ||
|
||
void QgsSpatialIndexAlgorithm::initAlgorithm( const QVariantMap & ) | ||
{ | ||
addParameter( new QgsProcessingParameterVectorLayer( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) ); | ||
|
||
addOutput( new QgsProcessingOutputVectorLayer( QStringLiteral( "OUTPUT" ), QObject::tr( "Indexed layer" ) ) ); | ||
} | ||
|
||
QVariantMap QgsSpatialIndexAlgorithm::processAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) | ||
{ | ||
QgsVectorLayer *layer = parameterAsVectorLayer( parameters, QStringLiteral( "INPUT" ), context ); | ||
|
||
if ( !layer ) | ||
throw QgsProcessingException( QObject::tr( "Could not load source layer for %1." ).arg( QStringLiteral( "INPUT" ) ) ); | ||
|
||
QgsVectorDataProvider *provider = layer->dataProvider(); | ||
|
||
if ( provider->capabilities() & QgsVectorDataProvider::CreateSpatialIndex ) | ||
{ | ||
if ( !provider->createSpatialIndex() ) | ||
{ | ||
feedback->pushInfo( QObject::tr( "Could not create spatial index" ) ); | ||
} | ||
} | ||
else | ||
{ | ||
feedback->pushInfo( QObject::tr( "Layer's data provider does not support spatial indexes" ) ); | ||
} | ||
|
||
QVariantMap outputs; | ||
outputs.insert( QStringLiteral( "OUTPUT" ), layer->id() ); | ||
return outputs; | ||
} | ||
|
||
///@endcond |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*************************************************************************** | ||
qgsalgorithmspatialindex.h | ||
------------------------------ | ||
begin : November 2019 | ||
copyright : (C) 2019 by Alexander Bruy | ||
email : alexander dot bruy at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSALGORITHMSPATIALINDEX_H | ||
#define QGSALGORITHMSPATIALINDEX_H | ||
|
||
#define SIP_NO_FILE | ||
|
||
#include "qgis_sip.h" | ||
#include "qgsprocessingalgorithm.h" | ||
|
||
///@cond PRIVATE | ||
|
||
/** | ||
* Native constant raster algorithm. | ||
*/ | ||
class QgsSpatialIndexAlgorithm : public QgsProcessingAlgorithm | ||
{ | ||
|
||
public: | ||
|
||
QgsSpatialIndexAlgorithm() = default; | ||
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override; | ||
QString name() const override; | ||
QString displayName() const override; | ||
QStringList tags() const override; | ||
QString group() const override; | ||
QString groupId() const override; | ||
Flags flags() const override; | ||
QString shortHelpString() const override; | ||
QgsSpatialIndexAlgorithm *createInstance() const override SIP_FACTORY; | ||
|
||
protected: | ||
|
||
QVariantMap processAlgorithm( const QVariantMap ¶meters, | ||
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override; | ||
}; | ||
|
||
///@endcond PRIVATE | ||
|
||
#endif // QGSALGORITHMSPATIALINDEX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters