<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Arcmap cannot label based on shape field in Mapping Questions</title>
    <link>https://community.esri.com/t5/mapping-questions/arcmap-cannot-label-based-on-shape-field/m-p/744048#M8034</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sooo... it works for lines and polygons, not points.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For lines, the field st_length(shape) appears in the fields list.&lt;/P&gt;&lt;P&gt;So this works (vbscript):&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;round([st_length(shape)],1) &amp;amp; "m"&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For polygons, the field st_area(shape) appears in the field list.&lt;/P&gt;&lt;P&gt;So this works (vbscript):&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;round([st_area(shape)]/10000,1) &amp;amp; "ha"&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For points, there's no access to the shape field nor any derivation.&lt;/P&gt;&lt;P&gt;There is a workaround, that's a bit complex, and may suffer low performance with many points.&lt;/P&gt;&lt;P&gt;But for a few points it works, it's just incredibly convoluted to do such a simple task (python):&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ( [objectid] ):
 lr="layer name"
 with arcpy.da.SearchCursor(lr, 'Shape@',r'"objectid"='+str( [objectid] )) as cursor:
   for row in cursor:
     a=row[0]
     x = str(round(a[0].X,1))
     y = str(round(a[0].Y,1))
 return x + ";" + y&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 16:52:22 GMT</pubDate>
    <dc:creator>DuarteCarreira</dc:creator>
    <dc:date>2021-12-12T16:52:22Z</dc:date>
    <item>
      <title>Arcmap cannot label based on shape field</title>
      <link>https://community.esri.com/t5/mapping-questions/arcmap-cannot-label-based-on-shape-field/m-p/744047#M8033</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm just looking for confirmation from fellow arcmap users.&lt;/P&gt;&lt;P&gt;Is this true? Can anyone have a simple X,Y label for points in arcmap?&lt;/P&gt;&lt;P&gt;Or a "XXX m2" label for polygons?&lt;/P&gt;&lt;P&gt;Just with a label expression?&lt;/P&gt;&lt;P&gt;For feature classes in enterprise geodatabases?&lt;/P&gt;&lt;P&gt;Without creating fields that need to be updated manually or in some convoluted automated way?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am an old arcmap user, and I know this was bread&amp;amp;butter... did we lose this basic gis ability?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If not, please, please let me know how to do it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Duarte&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Aug 2019 10:23:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/arcmap-cannot-label-based-on-shape-field/m-p/744047#M8033</guid>
      <dc:creator>DuarteCarreira</dc:creator>
      <dc:date>2019-08-09T10:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: Arcmap cannot label based on shape field</title>
      <link>https://community.esri.com/t5/mapping-questions/arcmap-cannot-label-based-on-shape-field/m-p/744048#M8034</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sooo... it works for lines and polygons, not points.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For lines, the field st_length(shape) appears in the fields list.&lt;/P&gt;&lt;P&gt;So this works (vbscript):&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;round([st_length(shape)],1) &amp;amp; "m"&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For polygons, the field st_area(shape) appears in the field list.&lt;/P&gt;&lt;P&gt;So this works (vbscript):&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;round([st_area(shape)]/10000,1) &amp;amp; "ha"&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For points, there's no access to the shape field nor any derivation.&lt;/P&gt;&lt;P&gt;There is a workaround, that's a bit complex, and may suffer low performance with many points.&lt;/P&gt;&lt;P&gt;But for a few points it works, it's just incredibly convoluted to do such a simple task (python):&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def FindLabel ( [objectid] ):
 lr="layer name"
 with arcpy.da.SearchCursor(lr, 'Shape@',r'"objectid"='+str( [objectid] )) as cursor:
   for row in cursor:
     a=row[0]
     x = str(round(a[0].X,1))
     y = str(round(a[0].Y,1))
 return x + ";" + y&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:52:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/arcmap-cannot-label-based-on-shape-field/m-p/744048#M8034</guid>
      <dc:creator>DuarteCarreira</dc:creator>
      <dc:date>2021-12-12T16:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: Arcmap cannot label based on shape field</title>
      <link>https://community.esri.com/t5/mapping-questions/arcmap-cannot-label-based-on-shape-field/m-p/744049#M8035</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So more info... a few months later with arcmap 10.7.1 and using Python this time. See solution below.&lt;/P&gt;&lt;P&gt;I just noticed that shape_area is of type unicode...&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;str(type([st_area(shape)]))&lt;/PRE&gt;&lt;P&gt;shows &amp;lt;type 'unicode'&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also since my locale uses "," for decimal places it complicates even more.&lt;/P&gt;&lt;P&gt;For instance, multiplying st_area(shape) by 1 works fine, it returns "49698,074309".&lt;/P&gt;&lt;P&gt;Now let's divide by 1:&amp;nbsp;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;[st_area(shape)]/1
TypeError: unsupported operand type(s) for /: 'unicode' and 'int'&lt;/PRE&gt;&lt;P&gt;Hmm, what's going on?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let's try to convert to float:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;float([st_area(shape)])
ValueError: invalid literal for float(): 49698,074309&lt;/PRE&gt;&lt;P&gt;What?&lt;/P&gt;&lt;P&gt;Ok, let's convert it to int:&lt;/P&gt;&lt;P&gt;int([st_area(shape)])&lt;BR /&gt;ValueError: invalid literal for int() with base 10: '49698,074309'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What if the issue is the decimal separator? Let's replace "," with ".":&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;int([st_area(shape)].replace(",","."))
ValueError: invalid literal for int() with base 10: '49698.074309'&lt;/PRE&gt;&lt;P&gt;That's no it either... strange enough it works for float which is good enough for me:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;float([st_area(shape)].replace(",","."))
49698,074309&lt;/PRE&gt;&lt;P&gt;If you look carefully you'll see we've gone from "," to "." back to "," again...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So in short we have to replace decimal separator with "." and then convert to float so we can finally convert m2 to hectares:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;str(float([st_area(shape)].replace(",","."))/10000) + " ha"
4.9698074309 ha&lt;/PRE&gt;&lt;P&gt;Notice how again we are showing "."?&lt;/P&gt;&lt;P&gt;Anyway, a bit convoluted but still better than using cursors!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:52:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/mapping-questions/arcmap-cannot-label-based-on-shape-field/m-p/744049#M8035</guid>
      <dc:creator>DuarteCarreira</dc:creator>
      <dc:date>2021-12-12T16:52:25Z</dc:date>
    </item>
  </channel>
</rss>

