QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
21 
22 QString QgsStDbscanClusteringAlgorithm::name() const
23 {
24  return QStringLiteral( "stdbscanclustering" );
25 }
26 
27 QString QgsStDbscanClusteringAlgorithm::displayName() const
28 {
29  return QObject::tr( "ST-DBSCAN clustering" );
30 }
31 
32 QString QgsStDbscanClusteringAlgorithm::shortDescription() const
33 {
34  return QObject::tr( "Clusters spatiotemporal point features using a time and density based scan algorithm." );
35 }
36 
37 QStringList QgsStDbscanClusteringAlgorithm::tags() const
38 {
39  return QObject::tr( "clustering,clusters,density,based,points,temporal,time,interval,duration,distance" ).split( ',' );
40 }
41 
42 QString QgsStDbscanClusteringAlgorithm::group() const
43 {
44  return QObject::tr( "Vector analysis" );
45 }
46 
47 QString QgsStDbscanClusteringAlgorithm::groupId() const
48 {
49  return QStringLiteral( "vectoranalysis" );
50 }
51 
52 void QgsStDbscanClusteringAlgorithm::initAlgorithm( const QVariantMap & )
53 {
54  addParameter( new QgsProcessingParameterFeatureSource( QStringLiteral( "INPUT" ),
55  QObject::tr( "Input layer" ), QList< int >() << QgsProcessing::TypeVectorPoint ) );
56  addParameter( new QgsProcessingParameterField( QStringLiteral( "DATETIME_FIELD" ),
57  QObject::tr( "Date/time field" ), QVariant(),
58  QStringLiteral( "INPUT" ), QgsProcessingParameterField::DateTime, false, false ) );
59 
60  addParameter( new QgsProcessingParameterNumber( QStringLiteral( "MIN_SIZE" ), QObject::tr( "Minimum cluster size" ),
62  addParameter( new QgsProcessingParameterDistance( QStringLiteral( "EPS" ),
63  QObject::tr( "Maximum distance between clustered points" ), 1, QStringLiteral( "INPUT" ), false, 0 ) );
64  auto durationParameter = std::make_unique<QgsProcessingParameterDuration>( QStringLiteral( "EPS2" ),
65  QObject::tr( "Maximum time duration between clustered points" ), 0, false, 0 );
66  durationParameter->setDefaultUnit( QgsUnitTypes::TemporalHours );
67  addParameter( durationParameter.release() );
68 
69  auto dbscanStarParam = std::make_unique<QgsProcessingParameterBoolean>( QStringLiteral( "DBSCAN*" ),
70  QObject::tr( "Treat border points as noise (DBSCAN*)" ), false, true );
71  dbscanStarParam->setFlags( dbscanStarParam->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
72  addParameter( dbscanStarParam.release() );
73 
74  auto fieldNameParam = std::make_unique<QgsProcessingParameterString>( QStringLiteral( "FIELD_NAME" ),
75  QObject::tr( "Cluster field name" ), QStringLiteral( "CLUSTER_ID" ) );
76  fieldNameParam->setFlags( fieldNameParam->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
77  addParameter( fieldNameParam.release() );
78  auto sizeFieldNameParam = std::make_unique<QgsProcessingParameterString>( QStringLiteral( "SIZE_FIELD_NAME" ),
79  QObject::tr( "Cluster size field name" ), QStringLiteral( "CLUSTER_SIZE" ) );
80  sizeFieldNameParam->setFlags( sizeFieldNameParam->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
81  addParameter( sizeFieldNameParam.release() );
82 
83  addParameter( new QgsProcessingParameterFeatureSink( QStringLiteral( "OUTPUT" ), QObject::tr( "Clusters" ), QgsProcessing::TypeVectorPoint ) );
84 
85  addOutput( new QgsProcessingOutputNumber( QStringLiteral( "NUM_CLUSTERS" ), QObject::tr( "Number of clusters" ) ) );
86 }
87 
88 QString QgsStDbscanClusteringAlgorithm::shortHelpString() const
89 {
90  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"
91  "For more details, please see the following papers:\n"
92  "* 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"
93  "* Birant, Derya, and Alp Kut. \"ST-DBSCAN: An algorithm for clustering spatial–temporal data.\" Data & Knowledge Engineering 60.1 (2007): 208-221.\n"
94  "* Peca, I., Fuchs, G., Vrotsou, K., Andrienko, N. V., & Andrienko, G. L. (2012). Scalable Cluster Analysis of Spatial Events. In EuroVA@ EuroVis." );
95 }
96 
97 QgsStDbscanClusteringAlgorithm *QgsStDbscanClusteringAlgorithm::createInstance() const
98 {
99  return new QgsStDbscanClusteringAlgorithm();
100 }
101 
103 
104 
QgsProcessingParameterNumber
A numeric parameter for processing algorithms.
Definition: qgsprocessingparameters.h:2179
qgsalgorithmstdbscanclustering.h
QgsProcessingParameterDefinition::FlagAdvanced
@ FlagAdvanced
Parameter is an advanced parameter which should be hidden from users by default.
Definition: qgsprocessingparameters.h:451
QgsProcessingParameterFeatureSource
An input feature source (such as vector layers) parameter for processing algorithms.
Definition: qgsprocessingparameters.h:3057
QgsProcessing::TypeVectorPoint
@ TypeVectorPoint
Vector point layers.
Definition: qgsprocessing.h:49
QgsProcessingOutputNumber
A numeric output for processing algorithms.
Definition: qgsprocessingoutputs.h:312
QgsProcessingParameterFeatureSink
A feature sink output for processing algorithms.
Definition: qgsprocessingparameters.h:3219
QgsProcessingParameterField::DateTime
@ DateTime
Accepts datetime fields.
Definition: qgsprocessingparameters.h:2950
QgsProcessingParameterNumber::Integer
@ Integer
Integer values.
Definition: qgsprocessingparameters.h:2186
QgsProcessingParameterDistance
A double numeric parameter for distance values. Linked to a source layer or CRS parameter to determin...
Definition: qgsprocessingparameters.h:2282
QgsUnitTypes::TemporalHours
@ TemporalHours
Hours.
Definition: qgsunittypes.h:154
QgsProcessingParameterField
A vector layer or feature source field parameter for processing algorithms.
Definition: qgsprocessingparameters.h:2940