AnsweredAssumed Answered

Add a raster to a project file in Pro

Question asked by mcdo0007 on May 5, 2019
Latest reply on May 6, 2019 by mcdo0007

I'm converting Python standalone scripts from Desktop (10.6.1)  to Pro (2.3.2).  I can add a raster to an open Pro project file interactively by right clicking on the raster in the Catalog and choosing "Add to Current Map".  I would like to do this in a script and have tried two ways (one commented out below):

 

inRas = '<projectDir>/Risks/riskv0'
outAPRX = '<projectDir>/Reports/riskv0/riskv0.aprx'
templateFile = '<projectDir>/MapTemplates/risksTemplate/risksTemplate.aprx'
aprx = arcpy.mp.ArcGISProject(templateFile)
map = aprx.listMaps()[0]
map.addDataFromPath(inRas)
#refLyr = map.listLayers()[1]
#map.insertLayer(refLyr, inRas, "AFTER")
aprx.saveACopy(outAPRX)
del aprx

When I use addDataFromPath, I receive a RuntimeError for line 6 with no further information.

The listLayers/insertLayer approach results in a ValueErr at line 8 for the inRas file.

I would be grateful for any advice on adding a raster to a map in Pro.

Outcomes