QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgsabstractgeocoderlocatorfilter.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsabstractgeocoderlocatorfilter.cpp
3 ---------------
4 Date : August 2020
5 Copyright : (C) 2020 by Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17#include "moc_qgsabstractgeocoderlocatorfilter.cpp"
18#include "qgsgeocoder.h"
19#include "qgsgeocodercontext.h"
20
21QgsAbstractGeocoderLocatorFilter::QgsAbstractGeocoderLocatorFilter( const QString &name, const QString &displayName, const QString &prefix, QgsGeocoderInterface *geocoder, const QgsRectangle &boundingBox )
22 : mName( name )
23 , mDisplayName( displayName )
24 , mPrefix( prefix )
25 , mGeocoder( geocoder )
26 , mBoundingBox( boundingBox )
27{
28
29}
30
32{
33 return mName;
34}
35
37{
38 return mDisplayName;
39}
40
42{
43 return mPrefix;
44}
45
46void QgsAbstractGeocoderLocatorFilter::fetchResults( const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback )
47{
48 QgsGeocoderContext geocodeContext( context.transformContext );
49 geocodeContext.setAreaOfInterest( QgsGeometry::fromRect( context.targetExtent ) );
50 geocodeContext.setAreaOfInterestCrs( context.targetExtentCrs );
51
52 const QList< QgsGeocoderResult > results = mGeocoder->geocodeString( string, geocodeContext, feedback );
53 for ( const QgsGeocoderResult &result : results )
54 {
55 if ( result.isValid() )
56 {
57 const QgsLocatorResult locatorRes = geocoderResultToLocatorResult( result );
58 emit resultFetched( locatorRes );
59 }
60 }
61}
62
64{
65 const QgsGeocoderResult geocodeResult = locatorResultToGeocoderResult( result );
66 handleGeocodeResult( geocodeResult );
67}
68
73
75{
76 const QVariantMap attrs = result.userData().toMap();
77 QgsGeocoderResult geocodeResult( attrs.value( QStringLiteral( "identifier" ) ).toString(),
78 attrs.value( QStringLiteral( "geom" ) ).value< QgsGeometry >(),
79 attrs.value( QStringLiteral( "crs" ) ).value< QgsCoordinateReferenceSystem >() );
80 geocodeResult.setAdditionalAttributes( attrs.value( QStringLiteral( "attributes" ) ).toMap() );
81 geocodeResult.setViewport( attrs.value( QStringLiteral( "viewport" ) ).value< QgsRectangle >() );
82 geocodeResult.setDescription( result.description );
83 geocodeResult.setGroup( result.group );
84 return geocodeResult;
85}
86
88{
89 QVariantMap attrs;
90 attrs.insert( QStringLiteral( "identifier" ), result.identifier() );
91 attrs.insert( QStringLiteral( "geom" ), result.geometry() );
92 attrs.insert( QStringLiteral( "viewport" ), result.viewport() );
93 attrs.insert( QStringLiteral( "crs" ), result.crs() );
94 attrs.insert( QStringLiteral( "attributes" ), result.additionalAttributes() );
95 QgsLocatorResult res( this, result.identifier(), attrs );
96 res.description = result.description();
97 res.group = result.group();
98 return res;
99}
void fetchResults(const QString &string, const QgsLocatorContext &context, QgsFeedback *feedback) override
QgsAbstractGeocoderLocatorFilter(const QString &name, const QString &displayName, const QString &prefix, QgsGeocoderInterface *geocoder, const QgsRectangle &boundingBox=QgsRectangle())
Constructor for QgsAbstractGeocoderLocatorFilter.
void triggerResult(const QgsLocatorResult &result) override
QgsGeocoderInterface * geocoder() const
Returns the geocoder attached to the filter.
QgsGeocoderResult locatorResultToGeocoderResult(const QgsLocatorResult &result) const
Converts a locator result to a geocoder result.
QgsLocatorResult geocoderResultToLocatorResult(const QgsGeocoderResult &result)
Converts a geocoder result to a locator result.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Encapsulates the context of a geocoding operation.
void setAreaOfInterestCrs(const QgsCoordinateReferenceSystem &crs)
Sets the crs for the area of interest, which can be used to indicate the desired geographic area wher...
void setAreaOfInterest(const QgsGeometry &area)
Sets the optional area of interest, which can be used to indicate the desired geographic area where g...
Interface for geocoders.
Definition qgsgeocoder.h:37
virtual QList< QgsGeocoderResult > geocodeString(const QString &string, const QgsGeocoderContext &context, QgsFeedback *feedback=nullptr) const
Geocodes a string.
Represents a matching result from a geocoder search.
QString description() const
Returns the optional description for the result.
void setAdditionalAttributes(const QVariantMap &attributes)
Setss additional attributes generated during the geocode, which may be added to features being geocod...
QString group() const
Returns the optional group value for the result.
QString identifier() const
Returns the identifier string for the result.
QgsRectangle viewport() const
Returns the suggested viewport for the result, which reflects a recommended map extent for displaying...
void setDescription(const QString &description)
Sets an optional description for the result.
QgsCoordinateReferenceSystem crs() const
Returns the coordinate reference system for the calculated geometry().
void setGroup(const QString &group)
Sets the optional group value for the result.
void setViewport(const QgsRectangle &viewport)
Sets the suggested viewport for the result, which reflects a recommended map extent for displaying th...
QgsGeometry geometry() const
Returns the resultant geometry resulting from the geocoding operation.
QVariantMap additionalAttributes() const
Contains additional attributes generated during the geocode, which may be added to features being geo...
static QgsGeometry fromRect(const QgsRectangle &rect)
Creates a new geometry from a QgsRectangle.
Encapsulates the properties relating to the context of a locator search.
QgsCoordinateTransformContext transformContext
Coordinate transform context, to use whenever performing coordinate transformations inside a locator.
QgsCoordinateReferenceSystem targetExtentCrs
Coordinate reference system for the map extent variable.
QgsRectangle targetExtent
Map extent to target in results.
Encapsulates properties of an individual matching result found by a QgsLocatorFilter.
QString description
Descriptive text for result.
QVariant userData() const
Returns the userData.
QString group
Group the results by categories If left as empty string, this means that results are all shown withou...
A rectangle specified with double values.