7

What's a provider in PyQGIS and how many types of providers exist?

I am really not sure what a provider does. There is an example below from PyQGIS cookbook where a provider is used to load a QgsVectorLayer.

#get the path to the shapefile e.g. /home/project/data/ports.shp
path_to_airports_layer = "testdata/airports.shp"

#The format is:
vlayer = QgsVectorLayer(data_source, layer_name, provider_name)

vlayer = QgsVectorLayer(path_to_airports_layer, "Airports layer", "ogr")

2 Answers 2

11

Provider is a piece of code that reads and perhaps writes data from some source. The official providers you can find from the source code but there are also other providers that users have written for their special needs. Check these two directories:

https://github.com/qgis/QGIS/tree/master/src/core/providers

  • arcgis
  • ept
  • gdal
  • memory
  • meshmemory
  • ogr

https://github.com/qgis/QGIS/tree/master/src/providers

  • arcgisrest
  • db2
  • delimitedtext
  • geonode
  • gpx
  • grass
  • mdal
  • mssql
  • oracle
  • ows
  • pdal
  • postgres
  • spatialite
  • virtual
  • wcs
  • wfs
  • wms

GDAL and OGR providers can read any format that GDAL supports, that is https://gdal.org/drivers/raster/index.html and https://gdal.org/drivers/vector/index.html. It is possible to read some formats either with a native provider or by using GDAL/OGR (for example SpatiaLite).

5
  • 8
    You can use QgsProviderRegistry.instance().providerList() to get the whole list of all available data provider keys.
    – christoph
    Jan 4, 2021 at 14:50
  • 2
    @christoph It would be nice if you added this information as an answer instead of a comment. I was going to add that as an answer but you specified it first. Jan 4, 2021 at 20:02
  • 1
    @KadirŞahbaz only wanted to complete the answer of user30184. Don‘t feel we have a competition here ;-)
    – christoph
    Jan 4, 2021 at 20:11
  • @christoph I don't feel so. But it wouldn't be ethical to present something that someone else first mentioned as if it were his/her own thought. And the information you gave is worth enough to be a separate answer for future users. Jan 4, 2021 at 20:20
  • @KadirŞahbaz thanks a lot, your‘e a really honorable member of the community!
    – christoph
    Jan 4, 2021 at 20:24
7

You can use QgsProviderRegistry.instance().providerList() to get the whole list of all available data provider keys.

# OUTPUT
['DB2', 'OAPIF', 'WFS', 'arcgisfeatureserver', 'arcgismapserver',
 'delimitedtext', 'gdal', 'geonode', 'gpx', 'grass', 'grassraster',
 'mdal', 'memory', 'mesh_memory', 'mssql', 'ogr', 'ows', 'postgres', 
 'postgresraster', 'spatialite', 'vectortile', 'virtual', 'wcs', 'wms']
1
  • This answer comes from christoph's comment under user30184's answer. It was added as a separate "Community Wiki" answer. Jan 4, 2021 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.