{"id":651,"date":"2012-07-09T14:11:12","date_gmt":"2012-07-09T14:11:12","guid":{"rendered":"http:\/\/www.geoplanit.co.uk\/?p=651"},"modified":"2012-07-09T14:11:48","modified_gmt":"2012-07-09T14:11:48","slug":"a-quick-python-label-expressions-in-arcgis","status":"publish","type":"post","link":"https:\/\/www.geoplanit.co.uk\/?p=651","title":{"rendered":"A quick Python Label Expression in ArcGIS"},"content":{"rendered":"<p>Well I&#8217;ve been wanting to label certain features based on certain attributes (I \u00a0know exciting stuff), ArcGIS allows you to do this and until release 10 you were scripting this in VBScript. \u00a0 Of course everyone is going Python now so I&#8217;m starting to use it&#8230; \u00a0The following is really a note for me to come back to, but it may help or interest others&#8230;.<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/i0.wp.com\/www.geoplanit.co.uk\/wp-content\/uploads\/2012\/07\/arcgis_label_expression.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-652\" title=\"arcgis_label_expression\" src=\"https:\/\/i0.wp.com\/www.geoplanit.co.uk\/wp-content\/uploads\/2012\/07\/arcgis_label_expression.jpg?resize=696%2C393\" alt=\"\" width=\"696\" height=\"393\" srcset=\"https:\/\/i0.wp.com\/www.geoplanit.co.uk\/wp-content\/uploads\/2012\/07\/arcgis_label_expression.jpg?resize=1024%2C578&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.geoplanit.co.uk\/wp-content\/uploads\/2012\/07\/arcgis_label_expression.jpg?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.geoplanit.co.uk\/wp-content\/uploads\/2012\/07\/arcgis_label_expression.jpg?w=1194&amp;ssl=1 1194w\" sizes=\"auto, (max-width: 696px) 100vw, 696px\" \/><\/a><\/p>\n<p>Right-click your layer you want to label, in the Layer Properties dialog box select the Labels Tab check Label features in this layer and click on the &#8221; Expression Button&#8221;. \u00a0 In the Label Expression dialog box select Python as the Parser and check the Advanced box.<\/p>\n<p>Use this code:<\/p>\n<p>&nbsp;<\/p>\n<pre>def FindLabel ( [DistrictName], [QuarterCentre] ):\r\n\tif [QuarterCentre]:\r\n\t\treturn  \"&lt;BOL&gt;&lt;UND&gt;\"\u00a0 + [DistrictName] + \"&lt;\/UND&gt;&lt;\/BOL&gt;\"\r\n\telse:\r\n\t\treturn [DistrictName]<\/pre>\n<p>Ensure you&#8217;ve tabbed everything as well, make sure you declare all the fields you want to use at the top. This basically checks the QauarterCentre field and if it has a value <strong>Bolds<\/strong> and <span style=\"text-decoration: underline;\">Underlines<\/span> the label. \u00a0Otherwise it just labels the feature. \u00a0 To do the opposite you can use &#8220;if not [QuarterCentre]&#8221;.<\/p>\n<p><a href=\"http:\/\/resources.arcgis.com\/en\/help\/main\/10.1\/index.html#\/Using_text_formatting_tags\/00s80000000p000000\/\" target=\"_blank\">For more information goto the ArcGIS 10.1 help here.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well I&#8217;ve been wanting to label certain features based on certain attributes (I \u00a0know exciting stuff), ArcGIS allows you to do this and until release 10 you were scripting this in VBScript. \u00a0 Of course everyone is going Python now so I&#8217;m starting to use it&#8230; \u00a0The following is really a note for me to [&hellip;]<\/p>\n","protected":false},"author":161,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,13,91,220],"tags":[],"class_list":{"0":"post-651","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-arcgis","7":"category-arcmap","8":"category-programming","9":"category-python"},"_links":{"self":[{"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/users\/161"}],"replies":[{"embeddable":true,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=651"}],"version-history":[{"count":4,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/651\/revisions"}],"predecessor-version":[{"id":656,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/651\/revisions\/656"}],"wp:attachment":[{"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.geoplanit.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}