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")

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Casian Pavel
  • 193
  • 6

2 Answers2

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).

user30184
  • 65,331
  • 4
  • 65
  • 118
  • 8
    You can use QgsProviderRegistry.instance().providerList() to get the whole list of all available data provider keys. – christoph Jan 04 '21 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. – Kadir Şahbaz Jan 04 '21 at 20:02
  • 1
    @KadirŞahbaz only wanted to complete the answer of user30184. Don‘t feel we have a competition here ;-) – christoph Jan 04 '21 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. – Kadir Şahbaz Jan 04 '21 at 20:20
  • @KadirŞahbaz thanks a lot, your‘e a really honorable member of the community! – christoph Jan 04 '21 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']
Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389