def moveLyr(mapdoc, dataframe, lyr_to_move, reference_lyr_name, keyword='AFTER'): ''' Move layer within a dataframe in relation to the reference layer. The keywork determines whether the layer is moved above or below the reference layer ''' move_lyr = mp.ListLayers(mapdoc, lyr_to_move.name, dataframe)[0] ref_lyr = mp.ListLayers(mapdoc, reference_lyr_name, dataframe)[0] mp.MoveLayer(df, ref_lyr, move_lyr, keyword)
#------------------------------------------------------------------------------- import arcpy import arcpy.mapping as map #cambio el nombre del modulo #Definicion de variables ruta_mxd = 'c:\proyecto\proyecto.mxd' mxd = map.MapDocument(ruta_mxd) #acceso al proyecto df = map.ListDataFrames(mxd)[0] #acceso al primer mapa de la lista (dataframe) #Acceso a la primera y ultima capa de la lista lista_capas = map.ListLayers (mxd,"",df) #acceso a la lista de capas n = len(lista_capas) #numero de capas primera = lista_capas[0] #primera capa (la de arriba) ultima = lista_capas[n-1] #ultima capa (la de abajo) #Desplazamiento de la capa map.MoveLayer(df,primera,ultima,'BEFORE') #Refresco de la vista y de la TOC (solo si mxd = 'CURRENT' arcpy.RefreshActiveView() arcpy.RefreshTOC() #Exportar mapa a pdf map.ExportToPDF(mxd, "C:/Projecto/Output/mapa.pdf") #liberacion de memoria del mxd, df, primera, ultima #------------------------------------------------------------------------------- # DESCRIBE LAYERS #------------------------------------------------------------------------------- import arcpy
## Step 1 import arcpy.mapping as MAP mxd = MAP.MapDocument(r"C:\Student\PYTH\Map_production\CorvallisMeters.mxd") df = MAP.ListDataFrames(mxd)[0] ## Step 2 updateLayer = MAP.ListLayers(df, "ParkingMeters")[0] sourceLayer = MAP.Layer(r"C:\Student\PYTH\Map_production\ParkingMeters.lyr") MAP.UpdateLayer(df, updateLayer, sourceLayer, True) addLayer = MAP.Layer(r"C:\Student\PYTH\Map_production\Schools.lyr") MAP.AddLayer(df, addLayer) refLayer = MAP.ListLayers(df, "Schools")[0] ## This is the tricky step. The order of the arguments appears to be backwards. MAP.MoveLayer(df, refLayer, updateLayer, "BEFORE") ## Step 3 mxd.title = "Corvallis Meters Map" elemList = MAP.ListLayoutElements(mxd, "TEXT_ELEMENT") for elem in elemList: if elem.name == "Corvallis Meters": elem.text = "Corvallis Parking Meters Inventory Report" #mxd.saveACopy(r"C:\Student\PYTH\Map_production\CorvallisMeters_ks.mxd") del mxd
if lyr.name == 'Transportation_Polygons': lyr.definitionQuery = "TRANSPORTATIONTYPE = 'RRWYLIN'" #arcpy.ApplySymbologyFromLayer_management(lyr, lyr_style_guide[lyr.name]) # This needs to stay below apply symbology layer because we're changing the lyr name mp.AddLayer(df, lyr, 'AUTO_ARRANGE') u_lyr = mp.ListLayers(mxd, lyr.name, df)[0] if u_lyr.name == 'Structure_Points': # moves structure points below the address range annotation to solve obscuring issue if len(mp.ListLayers( mxd, 'road_l_address_anno', df)) > 0: # check if road anno is actually in the map ref_lyr = mp.ListLayers(mxd, 'road_l_address_anno', df)[0] mp.MoveLayer(df, ref_lyr, u_lyr, 'AFTER') # Rename the unsurveyed parcels more concisely if u_lyr.name == 'Unsurveyed_Tenured_Commissioners_Land': u_lyr.name = 'Unsurveyed_Parcels' aug_counts[ 'Unsurveyed_Parcels'] += 1 # Adds the lyr to the metrics counts continue # this must always be the last thing done because of the name change in this part of the loop aug_counts[lyr.name] += 1 # Adds the lyr to the metrics counts # Check if there is yk_adp in the new layers. If there is adp will be labeled turn off the labels for sp if 'yk_Address_Points' in fc_list and 'Surveyed_Parcels' in fc_list: sp_lyr = mp.ListLayers(mxd, 'Surveyed_Parcels', df)[0] sp_lyr.showLabels = False # Change the symbology of select base map layers to match adjusted settings