import comtypes.client esriCarto = comtypes.client.GetModule(r'C:\Program Files\ArcGIS\com\esriCarto.olb') def openMxd(strMxd): """ Opens an MXD and returns an IMapDocument object. """ try: objMapDocument = comtypes.client.CreateObject(esriCarto.MapDocument, interface=esriCarto.IMapDocument) if objMapDocument.IsMapDocument(strMxd): objMapDocument.Open(strMxd, "") else: return 0 return objMapDocument except: return 0 strMxd = r"C:\workspace\test.mxd" # Open the MXD objMapDocument = openMxd(strMxd) if objMapDocument: try: # Get the first map in the MXD objMap = objMapDocument.Map(0) # Get the first layer in the map (i.e. data frame) - MUST BE A RASTER objSourceLayer = objMap.Layer(0) # Get the layer's renderer objRasterLayer = objSourceLayer.QueryInterface(esriCarto.IRasterLayer) objSourceRasterRenderer = objRasterLayer.Renderer # Loop through the rest of the layer in the map for i in range(1, objMap.LayerCount): objDestinationLayer = objMap.Layer(i) print objDestinationLayer.Name # Replace the current layer's renderer with the first layer's renderer try: objRasterLayer = objDestinationLayer.QueryInterface(esriCarto.IRasterLayer) objRasterLayer.Renderer = objSourceRasterRenderer except: print "Not a raster" continue # Save the MXD and close it. objMapDocument.Save() objMapDocument.Close() except: print "Error" objMapDocument.Close()
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.