<?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 Python - Field Calculator Expression - Writing Bytearray to Text Field (WKB) in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/python-field-calculator-expression-writing/m-p/1062018#M41370</link>
    <description>&lt;P&gt;Need a little python help. This is for use in field calculator. Goal is to write the WKB representation of geometry objects (in a feature class) to a text field, for the purpose of exporting to csv.&lt;/P&gt;&lt;P&gt;ArcPy supports writing WKB of geometry objects. See:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/geometry.htm#P_GUID-BC466D06-360C-42BD-B198-DA4139B45F49" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/geometry.htm#P_GUID-BC466D06-360C-42BD-B198-DA4139B45F49&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The basic expression to get the WKB is !Shape.WKB!, although that returns a bytearray. I believe it needs to be encoded and converted to a string. The output should look like this image:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ColeAndrews_0-1622060899503.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/14255i079D921815F66069/image-size/large?v=v2&amp;amp;px=999" role="button" title="ColeAndrews_0-1622060899503.png" alt="ColeAndrews_0-1622060899503.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The text in that image exports to csv as: "\001\006\000\000\000\001\000\000\000\001\003\000\000\000\001\000\000\000\012\023\000\000\314\276\362 . . . "&lt;/P&gt;</description>
    <pubDate>Wed, 26 May 2021 20:40:46 GMT</pubDate>
    <dc:creator>ColeAndrews</dc:creator>
    <dc:date>2021-05-26T20:40:46Z</dc:date>
    <item>
      <title>Python - Field Calculator Expression - Writing Bytearray to Text Field (WKB)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-field-calculator-expression-writing/m-p/1062018#M41370</link>
      <description>&lt;P&gt;Need a little python help. This is for use in field calculator. Goal is to write the WKB representation of geometry objects (in a feature class) to a text field, for the purpose of exporting to csv.&lt;/P&gt;&lt;P&gt;ArcPy supports writing WKB of geometry objects. See:&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/geometry.htm#P_GUID-BC466D06-360C-42BD-B198-DA4139B45F49" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/geometry.htm#P_GUID-BC466D06-360C-42BD-B198-DA4139B45F49&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The basic expression to get the WKB is !Shape.WKB!, although that returns a bytearray. I believe it needs to be encoded and converted to a string. The output should look like this image:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ColeAndrews_0-1622060899503.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/14255i079D921815F66069/image-size/large?v=v2&amp;amp;px=999" role="button" title="ColeAndrews_0-1622060899503.png" alt="ColeAndrews_0-1622060899503.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The text in that image exports to csv as: "\001\006\000\000\000\001\000\000\000\001\003\000\000\000\001\000\000\000\012\023\000\000\314\276\362 . . . "&lt;/P&gt;</description>
      <pubDate>Wed, 26 May 2021 20:40:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-field-calculator-expression-writing/m-p/1062018#M41370</guid>
      <dc:creator>ColeAndrews</dc:creator>
      <dc:date>2021-05-26T20:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Field Calculator Expression - Writing Bytearray to Text Field (WKB)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-field-calculator-expression-writing/m-p/1062044#M41371</link>
      <description>&lt;P&gt;Here is a similar question:&lt;/P&gt;&lt;P&gt;&lt;A href="https://gis.stackexchange.com/questions/75967/pyqgis-converting-wkb-to-string" target="_blank"&gt;https://gis.stackexchange.com/questions/75967/pyqgis-converting-wkb-to-string&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 May 2021 21:03:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-field-calculator-expression-writing/m-p/1062044#M41371</guid>
      <dc:creator>ColeAndrews</dc:creator>
      <dc:date>2021-05-26T21:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Field Calculator Expression - Writing Bytearray to Text Field (WKB)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-field-calculator-expression-writing/m-p/1062159#M41383</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcpy.da import SearchCursor
in_fc = r"C:\arcpro_npg\npg\Project_npg\tests.gdb\sq"
with SearchCursor(in_fc, ['SHAPE@WKB']) as cursor:
    shps = [row[0] for row in cursor]
