QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsgeocoderlocatorfilter.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsgeocoderlocatorfilter.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_qgsgeocoderlocatorfilter.cpp"
18#include "qgsmapcanvas.h"
19#include "qgsmessagelog.h"
20#include "qgsgeocoderresult.h"
21
22QgsGeocoderLocatorFilter::QgsGeocoderLocatorFilter( const QString &name, const QString &displayName, const QString &prefix, QgsGeocoderInterface *geocoder, QgsMapCanvas *canvas, const QgsRectangle &boundingBox )
23 : QgsAbstractGeocoderLocatorFilter( name, displayName, prefix, geocoder, boundingBox )
24 , mCanvas( canvas )
25{
26
27}
28
30{
31 QgsLocatorFilter *filter = new QgsGeocoderLocatorFilter( name(), displayName(), prefix(), geocoder(), mCanvas );
32 filter->setFetchResultsDelay( fetchResultsDelay() );
33 return filter;
34}
35
36void QgsGeocoderLocatorFilter::handleGeocodeResult( const QgsGeocoderResult &result )
37{
38 const QgsCoordinateTransform ct( result.crs(), mCanvas->mapSettings().destinationCrs(), mCanvas->mapSettings().transformContext() );
39 QgsGeometry g = result.geometry();
40 const QgsRectangle viewport = result.viewport();
41 try
42 {
43 QgsRectangle bounds;
44 g.transform( ct );
45 if ( viewport.isNull() )
46 {
47 bounds = g.boundingBox();
48 }
49 else
50 {
51 QgsCoordinateTransform extentTransform = ct;
52 extentTransform.setBallparkTransformsAreAppropriate( true );
53 bounds = extentTransform.transformBoundingBox( viewport );
54 }
55 mCanvas->zoomToFeatureExtent( bounds );
56
57 mCanvas->flashGeometries( QList< QgsGeometry >() << g );
58 }
59 catch ( QgsCsException & )
60 {
61 QgsMessageLog::logMessage( tr( "Could not transform result to canvas CRS" ) );
62 }
63}
64
An abstract base class which implements a locator filter populated from a QgsGeocoderInterface.
QgsGeocoderInterface * geocoder() const
Returns the geocoder attached to the filter.
Class for doing transforms between two map coordinate systems.
void setBallparkTransformsAreAppropriate(bool appropriate)
Sets whether approximate "ballpark" results are appropriate for this coordinate transform.
QgsRectangle transformBoundingBox(const QgsRectangle &rectangle, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool handle180Crossover=false) const
Transforms a rectangle from the source CRS to the destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
Interface for geocoders.
Definition qgsgeocoder.h:37
An adapter class which implements a locator filter populated from a QgsGeocoderInterface.
QgsLocatorFilter * clone() const override SIP_FACTORY
QgsGeocoderLocatorFilter(const QString &name, const QString &displayName, const QString &prefix, QgsGeocoderInterface *geocoder, QgsMapCanvas *canvas, const QgsRectangle &boundingBox=QgsRectangle())
Constructor for QgsGeocoderLocatorFilter.
Represents a matching result from a geocoder search.
QgsRectangle viewport() const
Returns the suggested viewport for the result, which reflects a recommended map extent for displaying...
QgsCoordinateReferenceSystem crs() const
Returns the coordinate reference system for the calculated geometry().
QgsGeometry geometry() const
Returns the resultant geometry resulting from the geocoding operation.
A geometry is the spatial representation of a feature.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
QgsRectangle boundingBox() const
Returns the bounding box of the geometry.
Abstract base class for filters which collect locator results.
void setFetchResultsDelay(int delay)
Sets a delay (in milliseconds) for the filter to wait prior to fetching results.
Map canvas is a class for displaying all GIS data types on a canvas.
void flashGeometries(const QList< QgsGeometry > &geometries, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem(), const QColor &startColor=QColor(255, 0, 0, 255), const QColor &endColor=QColor(255, 0, 0, 0), int flashes=3, int duration=500)
Causes a set of geometries to flash within the canvas.
void zoomToFeatureExtent(QgsRectangle &rect)
Zooms to feature extent.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
A rectangle specified with double values.