ArcGIS Desktop

  • ArcGIS Pro
  • ArcMap

  • My Profile
  • 帮助
  • Sign Out
ArcGIS Desktop

ArcGIS Online

专为贵组织打造的制图平台

ArcGIS Desktop

全面的专业性 GIS

ArcGIS Enterprise

面向企业的 GIS

ArcGIS Developers

用于构建位置感知应用程序的工具

ArcGIS Solutions

适用于行业的免费模板地图和应用程序

ArcGIS Marketplace

获取适用于组织的应用程序和数据

  • 文档
  • 支持
Esri
  • 登录
user
  • 我的个人资料
  • 登出

ArcMap

  • 主页
  • 入门
  • 地图
  • 分析
  • 管理数据
  • 工具
  • 扩展模块

VBScript and visual specifications

获得 Production Mapping 许可后可用。

  • Labeling features with domain descriptions in VBScript expressions
  • Expressions and calculated representations
  • Expressions and calculated fields

The rules in a visual specification determine the way a calculated representation or calculated field is going to appear in your map based on the attributes you are using. Rules are defined using either or both of the following:

  • Structured Query Language (SQL) statements
  • Scripts constructed using Visual Basic Scripting Edition (VBScript)

You can define the calculated representation using only an SQL query, or you can also use a script to further refine the way features are symbolized. The script provides you with a way to assign symbols to SQL query results based on additional conditions (programmatic expressions). For example, you can assign features with one subtype of one symbol and features with another subtype of a different symbol.

VBScript expressions must be defined when you are creating rules for calculated fields. However, they are not required for calculated representations.

The fields available for use with the expressions are based on the fields included in the SELECT part of your SQL statement. If you only have one or two fields from your feature classes available for selection, only those appear in the Expression Parser dialog box for the visual specification.

The conditions for symbolization and text strings are determined using if and else statements. The if part of the statement contains the feature attribute and the array of values you want to use in the condition. The else part of the statement represents a different condition that you want to apply to the symbolization and labels.

The following example uses if and else statements:

if IsNull( [SRC_SUB_arr](0) ) then
  strSUB = ""
else
  strSUB = [SRC_SUB_arr](0)
end if
Generate = strSUB
End Function

The Expression Parser analyzes your SELECT statement and constructs the outline of a function, Generate, in which you can conduct additional processing of the query results. The Generate function contains two parameters for each field specified in the SELECT clause of the query:

  • A scalar version (for example, [SRC_SUB])
  • An array version (for example, [SRC_SUB_arr])

If your query returns one result row per feature, you can ignore the array parameters in your VBScript code and just manipulate the scalar parameters to construct your calculated field.

In certain advanced cases, a query can return multiple result rows per feature. In those cases, your VBScript code can loop through the result rows using the array parameters to construct a multiline text string. To format a text string with multiple lines, you can include vbNewLine, vbCRLF, or Chr(13) + Chr(10).

The following example uses array parameters and looping:

if IsNull( [SRC_SUB_arr](0) ) then
  strSUB = ""
else
  strSUB = [SRC_SUB_arr](0)
end if

if IsNull( [NAME as B_NAME_arr](0) ) then
  strNAME = ""
else
  strNAME = [NAME as B_NAME_arr](0)
end if

if IsNull( [COLOUR as B_COLOUR_arr](0) ) then
  strCOLOUR = ""
else
  strCOLOUR = [COLOUR as B_COLOUR_arr](0)
end if

if IsNull( [COLPAT_arr](0) ) then
  strCOLPAT = ""
else
  strCOLPAT = [COLPAT_arr](0)
end if

str1 = "Primary: " + strSUB + "NAME: " + strNAME + " Color: " + strCOLOUR + " Pattern: " + strCOLPAT + Chr(13) + Chr(10)

For i = 0 To UBound([SRC_SUB_arr])
  if IsNull( [DEST_SUB_arr](i) ) then
    strSUB = ""
  else
    strSUB = [DEST_SUB_arr](i)
  end if

  if IsNull( [NAME as S_NAME_arr](i) ) then
    strNAME = ""
  else
    strNAME = [NAME as S_NAME_arr](i)
  end if

  if IsNull( [COLOUR as S_COLOUR_arr](i) ) then
    strCOLOUR = ""
  else
    strCOLOUR = [COLOUR as S_COLOUR_arr](i)
  end if

  str1 = str1 + "Secondary: " + strSUB + "  NAME: " + strNAME + "  Color: " + strCOLOUR

  if IsNull( [LITCHR_arr](i) ) then
    strLITCHR = ""
  else
    strLITCHR = [LITCHR_arr](i)
  end if

  if Len( strLITCHR ) > 0 then
    str1 = str1 + "  LITCHR: " + strLITCHR
  end if

  if IsNull( [TOPSHP_arr](i) ) then
    strTOPSHP = ""
  else
    strTOPSHP = [TOPSHP_arr](i)
  end if

  if Len( [strTOPSHP] ) > 0 then
    str1 = str1 + "  TOPSHP: " + strTOPSHP
  end if
  str1 = str1 + Chr(13) + Chr(10)
Next
Generate = str1
End Function

Labeling features with domain descriptions in VBScript expressions

You can also display domain description text in attribute fields for labeling features using the Expression Parser dialog box. A special syntax is used to call the domain description stored in a field: $[<field_name>]. For example, boundary classifications in a map are stored in the Boundary_class attribute field as coded value domains with textual descriptions. To label the boundary areas with the domain descriptions, you can use the following syntax:

if [Boundary_class] = 0 then
 Generate = $[Boundary_class]
else
 Generate = $[Boundary_class]
end if
End Function

The boundary areas are labeled as City and County.

Expressions and calculated representations

Expressions created using VBScript allow you to set conditions that determine the way symbols are represented based on a range of attributes or associated table values. For example, features with an FCsubtype value of 0 can be represented with one symbol, and features with any other subtype can be represented with another symbol:

if [FCsubtype] = 0 then
  reprule = "ESRI.Style::On Point"
else
  reprule = "ESRI.Style::Buffer Hatch"
end if

Generate = reprule
End Function

Expressions and calculated fields

With calculated fields, VBScript can be used to customize labels for features in the map. For example, you may want to use one font size for the labels on small cities and a different font size for the labels on larger cities.

相关主题

  • 构建标注表达式
  • What are visual specifications?
  • A quick tour of visual specifications
  • SQL statements and visual specifications
  • Changing the statement or the expression or VBScript expression

ArcGIS Desktop

  • 主页
  • 文档
  • 支持

ArcGIS

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS
  • ArcGIS Developer
  • ArcGIS Solutions
  • ArcGIS Marketplace

关于 Esri

  • 关于我们
  • 招贤纳士
  • Esri 博客
  • 用户大会
  • 开发者峰会
Esri
分享您的想法。
Copyright © 2021 Esri. | 隐私政策 | 法律声明