Using this code:
>>> polyline = arcpy.AsShape("""{"paths":[[[686187.19259999972,4929374.2093000002],[686221.91579999961,4929363.8212000001],[686224.60580000002,4929363.6297999993],[686227.87069999985,4929364.5913999993],[686230.85759999976,4929365.9749999996]]],"spatialReference":{"wkid":25832,"latestWkid":25832}}""", True)
>>> arcpy.CopyFeatures_management(polyline,"in_memory\polyline")
<Result 'in_memory\\polyline'>
>>>
>>> segment = arcpy.AsShape("""{"paths":[[[686187.19259999972,4929374.2093000002],[686230.85759999976,4929365.9749999996]]],"spatialReference":{"wkid":25832,"latestWkid":25832}}""", True)
>>> arcpy.CopyFeatures_management(segment,"in_memory\segment")
<Result 'in_memory\\segment'>
>>>
I get:
What version of ArcGIS are you using? I am using ArcMap 10.6.1.
When you print `polyline`, it shows the correct coordinates? And, CRS is defined in the output feature class (just verify that it actually gets set in the feature class)?
Nesting an insert cursor within a search cursor on the same feature class or table seems ripe for problems. That said, it isn't the cause of the issue you are seeing. Try the following code:
outpathname = "in_memory\polyline"
polyline = arcpy.AsShape("""{"paths":[[[686187.19259999972,4929374.2093000002],[686221.91579999961,4929363.8212000001],[686224.60580000002,4929363.6297999993],[686227.87069999985,4929364.5913999993],[686230.85759999976,4929365.9749999996]]],"spatialReference":{"wkid":25832,"latestWkid":25832}}""", True)
arcpy.CopyFeatures_management(polyline,outpathname)
SR = arcpy.Describe(outpathname).spatialReference
with arcpy.da.SearchCursor(outpathname, ['SHAPE@','*'] ) as cursor:
with arcpy.da.InsertCursor(outpathname, ['SHAPE@'] ) as icur:
for row in cursor:
polyline = row[0]
#print polyline
segment = arcpy.Polyline(arcpy.Array([polyline.firstPoint,polyline.lastPoint]),SR)
icur.insertRow([segment])
Yes!, it works! Thank you.
The problem is probably hidden in nested cursors. I also solved with a workaround. First duplicating records and after with a (not nested ) UpdateCursor updating the geometry, but your solution is more compact and I think I will use it.
Thank you again.
I think the issue here is that you were passing conflicting geometry data to the insert cursor. Since you used ["SHAPE@", "*"] for the fields, you were returning both a geometry object as well as a tuple of the shape's centroid x,y coordinates. When you went to insert the record, you passed a new geometry object but with the same tuple containing the previous geometry centroid.
Ok, I thinked something similar … but I always thinked that all spatial information was inside the SHAPE field and replacing it with a new geometry all should be fine.
Anyway Tahnk you again. I should be more carefull in using cursors.