QGIS API Documentation 4.3.0-Master (ffcfc20b9b4)
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
21
22#include <QString>
23
24using namespace Qt::StringLiterals;
25
27
28QString QgsStDbscanClusteringAlgorithm::name() const
29{
30 return u"stdbscanclustering"_s;
31}
32
33QString QgsStDbscanClusteringAlgorithm::displayName() const
34{
35 return QObject::tr( "ST-DBSCAN clustering" );
36}
37
38QString QgsStDbscanClusteringAlgorithm::shortDescription() const
39{
40 return QObject::tr( "Clusters spatiotemporal point features using a time and density based scan algorithm." );
41}
42
43QStringList QgsStDbscanClusteringAlgorithm::tags() const
44{
45 return QObject::tr( "clustering,clusters,density,based,points,temporal,time,interval,duration,distance" ).split( ',' );
46}
47
48QString QgsStDbscanClusteringAlgorithm::group() const
49{
50 return QObject::tr( "Vector analysis" );
51}
52
53QString QgsStDbscanClusteringAlgorithm::groupId() const
54{
55 return u"vectoranalysis"_s;
56}
57
58void QgsStDbscanClusteringAlgorithm::initAlgorithm( const QVariantMap & )
59{
60 QGS_MARK_ALGORITHM_SOURCE
61
62 addParameter( new QgsProcessingParameterFeatureSource( u"INPUT"_s, QObject::tr( "Input layer" ), QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::VectorPoint ) ) );
63 addParameter( new QgsProcessingParameterField( u"DATETIME_FIELD"_s, QObject::tr( "Date/time field" ), QVariant(), u"INPUT"_s, Qgis::ProcessingFieldParameterDataType::DateTime, false, false ) );
64
65 addParameter( new QgsProcessingParameterNumber( u"MIN_SIZE"_s, QObject::tr( "Minimum cluster size" ), Qgis::ProcessingNumberParameterType::Integer, 5, false, 1 ) );
66 addParameter( new QgsProcessingParameterDistance( u"EPS"_s, QObject::tr( "Maximum distance between clustered points" ), 1, u"INPUT"_s, false, 0 ) );
67 auto durationParameter = std::make_unique<QgsProcessingParameterDuration>( u"EPS2"_s, QObject::tr( "Maximum time duration between clustered points" ), 0, false, 0 );
68 durationParameter->setDefaultUnit( Qgis::TemporalUnit::Hours );
69 addParameter( durationParameter.release() );
70
71 auto dbscanStarParam = std::make_unique<QgsProcessingParameterBoolean>( u"DBSCAN*"_s, QObject::tr( "Treat border points as noise (DBSCAN*)" ), false, true );
72 dbscanStarParam->setFlags( dbscanStarParam->flags() | Qgis::ProcessingParameterFlag::Advanced );
73 addParameter( dbscanStarParam.release() );
74
75 auto fieldNameParam = std::make_unique<QgsProcessingParameterString>( u"FIELD_NAME"_s, QObject::tr( "Cluster field name" ), u"CLUSTER_ID"_s );
76 fieldNameParam->setFlags( fieldNameParam->flags() | Qgis::ProcessingParameterFlag::Advanced );
77 addParameter( fieldNameParam.release() );
78 auto sizeFieldNameParam = std::make_unique<QgsProcessingParameterString>( u"SIZE_FIELD_NAME"_s, QObject::tr( "Cluster size field name" ), u"CLUSTER_SIZE"_s );
79 sizeFieldNameParam->setFlags( sizeFieldNameParam->flags() | Qgis::ProcessingParameterFlag::Advanced );
80 addParameter( sizeFieldNameParam.release() );
81
82 addParameter( new QgsProcessingParameterFeatureSink( u"OUTPUT"_s, QObject::tr( "Clusters" ), Qgis::ProcessingSourceType::VectorPoint ) );
83
84 addOutput( new QgsProcessingOutputNumber( u"NUM_CLUSTERS"_s, QObject::tr( "Number of clusters" ) ) );
85}
86
87QString QgsStDbscanClusteringAlgorithm::shortHelpString() const
88{
89 return QObject::tr( "Clusters point features based on a 2D implementation of spatiotemporal density-based clustering of applications with noise (ST-DBSCAN) algorithm." );
90}
91
92QList<QgsAcademicReference> QgsStDbscanClusteringAlgorithm::academicReferences() const
93{
95 { u"Ester, M."_s, u"Kriegel, H. P."_s, u"Sander, J."_s, u"Xu, X."_s },
96 1996,
97 u"A Density-Based Algorithm for Discovering Clusters in Large Spatial Databases with Noise"_s,
98 u"Proceedings of the 2nd International Conference on Knowledge Discovery and Data Mining, Portland, OR"_s,
99 u"AAAI Press"_s,
100 u"226-231"_s
101 );
102
103 const QgsAcademicReference birantReference = QgsAcademicReference::
104 createJournalArticle( { u"Birant, D."_s, u"Kut, A."_s }, 2007, u"ST-DBSCAN: An algorithm for clustering spatial–temporal data"_s, u"Data & Knowledge Engineering"_s, u"60"_s, u"1"_s, u"208-221"_s );
105
106 const QgsAcademicReference pecaReference = QgsAcademicReference::
107 createPresentation( { u"Peca, I."_s, u"Fuchs, G."_s, u"Vrotsou, K."_s, u"Andrienko, N. V."_s, u"Andrienko, G. L."_s }, 2012, u"Scalable Cluster Analysis of Spatial Events"_s, u"EuroVA@ EuroVis"_s );
108
109 return { esterReference, birantReference, pecaReference };
110}
111
112QgsStDbscanClusteringAlgorithm *QgsStDbscanClusteringAlgorithm::createInstance() const
113{
114 return new QgsStDbscanClusteringAlgorithm();
115}
116
@ VectorPoint
Vector point layers.
Definition qgis.h:3750
@ DateTime
Accepts datetime fields.
Definition qgis.h:4039
@ Hours
Hours.
Definition qgis.h:5662
@ Advanced
Parameter is an advanced parameter which should be hidden from users by default.
Definition qgis.h:3982
Encapsulates an academic reference and formats it according to style guidelines.
static QgsAcademicReference createPresentation(const QStringList &authors, int year, const QString &title, const QString &meeting, const QString &publisher=QString(), const QString &pages=QString())
Creates a conference paper or presentation reference.
static QgsAcademicReference createJournalArticle(const QStringList &authors, int year, const QString &title, const QString &journal, const QString &volume=QString(), const QString &issue=QString(), const QString &pages=QString())
Creates a journal article reference.
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.