Add Geometry as Text Options to 'Calculate Geometry Attributes' (WKT, WKB, GeoJSON)

10-16-2020 07:30 AM
Status: Open
Occasional Contributor III

As mentioned here by Kory Kramer, ArcPy now has functions to calculate spatial objects as text, such as WKT and GeoJSON. Please add this to an out of the box GP tool-- I believe Calculate Geometry Attributes is the perfect place for it. 

Purpose: populate a text field with the string representation of valid geometric objects, with options including WKT, WKB, and GeoJSON.

Use case: Portability of GIS data. We need the ability to load a delimited csv of all tabular attributes of a feature class to data warehouses, including one text field containing the text representation of a spatial object. Once the csv is loaded to a data warehouse as a table, most of the database platforms can convert the geometry text to a spatial object using SQL functions like ST_FromText and TO_GEOGRAPHY.


You got my vote, I think this it quite a good idea.


This is a relatively simple enhancement that would make this task much easier to work with, especially in model builder, so I requested it be logged as a formal enhancement. Here is the enhancement number:


The esri product team marked this enhancement (ENH-000134719) as not in product plan because it can be done with ArcPy, so I am adding more context to this request.

The WKB function !Shape.WKB! outputs a bytearray, which can't be written to a basic file geodatabase field. For portability purposes, the bytearray should be converted to hexadecimal and stored in a text field. If you look at spatial SQL functions that create GEOMETRY or GEOGRAPHY columns from WKB (non-esri databases), the input type is this hexadecimal format. 

For complex geometries, the WKT, WKB, or GeoJSON can be extremely long in terms of # of characters. Using the field calculator, I have to create the new field and give the field the max text length available to ensure no truncation happens. 

If we added these functions to the 'Add Geometry Attributes' tool, that tool can auto-size the new field based on the length of the output text representation. Additionally, it increases the user-friendliness and intuitiveness of these ArcPy parameters.