4

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.

4

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. – ar-siddiqui Sep 23 '20 at 16:37
-2

You can find the answer here. There is lot of expalanations available for adding WFS layer in QGIS. This might help you.

2
  • Thanks for the answer Ahsan but I'm not trying to add a layer to the map, I'm trying to add the server connections to QGIS. – batesydownunder Sep 21 '18 at 6:54
  • If the answer to another question answers this question then that usually means that two questions should be duplicates. However, @batesydownunder seems to be saying that this answer does not correspond to their question. – PolyGeo Sep 21 '18 at 6:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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