Select to view content in your preferred language

changing layer order in contents programmatically (i.e. using arcpy)

1871
3
Jump to solution
08-01-2018 04:10 PM
MarkJones7
Regular Contributor

I have created a python script that takes csv files, converts them into feature class and then adds them to the map. I am using ArcGIS Pro so the function used is:

arcpy.management.XYTableToPoint(stabbings_in_table, stabbings_out_feature_class,stabbings_x_coords, stabbings_y_coords, stabbings_z_coords,arcpy.SpatialReference(2031))



I run this code two more times for the other two csv files I have. So, in the end my Contents section of the map has three layers in total: Homicides, Shootings, Stabbings

From there I then create the service definition and upload it to our internal Portal.

Here is my problem.

No matter what order I create the feature classes the Contents pane always ends up listing them in alphabetical order, which then causes the service definition/feature service to list them in alphabetical order as well. The order I need is:

[0] Stabbings

[1] Shootings

[2] Homicides

I know that inside of the actual map file you can click and drag on the layers to reorder them, but can this be done programmatically? My hope is that as long as the layers are in the order I need then they will stay in that order when the feature service is created.

Any help is greatly appreciated.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

You could try...

Alphabetical list of arcpy.mp classes—ArcPy | ArcGIS Desktop specifically

LayerFile—ArcPy | ArcGIS Desktop ...

but maybe if you set it up first and are using the same names, it might keep the order

I totally haven't tried this but I read about it here....

Introduction to sharing web layers—ArcGIS Pro | ArcGIS Desktop 

Preserve layer and table IDs

then

But I don't share maps, but might have to

View solution in original post

3 Replies
DanPatterson_Retired
MVP Emeritus

You could try...

Alphabetical list of arcpy.mp classes—ArcPy | ArcGIS Desktop specifically

LayerFile—ArcPy | ArcGIS Desktop ...

but maybe if you set it up first and are using the same names, it might keep the order

I totally haven't tried this but I read about it here....

Introduction to sharing web layers—ArcGIS Pro | ArcGIS Desktop 

Preserve layer and table IDs

then

But I don't share maps, but might have to

MarkJones7
Regular Contributor

you sir are an absolute GENIUS! Thank you! That worked perfectly!!

0 Kudos
DanPatterson_Retired
MVP Emeritus

Mark... glad it worked out