皆様へ!<\/P>
<\/P>
ModelBuilderでレイヤーに凡例を追加しようとしています。ヘルプページには「Apply Symbology From Layer」ツールを使用する必要があると書かれています。シンボロジーレイヤーは保存しましたが、凡例は含まれていません(私の理解では、凡例はマップファイルにのみ保存できるようです)。正しく行う方法を教えていただけますか?<\/P><\/BODY><\/HTML>
Actually, I think the question is about adding legend by using model builder to automate the process instead of doing it manually.. not sure how to add legend in model builder but you can create legend items after adding symbology in arcpy.. If you have any idea about how to add legend with model or script, I can also utilize from that..
Hi,
if this is just for symbology... right click in the model element (final output) -> properties -> layer symbology tab
Ok I created tool and here how you do it.
This is the tool view below
Here the script for it
import arcpy,os
symbologyLayer=arcpy.GetParameterAsText(2)
LabelExpression=arcpy.GetParameterAsText(1)
try:
for idx, item in enumerate(LabelExpression.split()):
if 'VISIBLE'==item:
num=idx
arcpy.AddWarning(LabelExpression.split()[idx-1])
LabelExpression="["+LabelExpression.split()[num-1]+"]"
except:
arcpy.AddError("Choose only one field name for label expession")
K_shp=arcpy.GetParameterAsText(0)
add_legend= arcpy.GetParameterAsText(3)
LayerName=os.path.split(K_shp)[1][:-4]+"_lyr"
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
arcpy.MakeFeatureLayer_management(K_shp,LayerName)
lyr1= arcpy.mapping.Layer(LayerName)
arcpy.ApplySymbologyFromLayer_management (lyr1, symbologyLayer)
lyr1.labelClasses[0].expression = LabelExpression
lyr1.showLabels = True
arcpy.RefreshActiveView()
arcpy.mapping.AddLayer(df, lyr1, "BOTTOM")
if add_legend=='true':
#styleItem = arcpy.mapping.ListStyleItems("USER_STYLE", "Legend Items", "NewDefaultLegendStyle")[0]
legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT", "Legend")[0]
#legend.updateItem(lyr1, styleItem)
legend.autoAdd = True
del mxd
Above is the tool parameters you need to arrange..
Only thing that I could not figure out how to add legend itself with arcpy, so you need to manully create and empty legend before you run the script.
If I understood correctly, you want to add legend with model builder.Apply Symbology From Layer extracts Symbology from a layer ( which is a layer you prepared before) to another layer which does not have symbology.
As far as I know , there is no tool to include legend in model builder but you could create a script "to add legend" in python and make a tool with that script. Then you can add it to your model. Here same code you can use to create layer from shp and add sybology.
import arcpy
symbologyLayer=r"C:\.....\sembology.lyr" # if you want to assign same layer format all the time this can be a path to your symbology
LabelExpression="[Fieldyouwantolabelwith]" #if you want label you can make it parameter if not you do not have to use this label parts
K_shp= arcpy.GetParameterAsText(0) ### your shp file you want to assign symbology
## those above will be your parameters
mxd = arcpy.mapping.MapDocument(r"C:\......\my.mxd")
#or mxd = arcpy.mapping.MapDocument("CURRENT")
arcpy.MakeFeatureLayer_management(K_shp,"Layername")
lyr1= arcpy.mapping.Layer("Layername")
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.