Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i wonder how i can add a raster layer to a remote (not the current) mxd file with arcpy. I need to not use a lyr file for that.

For vector Layer i have the following lines working fine :

mxdPath = "D:\FormationSpecialisee\IGN_IFI\doc1.mxd"
mxd = arcpy.mapping.MapDocument(mxdPath)
layer = arcpy.mapping.Layer(fcADD)
arcpy.mapping.AddLayer(df, layer , "AUTO_ARRANGE")

but it seems to not work for Raster Layer.

share|improve this question

You can create an in-memory RasterLayer by using arcpy.MakeRasterLayer to create the layer without an .lyr file and then add it to your DataFrame.

The following code will load a raster into a new raster layer, add it to the first dataframe of the specified mxd, and then save the mxd.

mxdPath = r'{path to mxd}'
rasterPath = r'{path to raster file}'
rasterLayerName = 'name to give new raster layer'

md = arcpy.mapping.MapDocument(mxdPath)
df = arcpy.mapping.ListDataFrames(md)[0]
result = arcpy.MakeRasterLayer_management(rasterPath, rasterLayerName)
layer = result.getOutput(0)
arcpy.mapping.AddLayer(df, layer, 'AUTO_ARRANGE')
share|improve this answer

mxdPath = r"D:\FormationSpecialisee\IGN_IFI\doc1.mxd"


mxdPath = "D:/FormationSpecialisee/IGN_IFI/doc1.mxd"


mxdPath = "D:\\FormationSpecialisee\\IGN_IFI\\doc1.mxd"

For use in Python

share|improve this answer

In a python window, just write:

arcpy.MakeRasterLayer_management(rasterFileName, "tmpLyr")

where rasterFileName is a string containing the path and name of your raster.

share|improve this answer

You'll need to have a .lyr file pointing to a raster with your predefined symbology, then open it with arcpy.mapping.Layer(yourlayerfile), add it to your map like you have, then use one of the layer datasource update methods to swap out the old data source with the new one.

share|improve this answer

Are you certain that your path is correct?

D:\FormationSpecialisee\IGN_IFI\doc1.mxd should be

D:\\FormationSpecialisee\\IGN_IFI\\doc1.mxd or


or its raw variant, in Python

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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