ArcGIS For Desktop
From Wildsong
Jump to navigationJump to search
Immediate mode recipes
def show_layers(df): layers = arcpy.mapping.ListLayers(map, "*", df) for l in layers: try: print l.workspacePath except: pass pass mxd=arcpy.mapping.MapDocument("CURRENT") #replace_workspace(map, r"C:\Users\wilson\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\Connection to cvogisprod.sde") #replace_workspace(map, r"P:\Data\cvogisprod_default.sde") o = r"P:\Data\State\ORE_counties_Intersect" n = r"\\pwsrv02\PWImages\MapServiceData" mxd.findAndReplaceWorkspacePaths(o,n) o = r"R:\GisdataNad_83\Other\County\Benton" mxd.findAndReplaceWorkspacePaths(o,n) o = r"P:\Data\NHD\NHD_BentonCounty.gdb" n = r"\\pwsrv02\PWImages\MapServiceData\NHD_BentonCounty.gdb" mxd.findAndReplaceWorkspacePaths(o,n) df=arcpy.mapping.ListDataFrames(mxd, "Base Map")[0] show_layers(df) def add_zoom_layer(df, scale): mapping.AddLayer(df, addLayer, "Bottom") def copy_layers(): template_mxd_file = "" new_mxd_file = "" # Copy the layer groups from my template document template_mxd = mapping.MapDocument(template_mxd) df = mapping.ListDataFrames(template_mxd, "Web Mercator")[0] # Add the annotation to each group new_mxd = mapping.MapDocument(new_mxd_file) df = mapping.ListDataFrames(new_mxd)[0] # Need to save the changed MXD out #mxd.saveACopy(new_mxd_file + '_1') del template_mxd, new_mxd # ----- def change_all_layers(): # Make all layers in map visible or NOT mxd = mapping.MapDocument("CURRENT") df = mapping.ListDataFrames(mxd)[0] layers = mapping.ListLayers(mxd, '*', df) for l in layers: l.visible = True # ...or False arcpy.RefreshTOC() # ================================================================================================= def layertype(l): t = '' if l.isRasterLayer: t = "Raster Layer" elif l.isGroupLayer: t = "Group Layer" elif l.isFeatureLayer: t = "Feature Layer" return t def symbology_report(l): try: t = l.symbologyType except: return False if t == 'UNIQUE_VALUES': print "Unique Values: desc:",l.symbology.classDescriptions print " labels:",l.symbology.classLabels print " values:",l.symbology.classValues print " field:",l.symbology.valueField print l.symbology pass elif t == 'OTHER': return False #elif l.symbologyType == 'GRADUATEDCOLORS': # pass #elif l.symbologyType == 'GRADUATEDSYMBOLS': # pass #elif l.symbologyType == 'RASTERCLASSIFIED': # pass return True def layer_report(l): #if not symbology_report(l): return print "-----" #if not(l.minScale or l.maxScale): return print "Name: %s Type: %s" % (l.name, layertype(l)) print "LongName: %s" % l.longName try: if l.visible: print "Visible" except: pass try: if l.showLabels: print "Show labels" except: pass symbology_report(l) try: if l.transparency != 0: print "Transparency: %d" % l.transparency except: pass if l.minScale != 0 or l.maxScale != 0: print "Scale range: %f %f" % (l.minScale, l.maxScale) try: print "Dataset: %s" % l.datasetName except: pass try: print "Data source: \"%s\"" % l.dataSource except: pass try: print "Workspace: \"%s\"" % l.workspacePath except: pass try: if l.definitionQuery: print "Def query: \"%s\"" % l.definitionQuery except: pass #l.brightness #l.contrast #l.credits def dataframe_report(mxd, df): layers = mapping.ListLayers(mxd, '*', df) for l in layers: layer_report(l) def mxd_report(mxdfile): # Tell me everything you know about this map's layers mxd = mapping.MapDocument(mxdfile) dataframes = mapping.ListDataFrames(mxd) for df in dataframes: print "== dataframe: %s" % df.name dataframe_report(mxd, df) mxd_report("P:/Annotation/WebMercator_annotation.mxd")