QGIS API Documentation 3.99.0-Master (357b655ed83)
Loading...
Searching...
No Matches
qgsalgorithmstdbscanclustering.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmstdbscanclustering.cpp
3 ---------------------
4 begin : July 2018
5 copyright : (C) 2018 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
20#include <QString>
21
22using namespace Qt::StringLiterals;
23
25
26QString QgsStDbscanClusteringAlgorithm::name() const
27{
28 return u"stdbscanclustering"_s;
29}
30
31QString QgsStDbscanClusteringAlgorithm::displayName() const
32{
33 return QObject::tr( "ST-DBSCAN clustering" );
34}
35
36QString QgsStDbscanClusteringAlgorithm::shortDescription() const
37{
38 return QObject::tr( "Clusters spatiotemporal point features using a time and density based scan algorithm." );
39}
40
41QStringList QgsStDbscanClusteringAlgorithm::tags() const
42{
43 return QObject::tr( "clustering,clusters,density,based,points,temporal,time,interval,duration,distance" ).split( ',' );
44}
45
46QString QgsStDbscanClusteringAlgorithm::group() const
47{
48 return QObject::tr( "Vector analysis" );
49}
50
51QString QgsStDbscanClusteringAlgorithm::groupId() const
52{
53 return u"vectoranalysis"_s;
54}
55
56void QgsStDbscanClusteringAlgorithm::initAlgorithm( const QVariantMap & )
57{
58 addParameter( new QgsProcessingParameterFeatureSource( u"INPUT"_s, QObject::tr( "Input layer" ), QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::VectorPoint ) ) );
59 addParameter( new QgsProcessingParameterField( u"DATETIME_FIELD"_s, QObject::tr( "Date/time field" ), QVariant(), u"INPUT"_s, Qgis::ProcessingFieldParameterDataType::DateTime, false, false ) );
60
61 addParameter( new QgsProcessingParameterNumber( u"MIN_SIZE"_s, QObject::tr( "Minimum cluster size" ), Qgis::ProcessingNumberParameterType::Integer, 5, false, 1 ) );
62 addParameter( new QgsProcessingParameterDistance( u"EPS"_s, QObject::tr( "Maximum distance between clustered points" ), 1, u"INPUT"_s, false, 0 ) );
63 auto durationParameter = std::make_unique<QgsProcessingParameterDuration>( u"EPS2"_s, QObject::tr( "Maximum time duration between clustered points" ), 0, false, 0 );
64 durationParameter->setDefaultUnit( Qgis::TemporalUnit::Hours );
65 addParameter( durationParameter.release() );
66
67 auto dbscanStarParam = std::make_unique<QgsProcessingParameterBoolean>( u"DBSCAN*"_s, QObject::tr( "Treat border points as noise (DBSCAN*)" ), false, true );
68 dbscanStarParam->setFlags( dbscanStarParam->flags() | Qgis::ProcessingParameterFlag::Advanced );
69 addParameter( dbscanStarParam.release() );
70
71 auto fieldNameParam = std::make_unique<QgsProcessingParameterString>( u"FIELD_NAME"_s, QObject::tr( "Cluster field name" ), u"CLUSTER_ID"_s );
72 fieldNameParam->setFlags( fieldNameParam->flags() | Qgis::ProcessingParameterFlag::Advanced );
73 addParameter( fieldNameParam.release() );
74 auto sizeFieldNameParam = std::make_unique<QgsProcessingParameterString>( u"SIZE_FIELD_NAME"_s, QObject::tr( "Cluster size field name" ), u"CLUSTER_SIZE"_s );
75 sizeFieldNameParam->setFlags( sizeFieldNameParam->flags() | Qgis::ProcessingParameterFlag::Advanced );
76 addParameter( sizeFieldNameParam.release() );
77
78 addParameter( new QgsProcessingParameterFeatureSink( u"OUTPUT"_s, QObject::tr( "Clusters" ), Qgis::ProcessingSourceType::VectorPoint ) );
79
80 addOutput( new QgsProcessingOutputNumber( u"NUM_CLUSTERS"_s, QObject::tr( "Number of clusters" ) ) );
81}
82
83QString QgsStDbscanClusteringAlgorithm::shortHelpString() const
84{
85 return QObject::tr( "Clusters point features based on a 2D implementation of spatiotemporal density-based clustering of applications with noise (ST-DBSCAN) algorithm.\n\n"
86 "For more details, please see the following papers:\n"
87 "* Ester, M., H. P. Kriegel, J. Sander, and X. Xu, \"A Density-Based Algorithm for Discovering Clusters in Large Spatial Databases with Noise\". In: Proceedings of the 2nd International Conference on Knowledge Discovery and Data Mining, Portland, OR, AAAI Press, pp. 226-231. 1996\n"
88 "* Birant, Derya, and Alp Kut. \"ST-DBSCAN: An algorithm for clustering spatial–temporal data.\" Data & Knowledge Engineering 60.1 (2007): 208-221.\n"
89 "* Peca, I., Fuchs, G., Vrotsou, K., Andrienko, N. V., & Andrienko, G. L. (2012). Scalable Cluster Analysis of Spatial Events. In EuroVA@ EuroVis." );
90}
91
92QgsStDbscanClusteringAlgorithm *QgsStDbscanClusteringAlgorithm::createInstance() const
93{
94 return new QgsStDbscanClusteringAlgorithm();
95}
96
@ VectorPoint
Vector point layers.
Definition qgis.h:3605
@ DateTime
Accepts datetime fields.
Definition qgis.h:3891
@ Hours
Hours.
Definition qgis.h:5270
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
Definition qgis.h:3834
A numeric output for processing algorithms.
A double numeric parameter for distance values.
A feature sink output for processing algorithms.
An input feature source (such as vector layers) parameter for processing algorithms.
A vector layer or feature source field parameter for processing algorithms.
A numeric parameter for processing algorithms.