0

I can easily add shapefiles to the Table of Contents in ArcMap using the following code:

mxd = arcpy.mapping.MapDocument("current") 
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
path = os.path.abspath("shapefile_path")
addLayer = arcpy.mapping.Layer(path)
arcpy.mapping.AddLayer(df, addLayer)
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
del mxd, addLayer 

but I am confused how to add raster data (which usually consists of several files).

1 Answer 1

1

It is by a very similar means.

  1. Use ArcMap to add your raster dataset to a map as a layer
  2. Set whatever Layer Properties you want
  3. Save the layer just authored as a layer file (*.lyr)
  4. Use arcpy.mapping.AddLayer to reference such "layers in a layer (.lyr) file".

If you want to automate the layer authoring process (steps 1-3) then try Make Feature Layer followed by Save To Layer File.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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