s0 = shps[0]
# --- first shape
s0
bytearray(b'\x01\x03\x00\x00\x00\x02\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\xa4O\x12A\x00\x00\x00@\xd0\x12SA\x00\x00\x00\x00\xa8O\x12A\x00\x00\x00\x00\xd2\x12SA\x00\x00\x00\x00\xa8O\x12A\x00\x00\x00\x80\xd2\x12SA\x00\x00\x00\x00\xa0O\x12A\x00\x00\x00\x80\xd2\x12SA\x00\x00\x00\x00\x88O\x12A\x00\x00\x00\x00\xd2\x12SA\x00\x00\x00\x00\x80O\x12A\x00\x00\x00\x00\xd0\x12SA\x00\x00\x00\x00\xa4O\x12A\x00\x00\x00@\xd0\x12SA\x04\x00\x00\x00\x00\x00\x00\x00\x8cO\x12A\x00\x00\x00\xc0\xd0\x12SA\x00\x00\x00\x00\x94O\x12A\x00\x00\x00\xc0\xd1\x12SA\x00\x00\x00\x00\x9cO\x12A\x00\x00\x00\xc0\xd0\x12SA\x00\x00\x00\x00\x8cO\x12A\x00\x00\x00\xc0\xd0\x12SA')

# ---- as hex
s0.hex()
'0103000000020000000700000000000000a44f124100000040d012534100000000a84f124100000000d212534100000000a84f124100000080d212534100000000a04f124100000080d212534100000000884f124100000000d212534100000000804f124100000000d012534100000000a44f124100000040d012534104000000000000008c4f1241000000c0d012534100000000944f1241000000c0d1125341000000009c4f1241000000c0d0125341000000008c4f1241000000c0d0125341'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry" target="_blank" rel="noopener"&gt;Well-known text representation of geometry - Wikipedia&lt;/A&gt;&lt;/P&gt;&lt;P&gt;if you can test with your inputs&lt;/P&gt;&lt;P&gt;Other options&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="from_WKB.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/14311i79C5C61746920F1A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="from_WKB.png" alt="from_WKB.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 01:47:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-field-calculator-expression-writing/m-p/1062159#M41383</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-05-27T01:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Field Calculator Expression - Writing Bytearray to Text Field (WKB)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-field-calculator-expression-writing/m-p/1062312#M41392</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp;, thanks for the response. Trying to simplify this as a field expression. Looks like I just need to use the hex function on the bytearray. If my empty field is called "WKB_String", then&amp;nbsp; [WKB_String] =&amp;nbsp;(!Shape.WKB!).hex() is populating the field. I would have thought the syntax was&amp;nbsp; [WKB_String] = hex.(!Shape.WKB!), but that throws an error that bytearray cannot be converted to integer. Does this image look like it is accomplishing the same end result as your script?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ColeAndrews_0-1622124863774.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/14354iB12D301F32C2CAF3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ColeAndrews_0-1622124863774.png" alt="ColeAndrews_0-1622124863774.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 14:35:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-field-calculator-expression-writing/m-p/1062312#M41392</guid>
      <dc:creator>ColeAndrews</dc:creator>
      <dc:date>2021-05-27T14:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: Python - Field Calculator Expression - Writing Bytearray to Text Field (WKB)</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/python-field-calculator-expression-writing/m-p/1062496#M41410</link>
      <description>&lt;P&gt;Confirmed, I took the string output of (!Shape.WKB!).hex() and input in to a few non-esri databases using spatial SQL functions. The databases can properly parse the hexidecimal WKB in to GEOMETRY/GEOGRAPHY data.&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 18:34:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/python-field-calculator-expression-writing/m-p/1062496#M41410</guid>
      <dc:creator>ColeAndrews</dc:creator>
      <dc:date>2021-05-27T18:34:03Z</dc:date>
    </item>
  </channel>
</rss>

