TransWikia.com

Altering PostGIS query in layer data source using ArcPy with ArcGIS Pro

Geographic Information Systems Asked on February 21, 2021

I’ve loaded several layers from a PostgreSQL database with the PostGIS extension installed into an ArcGIS Pro 2.4 project.

I’d like to make the same map a few times for the data in several different identically structured schemas.

The layer data sources are defined using PostgreSQL queries.

for example I need to change SELECT * FROM california.scratch.d4_level_1_needs_pt
into SELECT * FROM california.scratch.d5_level_1_needs_pt

or a slightly more complicated query:

SELECT 
    geom,linkid,route,finalscore,urgency,mobilityscore,
FROM 
    california.scratch.d4_level_1_needs_ln

It looks like I can update the layer source using:

import arcpy, pprint
p = arcpy.mp.ArcGISProject('current')
m = p.listMaps()[0]
l = m.listLayers()[0]
pprint.pprint(l.connectionProperties)

and arcpy.mp.ArcGISProject().updateConnectionProperties()

but when I print the connectionProperties of one of the layers I don’t see the query. it gives me:

{'connection_info': {'authentication_mode': 'DBMS',
                     'database': 'california',
                     'db_connection_properties': '***.***.**.**',
                     'dbclient': 'postgresql',
                     'instance': 'sde:postgresql:***.***.**.**',
                     'password': '<*********>',
                     'server': '***.***.**.**',
                     'user': 'user'},
 'dataset': 'california.scratch.%d4_partners_surveys_3',
 'workspace_factory': 'SDE'}

I could update the value for key dataset but that doesn’t help me if I want to update the columns I’m pulling in via the query.

Additionally, is there any way to associate the connections I print in the python window with the layers in the list by Drawing Order?

I don’t see any unique identifying info.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP