import arcpy from arcpy import analysis, env workspace = arcpy.env.workspace = r"C:/temp" arcpy.env.overwriteOutput = True mxDoc = arcpy.mapping.MapDocument(r"X:/GisResources/Mxd Map Templates/HighUnemploymentCensusTracts_Template.mxd") df = arcpy.mapping.ListDataFrames(mxDoc, "Detail Map") [0] co_layer = arcpy.mapping.ListLayers(mxDoc,"",df) [0] co_name = "NAME" rows = arcpy.SearchCursor(co_layer) for row in rows: co = row.getValue(co_name) whereClause = "NAME <> '%s'" % co analysis.Select(co_layer, "Co_%s" % co, whereClause) arcpy.ApplySymbologyFromLayer_management("Co_%s" % co, "Export_Output_21") inputLayer = arcpy.mapping.Layer("Co_%s" % co) arcpy.mapping.RemoveLayer(df, inputLayer) arcpy.RefreshActiveView()
Solved! Go to Solution.
Thank you both. Unfortunately, I won't be back in the office until Monday, so I will not be able to try out your suggestions until then. In the meantime, I can explain the purposes of this script. Text in bold indicates instructions that exist within the current script, as seen on the OP.
Iterate through features within IlCounties layer, and do the following for each feature:
the da.walk will do this for you.for dirpath, dirnames, filenames in arcpy.da.Walk(datatype="FeatureClass",type="All"): ## would restrict this "All" to the feature/table type you are after for filename in filenames: Rest of the code would go here since you want it for each feature in the FC....
Zoom to feature
cntyLayer = r'path\to\IlCounties" feature class ### would hard code this one since it is fixed, and we iterate through the others. df = arcpy.mapping.ListDataFrames(mxd, "Detail Map")[0] df2 = arcpy.mapping.ListDataFrames(mxd, "Locator Map")[0] # Just as well set both df's while here lyr = arcpy.mapping.ListLayers(mxd, "IlCounties", df)[0] df.extent = lyr.getSelectedExtent(True)
Select all features not equal to feature within IlCounties
Use SelectLayerByLocation with ARE_IDENTICAL_TO for overlap type and NEW_SELECTION for selection type.
Use SelectLayerByLocation with SWITCH_SELECTION as selection type ### These two will select features that are not equal to the other features
Export selection as new layer, add to Detail Map dataframe
Use CopyFeatures to export to new FGDB FC # this will only copy/export the selected features
then AddLayer to add the new FC to the df.
AddLayer(df,new_FC)
Update new layer to incorporate symbology of Export_Output_21
use UpdateLayer for this
Add new layer to a second existing dataframe (named Locator Map)
add layer again AddLayer(df2,new_FC) ## of course, you will have to update symobology again if needed.
Replace MXD title element to IlCounties feature name
legend = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "title")[0]
legend.text = filename
Export as PDF
ExportToPDF (mxd, out_pdf,resolution=266)
I'm mostly just seeking help for the instructions in bold at the moment. I'll answer your questions and suggestions directly come Monday. Thank you!
cntyLayer = r'path\to\IlCounties' arcpy.MakeFeatureLayer_management(cntyLayer, "IlCounties_lyr") for dirpath, dirnames, filenames in arcpy.da.Walk(datatype="FeatureClass",type="All"): for filename in filenames: df = arcpy.mapping.ListDataFrames(mxd, "Detail Map")[0] df2 = arcpy.mapping.ListDataFrames(mxd, "Locator Map")[0] # Just as well set both df's while here lyr = arcpy.mapping.ListLayers(mxd, "IlCounties", df)[0] df.extent = lyr.getSelectedExtent(True) arcpy.MakeFeatureLayer_management(filename, str(filename) + "_lyr") SelectLayerByLocation(str(filename) + "_lyr", "ARE_IDENTICAL_TO", "IlCounties_lyr", #, NEW_SELECTION) SelectLayerByLocation(str(filename) + "_lyr", "ARE_IDENTICAL_TO", "IlCounties_lyr", #, SWITCH_SELECTION) CopyFeatures AddLayer(df,new_FC) UpdateLayer AddLayer(df2,new_FC) UpdateLayer legend = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "title")[0] legend.text = filename ExportToPDF (mxd, out_pdf,resolution=266)
Where is it finding the value of Export_Output_21 since this is the layer you are trying to apply the symbology from?
ApplySymbologyFromLayer_management (in_layer, in_symbology_layer)
I have not used ApplySymbologyFromLayer before, but arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, True) is working for me to update my symbology from a .lyr file.
R_
arcpy.mapping.RemoveLayer(df, inputLayer) arcpy.RefreshActiveView()
mxDoc = arcpy.mapping.MapDocument("CURRENT")
rows = arcpy.SearchCursor(co_layer) nameList = [] for row in rows: co = row.getValue(co_name) nameList.append(co) del rows for name in nameList: whereClause = ' "NAME" = \'%s\' ' % (name) # ... and so on
export_layer = arcpy.mapping.ListLayers(mxDoc,"Export_Output_21",df) [0] arcpy.ApplySymbologyFromLayer_management("Co_%s" % co, export_layer)
Thank you both. Unfortunately, I won't be back in the office until Monday, so I will not be able to try out your suggestions until then. In the meantime, I can explain the purposes of this script. Text in bold indicates instructions that exist within the current script, as seen on the OP.
Iterate through features within IlCounties layer, and do the following for each feature:
the da.walk will do this for you.for dirpath, dirnames, filenames in arcpy.da.Walk(datatype="FeatureClass",type="All"): ## would restrict this "All" to the feature/table type you are after for filename in filenames: Rest of the code would go here since you want it for each feature in the FC....
Zoom to feature
cntyLayer = r'path\to\IlCounties" feature class ### would hard code this one since it is fixed, and we iterate through the others. df = arcpy.mapping.ListDataFrames(mxd, "Detail Map")[0] df2 = arcpy.mapping.ListDataFrames(mxd, "Locator Map")[0] # Just as well set both df's while here lyr = arcpy.mapping.ListLayers(mxd, "IlCounties", df)[0] df.extent = lyr.getSelectedExtent(True)
Select all features not equal to feature within IlCounties
Use SelectLayerByLocation with ARE_IDENTICAL_TO for overlap type and NEW_SELECTION for selection type.
Use SelectLayerByLocation with SWITCH_SELECTION as selection type ### These two will select features that are not equal to the other features
Export selection as new layer, add to Detail Map dataframe
Use CopyFeatures to export to new FGDB FC # this will only copy/export the selected features
then AddLayer to add the new FC to the df.
AddLayer(df,new_FC)
Update new layer to incorporate symbology of Export_Output_21
use UpdateLayer for this
Add new layer to a second existing dataframe (named Locator Map)
add layer again AddLayer(df2,new_FC) ## of course, you will have to update symobology again if needed.
Replace MXD title element to IlCounties feature name
legend = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "title")[0]
legend.text = filename
Export as PDF
ExportToPDF (mxd, out_pdf,resolution=266)
I'm mostly just seeking help for the instructions in bold at the moment. I'll answer your questions and suggestions directly come Monday. Thank you!
cntyLayer = r'path\to\IlCounties' arcpy.MakeFeatureLayer_management(cntyLayer, "IlCounties_lyr") for dirpath, dirnames, filenames in arcpy.da.Walk(datatype="FeatureClass",type="All"): for filename in filenames: df = arcpy.mapping.ListDataFrames(mxd, "Detail Map")[0] df2 = arcpy.mapping.ListDataFrames(mxd, "Locator Map")[0] # Just as well set both df's while here lyr = arcpy.mapping.ListLayers(mxd, "IlCounties", df)[0] df.extent = lyr.getSelectedExtent(True) arcpy.MakeFeatureLayer_management(filename, str(filename) + "_lyr") SelectLayerByLocation(str(filename) + "_lyr", "ARE_IDENTICAL_TO", "IlCounties_lyr", #, NEW_SELECTION) SelectLayerByLocation(str(filename) + "_lyr", "ARE_IDENTICAL_TO", "IlCounties_lyr", #, SWITCH_SELECTION) CopyFeatures AddLayer(df,new_FC) UpdateLayer AddLayer(df2,new_FC) UpdateLayer legend = arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT", "title")[0] legend.text = filename ExportToPDF (mxd, out_pdf,resolution=266)
Thank you both. Unfortunately, I won't be back in the office until Monday, so I will not be able to try out your suggestions until then. In the meantime, I can explain the purposes of this script. Text in bold indicates instructions that exist within the current script, as seen on the OP.
Iterate through features within IlCounties layer, and do the following for each feature:
Zoom to feature
Select all features not equal to feature within IlCounties
Export selection as new layer, add to Detail Map dataframe
Update new layer to incorporate symbology of Export_Output_21
Add new layer to a second existing dataframe (named Locator Map)
Replace MXD title element to IlCounties feature name
Export as PDF
I'm mostly just seeking help for the instructions in bold at the moment. I'll answer your questions and suggestions directly come Monday. Thank you!
import arcpy mxDoc = arcpy.mapping.MapDocument(r"X:/GisResources/Mxd Map Templates/HighUnemploymentCensusTracts_Template.mxd") out_pdf = r"X:/GisResources/NewPDF.pdf") ExportToPDF (mxDoc, out_pdf,resolution=266)
import arcpy from arcpy import analysis, env workspace = arcpy.env.workspace = r"C:/temp" env.overwriteOutput = True mxDoc = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxDoc, "Detail Map") [0] df2 = arcpy.mapping.ListDataFrames(mxDoc, "Locator Map") [0] co_layer = arcpy.mapping.ListLayers(mxDoc,"",df) [-1] co_name = "NAME" rows = arcpy.SearchCursor(co_layer) for row in rows: co = row.getValue(co_name) whereClause = "NAME <> '%s'" % co analysis.Select(co_layer, "Co_%s" % co, whereClause) arcpy.ApplySymbologyFromLayer_management("Co_%s" % co, "Export_Output_21") lyr = arcpy.mapping.ListLayers(mxDoc, "", df)[0] arcpy.mapping.AddLayer(df2, lyr) whereClause2 = "NAME = '%s'" % co analysis.Select(co_layer, "Co_%s1" % co, whereClause2) lyr = arcpy.mapping.ListLayers(mxDoc, "", df)[0] lyr1 = arcpy.mapping.ListLayers(mxDoc, "", df)[1] lyr2 = arcpy.mapping.ListLayers(mxDoc, "", df2)[0] df.extent = lyr.getSelectedExtent(True) arcpy.mapping.RemoveLayer(df, lyr) title = arcpy.mapping.ListLayoutElements(mxDoc, "TEXT_ELEMENT", "*")[0] title.text = "%s County" % co arcpy.mapping.ExportToPDF(mxDoc, r"C:/temp/ProjectDataFrame%s.pdf" % co) arcpy.mapping.RemoveLayer(df, lyr1) arcpy.mapping.RemoveLayer(df2, lyr2) arcpy.RefreshActiveView()