1

Wondering if anyone can assist. I have a need to have the JSON geometry string of my features written into a text field of the features attribute table. Currently I use Calculate Field and then with Expression Type set as Python 3, I use !Shape!.JSON to get the geometry of my shape written in the JSON format.

An example of the output is as below:

{"paths":[[[532598.86840000004,180156.41719999909],[532598.97449999955,180156.3571000006],[532599.06400000025,180156.30650000088],[532599.91660000011,180155.82430000044],[532600.00329999998,180155.77520000003],[532601.43379999977,180154.96600000001],[532601.49770000018,180154.92980000004],[532601.52730000019,180154.91300000064],[532601.59130000044,180154.87680000067],[532601.62550000008,180154.85749999993],[532601.81120000035,180154.75239999965],[532601.91069999989,180154.70790000074],[532602.01410000026,180154.68319999985],[532602.11649999954,180154.67769999988],[532602.22149999999,180154.69099999964],[532606.99629999977,180155.82829999924],[532610.7949000001,180156.73310000077],[532611.03139999975,180156.79880000092],[532611.28399999999,180156.89069999941],[532611.66770000011,180157.07819999941],[532611.98379999958,180157.28370000049],[532612.27969999984,180157.52869999968],[532612.59509999957,180157.86690000072],[532612.81230000034,180158.16840000078],[532612.99129999988,180158.48660000041],[532613.12820000015,180158.80629999936],[532613.21600000001,180159.08269999921],[532613.27099999972,180159.32069999911],[532613.31290000025,180159.60600000061],[532613.32870000042,180159.8423999995],[532613.32699999958,180160.08899999969],[532613.3088999996,180160.31799999997],[532613.27969999984,180160.51909999922],[532612.90199999977,180162.50180000067],[532612.82749999966,180162.96209999919],[532612.73489999957,180163.53390000015],[532612.33550000004,180166.00210000016]]],"spatialReference":{"wkid":27700,"latestWkid":27700}}

However the resulting string has the coordinate system reference (in BOLD above) included at the end of the string. I need to be able to exclude the CRS information. I found a C# code example for exporting geometries to JSON which includes the ability to set an export flag to exclude the CRS info when writing the JSON string out. However I need to implement this in the Calculate Field environment using either Python 3 or Arcade.

Failing this being possible, in what environment would I be able to implement the C# code? Here is a link to the ESRI page with the example referred to above: https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic8167.html

asked Aug 7, 2023 at 10:54

1 Answer 1

0

You can convert the JSON string to a Python dictionary using json — JSON encoder and decoder - Python 3.x documentation, pop off the spatial reference item, and then convert back to JSON.

Something along the lines of:

import json
def strip_json_crs(shape_json):
 d = json.loads(shape_json)
 d.pop('spatialReference')
 return json.dumps(d)
answered Aug 7, 2023 at 18:00
1
  • What a legend! That did the trick. Commented Aug 8, 2023 at 12:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.