Tuesday 28 May 2019

arcgis 10.1 - Generating true curve elliptical polygons in file geodatabase using ArcPy?


As background, this question arose from trying to answer a question on How to generate overlapping polygons from lines output from Table To Ellipse tool?



Using the ArcMap 10.1 GUI it is very easy to digitize true curve polygons into a file geodatabase feature class using the Ellipse Construction Tool but ...


Is it possible to write true curve elliptical polygons while reading rows (arcpy.da.SearchCursor) from a table containing a centre point, a major axis, a minor axis and an azimuth for each?


I had hoped that there might be a token available with arcpy.da.InsertCursor to do this, but SHAPE@ seems to be limited by what the Geometry object supports, and that does not appear to include true curves.



Answer



While arcpy Geometry objects do not support true curves, at 10.3, Esri implemented True Curves in the REST API, and therefore had to implement JSON support for them in FeatureSets. So you can "trick" arcpy into doing this for you if you create a curve in a JSON structure.


Here's an example: create a JSON file with true curves (this uses a circular arc and a Bezier curve), something like this:


{   'fieldAliases': {
'Id': 'Id',
'FID': 'FID'
},

'fields': [{
'alias': 'FID',
'type': 'esriFieldTypeOID',
'name': 'FID'
}, {
'alias': 'Id',
'type': 'esriFieldTypeInteger',
'name': 'Id'
}],
'displayFieldName': '',

'spatialReference': {
'wkid': 103734,
'latestWkid': 103734
},
'geometryType': 'esriGeometryPolyline'
'features': [{
'geometry': {
"curvePaths":[[
[6,3],[5,3],
{"b":[[3,2],[6,1],[2,4]]},

[1,2],
{"a":[[0,2],[0,3],0,0,2.094395102393195,1.83,0.33333333]}
]]
},
'attributes': {
'Id': 0,
'FID': 0
}
}],
}


Then, load that into a feature set and save it out to a Feature class.


fs = arcpy.FeatureSet()
fs.load(r'C:\path_to_your_json_file.json')
arcpy.management.CopyFeatures(fs, r'in_memory\test_curve')

And boom, you have true curves! This is what it created in ArcMap:


enter image description here


So in your case, maybe you can build a json structure by either casting the original features to a feature set and playing with the JSON, or as you iterate through rows in a search cursor. The math may be a little tricky to get what you want, but definitely is doable.





I should also mention that you don't have to form a full feature set, you can just pass the JSON geometry directly into the arcpy.AsShape(geojson, True) as well to get a geometry object back.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...