5
Copyright © 2010 ESRI China (Hong Kong) Limited Tips & Tricks prepared by ESRI China (HK) Technical Support All rights reserved. P. 1 of 5 Advanced Labeling Using VBScript and ArcGIS Text Formatting Tags Article ID : 100030 Software : ArcGIS – ArcView 9.3, ArcEditor 9.3, ArcInfo 9.3 (or higher versions) Platform : Windows XP, Windows Vista, Windows 7 Date : October 29, 2010 Introduction Labeling is the process of placing descriptive text onto or next to features on a map for identification. In ArcGIS, a label is specifically a piece of dynamic text string place at automatic position on the map. It is derived from one or more feature attributes. It is a fast and useful way if your data is expected to change frequently or map scales varies. Labels in a map document can be formatted by advanced labeling. By scripting label expressions with VBScripts and HTML-like ArcGIS text formatting tags (TFT), layers can be labeled with multiple fields and different styles. However, attentions should be paid to special characters like ampersand (&) to ensure proper formatting of labels. The following steps provide a workflow for using advanced labeling by scripting and TFT. 1 Procedures of adding labels with one or more fields 1.1 Open a map document (*.mxd) with layers in ArcMap. Right-click layer and choose Properties to open Layer Properties dialog box.

Advanced Labeling Using VBScript and ArcGIS Text ... · PDF fileAdvanced Labeling Using VBScript and ArcGIS Text Formatting Tags Article ID : 100030 Software : ArcGIS – ArcView 9.3,

Embed Size (px)

Citation preview

Page 1: Advanced Labeling Using VBScript and ArcGIS Text ... · PDF fileAdvanced Labeling Using VBScript and ArcGIS Text Formatting Tags Article ID : 100030 Software : ArcGIS – ArcView 9.3,

Copyright © 2010 ESRI China (Hong Kong) Limited Tips & Tricks prepared by ESRI China (HK) Technical Support All rights reserved. P. 1 of 5

Advanced Labeling Using VBScript and ArcGIS Text Formatting Tags

Article ID : 100030

Software : ArcGIS – ArcView 9.3, ArcEditor 9.3, ArcInfo 9.3 (or higher versions)

Platform : Windows XP, Windows Vista, Windows 7

Date : October 29, 2010

Introduction

Labeling is the process of placing descriptive text onto or next to features on a map for identification. In ArcGIS,

a label is specifically a piece of dynamic text string place at automatic position on the map. It is derived from one

or more feature attributes. It is a fast and useful way if your data is expected to change frequently or map scales

varies.

Labels in a map document can be formatted by advanced labeling. By scripting label expressions with VBScripts

and HTML-like ArcGIS text formatting tags (TFT), layers can be labeled with multiple fields and different styles.

However, attentions should be paid to special characters like ampersand (&) to ensure proper formatting of

labels. The following steps provide a workflow for using advanced labeling by scripting and TFT.

1 Procedures of adding labels with one or more fields

1.1 Open a map document (*.mxd) with layers in ArcMap. Right-click layer and choose Properties to

open Layer Properties dialog box.

Page 2: Advanced Labeling Using VBScript and ArcGIS Text ... · PDF fileAdvanced Labeling Using VBScript and ArcGIS Text Formatting Tags Article ID : 100030 Software : ArcGIS – ArcView 9.3,

Copyright © 2010 ESRI China (Hong Kong) Limited Tips & Tricks prepared by ESRI China (HK) Technical Support All rights reserved. P. 2 of 5

1.2 In Layer Properties dialog box, navigate to Labels tab. Check the option Label features in this layer if

necessary.

1.3 Click Expression button to open Label Expression dialog box. A field quoted by square bracket ([ ] )

is already included in Expression text area.

Page 3: Advanced Labeling Using VBScript and ArcGIS Text ... · PDF fileAdvanced Labeling Using VBScript and ArcGIS Text Formatting Tags Article ID : 100030 Software : ArcGIS – ArcView 9.3,

Copyright © 2010 ESRI China (Hong Kong) Limited Tips & Tricks prepared by ESRI China (HK) Technical Support All rights reserved. P. 3 of 5

1.4 To label with multiple fields, select a field in Label Fields and click Append button. The field selected

and a separating space are appended automatically in Expression text area.

[CNAME] & " " & [ENAME]

1.5 To validate the label expression in Expression text area, click Verify button. If the expression is valid,

a preview of sample data is shown in a pop-up dialog box. Click OK button to return.

Page 4: Advanced Labeling Using VBScript and ArcGIS Text ... · PDF fileAdvanced Labeling Using VBScript and ArcGIS Text Formatting Tags Article ID : 100030 Software : ArcGIS – ArcView 9.3,

Copyright © 2010 ESRI China (Hong Kong) Limited Tips & Tricks prepared by ESRI China (HK) Technical Support All rights reserved. P. 4 of 5

1.6 To accept the changes made, click OK button and Apply button in Label Expression and Layer

Properties dialog boxes respectively. Features are labeled with the two fields defined in the map.

2 Procedures of formatting labels using VBScript and TFT

2.1 To display fields in separate lines, return to Label Expression dialog box (steps 1.1 to 1.4). In

Expression text area, replace the string “ “ with a VBScript carriage return character vbNewLine .

Accept the changes made (step 1.6).

[CNAME] & vbNewLine & [ENAME]

Page 5: Advanced Labeling Using VBScript and ArcGIS Text ... · PDF fileAdvanced Labeling Using VBScript and ArcGIS Text Formatting Tags Article ID : 100030 Software : ArcGIS – ArcView 9.3,

Copyright © 2010 ESRI China (Hong Kong) Limited Tips & Tricks prepared by ESRI China (HK) Technical Support All rights reserved. P. 5 of 5

2.2 To format labels in specific styles, add ArcGIS text formatting tags in Expression text area.

"<CLR red='255' green='0' blue='0'><FNT name=' 標楷體' size='12'>"

& [CNAME] & "</FNT></CLR>"

& vbNewLine &

"<CLR red='0' green='0' blue='255'><FNT name='Verda na' size='8'>"

& [ENAME] & "</FNT></CLR>"

2.3 Labels with field values containing ampersand (&) character may interrupt VBScript parsing. As a

result, labels may be displayed improperly with label expression shown instead of fields. To eliminate

such scenario, add REPLACE() function to encode ampersand (&) character with “&amp; ”.

"<CLR red='255' green='0' blue='0'><FNT name=' 標楷體' size='12'>"

& REPLACE([CNAME], "&", "&amp;") & "</FNT></CLR>"

& vbNewLine &

"<CLR red='0' green='0' blue='255'><FNT name='Verda na' size='8'>"

& REPLACE([ENAME], "&", "&amp;") & "</FNT></CLR>"

Note: For details of ArcGIS text formatting tags, pls refer to

http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=280&pid=267&topicname=Using_text_formatting_

tags

The End