Skip to content

Commit

Permalink
[FEATURE][processing] Add a batch nominatim geocoder algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Mar 5, 2021
1 parent 7eaa5b7 commit f2b4948
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/analysis/CMakeLists.txt
Expand Up @@ -37,6 +37,7 @@ set(QGIS_ANALYSIS_SRCS
processing/qgsalgorithmassignprojection.cpp
processing/qgsalgorithmattributeindex.cpp
processing/qgsalgorithmbatchgeocode.cpp
processing/qgsalgorithmbatchnominatimgeocode.cpp
processing/qgsalgorithmboundary.cpp
processing/qgsalgorithmboundingbox.cpp
processing/qgsalgorithmbuffer.cpp
Expand Down Expand Up @@ -321,6 +322,7 @@ set(QGIS_ANALYSIS_HDRS
network/qgsvectorlayerdirector.h

processing/qgsalgorithmbatchgeocode.h
processing/qgsalgorithmbatchnominatimgeocode.h
processing/qgsalgorithmfiledownloader.h
processing/qgsalgorithmimportphotos.h
processing/qgsnativealgorithms.h
Expand Down
59 changes: 59 additions & 0 deletions src/analysis/processing/qgsalgorithmbatchnominatimgeocode.cpp
@@ -0,0 +1,59 @@
/***************************************************************************
qgsalgorithmbatchnominatimgeocode.cpp
------------------
begin : December 2020
copyright : (C) 2020 by Mathieu Pellerin
email : nirvn dot asia 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 "qgsalgorithmbatchgeocode.h"
#include "qgsalgorithmbatchnominatimgeocode.h"
#include "qgsgeocoder.h"
#include "qgsgeocoderresult.h"
#include "qgsgeocodercontext.h"
#include "qgsvectorlayer.h"

///@cond PRIVATE

QgsBatchNominatimGeocodeAlgorithm::QgsBatchNominatimGeocodeAlgorithm()
: QgsBatchGeocodeAlgorithm( &mNominatimGeocoder )
{
}

QString QgsBatchNominatimGeocodeAlgorithm::name() const
{
return QStringLiteral( "batchnominatimgeocoder" );
}

QString QgsBatchNominatimGeocodeAlgorithm::displayName() const
{
return QObject::tr( "Batch Nominatim geocoder" );
}

QStringList QgsBatchNominatimGeocodeAlgorithm::tags() const
{
return QObject::tr( "geocode,nominatim,batch" ).split( ',' );
}

QgsBatchNominatimGeocodeAlgorithm *QgsBatchNominatimGeocodeAlgorithm::createInstance() const
{
return new QgsBatchNominatimGeocodeAlgorithm();
}

bool QgsBatchNominatimGeocodeAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
feedback->pushInfo( QObject::tr( "The Nominatim geocoder data is made available by OpenStreetMap Foundation and contributors. "
"It is provided under the ODbL license which requires to share alike. Visit https://nominatim.org/ to learn more." ) );
return QgsBatchGeocodeAlgorithm::prepareAlgorithm( parameters, context, feedback );
}

///@endcond
62 changes: 62 additions & 0 deletions src/analysis/processing/qgsalgorithmbatchnominatimgeocode.h
@@ -0,0 +1,62 @@
/***************************************************************************
qgsalgorithmbatchnominatimgeocode.h
------------------
begin : December 2020
copyright : (C) 2020 by Mathieu Pellerin
email : nirvn dot asia 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 QGSALGORITHMBATCHNOMINATIMGEOCODE_H
#define QGSALGORITHMBATCHNOMINATIMGEOCODE_H

#define SIP_NO_FILE

#include "qgis_sip.h"
#include "qgis_analysis.h"
#include "qgsprocessingalgorithm.h"
#include "qgsalgorithmbatchgeocode.h"
#include "qgsnominatimgeocoder.h"

///@cond PRIVATE

/**
* Native batch Nominatim geocoder.
*/
class QgsBatchNominatimGeocodeAlgorithm : public QgsBatchGeocodeAlgorithm
{

public:

/**
* Constructor for QgsBatchNominatimGeocodeAlgorithm.
*/
QgsBatchNominatimGeocodeAlgorithm();

QString name() const override;
QString displayName() const override;
QStringList tags() const override;
QgsBatchNominatimGeocodeAlgorithm *createInstance() const override SIP_FACTORY;

protected:
bool prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;

private:

QgsNominatimGeocoder mNominatimGeocoder;

};

///@endcond PRIVATE

#endif // QGSALGORITHMBATCHNOMINATIMGEOCODE_H


2 changes: 2 additions & 0 deletions src/analysis/processing/qgsnativealgorithms.cpp
Expand Up @@ -28,6 +28,7 @@
#include "qgsalgorithmaspect.h"
#include "qgsalgorithmassignprojection.h"
#include "qgsalgorithmattributeindex.h"
#include "qgsalgorithmbatchnominatimgeocode.h"
#include "qgsalgorithmboundary.h"
#include "qgsalgorithmboundingbox.h"
#include "qgsalgorithmbuffer.h"
Expand Down Expand Up @@ -259,6 +260,7 @@ void QgsNativeAlgorithms::loadAlgorithms()
addAlgorithm( new QgsAspectAlgorithm() );
addAlgorithm( new QgsAssignProjectionAlgorithm() );
addAlgorithm( new QgsAttributeIndexAlgorithm() );
addAlgorithm( new QgsBatchNominatimGeocodeAlgorithm() );
addAlgorithm( new QgsBookmarksToLayerAlgorithm() );
addAlgorithm( new QgsBoundaryAlgorithm() );
addAlgorithm( new QgsBoundingBoxAlgorithm() );
Expand Down

0 comments on commit f2b4948

Please sign in to comment.