You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I briefly chatted with two of you at the expo in Palm Springs last week, and thought I'd give this new repo's issues section a try...
Describe the bug
I'm sending some polygon data (as JSON) to a vendor's API, and finding some differences in the coordinate structure when using the .JSON property vs the .WKT property of the arcpy.Geometry object. I suspect this might be a bug within the .JSON property, although is also very niche and may lead to some other resolution.
The difference only occurs for polygons with a self-intersection, e.g.,:
To Reproduce
Please provide steps or code to reproduce the behavior
I'm on ArcGIS Pro 3.2 / Python 3.9
A simple shapefile (with a self-intersection) is here: example.zip
A difference can be seen by getting the geometry object, calling .JSON and .WKT, and comparing the results.
The code below includes a string replacement hack I'm using (as a stand-in, getting the desired json from the wkt), and makes this difference a little clearer.
import arcpy
import json
def wkt_to_json(wkt: str):
"""
Janky text replacement to mimic getting arcpy.Geometry.JSON from wkt
Args:
wkt (str): well known text
Returns:
str: coords as lists of lists, etc
"""
return wkt.replace(
"MULTIPOLYGON (((", "[[[["
). replace(
")))", "]]]]"
).replace(
")), ((", "]]],[[["
).replace(
"), (", "]],[["
).replace(
", ", "],["
).replace(
" ", ","
)
if __name__ == "__main__":
# define shp
shp_path = r"c:\_test\example.shp"
# get shape object in wgs 84
shape = arcpy.da.SearchCursor(
in_table = shp_path,
field_names = ["shape@"],
spatial_reference = arcpy.SpatialReference(4326)
).next()[0]
# get coord rings from json
rings_json = [json.loads(shape.JSON)["rings"]]
# get coord rings from wkt
rings_wkt = eval(wkt_to_json(shape.WKT))
# print results
print(f"\njson:\n{rings_json}\n\nwkt:\n{rings_wkt}\n")
Results in the following print message (notice the extra nesting level in the WKT):
Hello! I briefly chatted with two of you at the expo in Palm Springs last week, and thought I'd give this new repo's issues section a try...
Describe the bug
I'm sending some polygon data (as JSON) to a vendor's API, and finding some differences in the coordinate structure when using the .JSON property vs the .WKT property of the arcpy.Geometry object. I suspect this might be a bug within the .JSON property, although is also very niche and may lead to some other resolution.
The difference only occurs for polygons with a self-intersection, e.g.,:
To Reproduce
Please provide steps or code to reproduce the behavior
Results in the following print message (notice the extra nesting level in the WKT):
Expected behavior
I'd like to be able to use the .JSON method, since it's more concise and seems to work fine for all other polygons (without a self-intersection).
The text was updated successfully, but these errors were encountered: