5

I am trying to deploy multiple ArcGIS Feature Service connections to all of the QGIS 3 users in my workplace.

Is there a way to do it using the Python API?

At the moment I'm manually adding the connections into the QGIS3.ini, like this :

[qgis]
connections-arcgisfeatureserver\My%20Service%20Name\url=https://services.somewhere.com/arcgis/rest/services/My_Service_Name/MapServer
ARCGISFEATURESERVER\My%20Service%20Name\username=MyUsername
ARCGISFEATURESERVER\My%20Service%20Name\password=MyPassword
ARCGISFEATURESERVER\My%20Service%20Name\authcfg=

but I would prefer to add them using Python if possible.

1
  • You can find the answer here. There is lot of expalanations available for adding WFS layer in QGIS. This might help you. Commented Sep 21, 2018 at 6:28

1 Answer 1

5

See qgis.core.QgsSettings

Instantiate QgsSettings() in the QGIS console and you can access all the settings as keys/values

For ArcGIS FeatureServer, try:

[i for i in QSettings().allKeys() if 'arcgisfeatureserver' in i]

which will show all the keys for the featureserver settings.

For each feature service [SERVICENAME] and parameter [PARAM] the key [KEY] will be in the form:

'qgis/connections-arcgisfeatureserver/[SERVICENAME]/[PARAM]'

Which you can set using QgsSettings().setValue([KEY], [VALUE])

So for your feature service you would have

QgsSettings().setValue('qgis/connections-arcgisfeatureserver/[SERVICENAME]/url', [URL])
QgsSettings().setValue('qgis/connections-arcgisfeatureserver/[SERVICENAME]/username', [USERNAME])
QgsSettings().setValue('qgis/connections-arcgisfeatureserver/[SERVICENAME]/password', [PASSWORD])
QgsSettings().setValue('qgis/connections-arcgisfeatureserver/[SERVICENAME]/authcfg', '')

Then update the GUI with

iface.reloadConnections()

I think PyQt's QSettings() does the same thing too.

1
  • This solution has worked for me. It should be marked as the correct solution. Commented Sep 23, 2020 at 16:37

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.