16 Commits

Author SHA1 Message Date
Nyall Dawson
3f6b490218 Sipify 2025-04-02 11:11:10 +10:00
Nyall Dawson
3a578d6712 Header update 2024-08-13 20:28:55 +10:00
Nyall Dawson
046883fa9c Promote QgsWkbTypes enums to enum class, move to Qgis 2023-02-22 12:39:21 +10:00
Denis Rouzaud
ba8a445850 run sipify 2021-03-22 21:13:52 +01:00
Mathieu Pellerin
53928bdbcc
[locators] Add a bounding box property to the abstract geocoder locator filter base class (#42133) 2021-03-10 08:24:44 +07:00
nirvn
7eaa5b7074 [FEATURE][locator] Add a nominatim locator filter 2021-03-05 09:31:48 +07:00
Nyall Dawson
50b9beaad6 [sipify] Catch more class references and insert :py:class: annotations 2021-01-31 05:41:22 +10:00
nirvn
a057e56fd3 Address review 2020-12-15 13:47:43 +07:00
nirvn
ebc2695dc1 [FEATURE][geocoder] Add a nominatim API geocoder 2020-12-15 13:47:43 +07:00
Nyall Dawson
3a3e771d04 Cache google maps geocoder results so that we don't send the same
request multiple times
2020-12-15 14:22:59 +10:00
Nyall Dawson
1acfe1fbe6 Add group and description to QgsGeocoderResult, link in to locator,
and populate group in Google Maps geocoding results
2020-11-03 12:11:56 +10:00
Nyall Dawson
cbaeb99a72 Add optional viewport property for geocoder results
Allows specifying an optional recommended viewport bounds for
displaying the geocode result (e.g. the canvas extent to zoom
to for showing the results)
2020-11-03 12:11:56 +10:00
Nyall Dawson
e70caeb3e1 Add getter/setter for api key, region 2020-11-03 12:11:56 +10:00
Nyall Dawson
98d09715a4 [api] Add new class QgsGoogleMapsGeocoder
This geocoder utilises the Google Maps "geocoding" API in order to geocode
strings. The Google Maps service is not publicly available, and accordingly
an API key must be first obtained from Google and specified when constructing
this class.

(The user is responsible for managing their Google Maps API key, and ensuring
that the use of this geocoder does not exceed their usage limits! Excessive use
of the Google Maps geocoder API can result in charges being applied to the API key
holder.)

This is raw underlying API only. It is intended to be exposed to QGIS users only
via plugins, and does not result in any out-of-the-box Google Maps functionality.

In order for a plugin to use it, they must do something like this:

    # create a google maps geocoder
    api_key = 'my api key'
    coder = QgsGoogleMapsGeocoder(api_key)

    # add it to the locator bar
    filter = QgsGeocoderLocatorFilter('Google', 'Google', 'addr', coder, iface.mapCanvas())
    iface.registerLocatorFilter(filter)

Mini FAQ:

Q: Why is this being added to core, instead of a plugin?
A: While a plugin would be perfectly acceptable if we are only targetting QGIS desktop,
the intention here is to allow this underlying, low level class to be reused outside
of QGIS desktop (e.g. on QField) with a minimal amount of duplicate effort.
2020-11-03 12:11:56 +10:00
Nyall Dawson
9935bbe05e Add adapter class QgsGeocoderLocatorFilter
This class implements the required logic to bridge a
class which implements the QgsGeocoderInterface interface to a
QgsLocatorFilter. It allows easy creation of a locator filter
from a geocoder.

E.g.

    class GoogleGeocoder(QgsGeocoderInterface):
      ... class which implements QgsGeocoderInterface...

    my_google_geocoder = GoogleGeocoder(api_key)
    my_google_locator_filter = QgsGeocoderLocatorFilter('google', 'Google Maps', 'google', my_google_geocoder, iface.mapCanvas())
    iface.registerLocatorFilter(my_google_locator_filter)

Note:

There's an abstract base class QgsAbstractGeocoderLocatorFilter which
lives in core. This base class has the guts of the geocoder to filter
adapter logic, but it does NOT implement the part which actually zooms
the canvas to the geocode results (because it's in core!)

This abstract base class is in place for applications like QField,
where the GUI library and QgsMapCanvas is NOT used. Those applications
can then implement their own concrete class based on QgsAbstractGeocoderLocatorFilter
with the correct logic to zoom their interface to a region. Ultimately,
a single QgsGeocoderInterface could be usable across QGIS desktop, QField,
with almost all logic shared via the common abstract adapter class.
2020-11-02 11:22:48 +10:00
Nyall Dawson
4f6f163ead Move geocoder classes to core 2020-10-30 14:31:04 +10:00