A Python project - A river flow analysis - I've generated my vector polyline object for the rivers (four classifications) - how do I move this into a map?
This fc is saved in the gdb - a map already exists.
I want to use Python to add some symbology, but the code I'm using needs the layer to be in a map.
What I need to know is the Python code to send a layer to an existing map from the gdb without opening ArcGIS Pro and doing it manually.
I'd also like to know how to change the line thickness symbology with Python eventually.
Any help would be appreciated.
Solved! Go to Solution.
Solved - but I had to create a lyrx Layer File and move the layer to the map from there - but the result is what I wanted - thanks to Dan for pointing me in the right direction.
Not doing at all well with this - I'm either getting the syntax wrong or the file type is incompatible. The examples given are less than helpful.
Here is an illustration of what I want to do = in ArcGIS Pro it would be "right click>add to current map"
If you know the source data, then
Make Feature Layer (Data Management)—ArcGIS Pro | Documentation
followed by
Copy Features (Data Management)—ArcGIS Pro | Documentation
if you want it to be permanent
Thank you Dan,
That was painless - now I've got a 'Stream.lyr' fc, which should be more acceptable for Map methods.
I'll attempt to move this into the map now. (fingers crossed)
I feel I'm close, but I can't the script to accept the 'Stream_lyr' value - both full path and workspace get the same error.
This is with ArcGIS closed. The variables are accepted when I run the script with the 'insert layer' commented out.
I'm probably making a rookie mistake - but I'm out of ideas.
I can't tell from the script and the above as to whether you created a "layer" on disk as a *.lyrx file which would be in a folder or you want to make one from a featureclass in the geodatabase.
'Stream_lyr' is in the original gdb folder where the 'Stream' shapefile was.
I've just realised that the name 'Stream_lyr' is just the name I gave the script to output.
Checked - it's just a copy of my original file with a deceptive name - back to square one. 😞
Thanks anyway, for your help Dan.
So I still need to go from this to this - using Python script.
It's the inserted layer name that is killing me:
Full paths, indexes, simple strings, nothing works. ValueErrors at every turn
"layerfilename = r"C:\Users\OEM\Documents\Tony\Massey\Paper 2 Labs\Lab7_Rasters\Wellington\Wellington.gdb\Stream"
import arcpy
map_object = arcpy.mp.ArcGISProject(project_path)
insertLyr = arcpy.mp.LayerFile(layerfilename)
m = map_object.listMaps('*')[0]
refLyr = m.listLayers("Catchment_Bnd")[0]
m.insertLayer(refLyr, insertLyr, "BEFORE")
map_object.save()
del map_object"