I am trying to use arcpy and pandas to build a line geometry from 2 point geometry columns in a pandas dataframe. I create the dataframe by loading in the featureclass using the GeoAccessor
from arcgis import GeoAccessor
from pandas import DataFrame as pdDataFrame
from arcpy import Polyline as apPolyline, Array as apArray, PointGeometry as apPointGeo, Point as apPoint
sdf1 = pdDataFrame.spatial.from_featureclass(r'MyGDB\MyPointFC_spoints')
sdf2 = pdDataFrame.spatial.from_featureclass(r'MyGDB\MyPointFC_epoints')
sdf2 = sdf2.add_prefix('end_')
sdf1 = sdf1.merge(sdf2, how='Left', left_on='sjid', right_on='ejid')
SDF1 now has 2 SHAPE columns that are point columns named 'SHAPE' and 'end_SHAPE' I have a custom function that takes the 2 shape columns and makes a polyline
def buildSegments(x):
point = apPoint()
array = apArray()
point.X = x['SHAPE'].x
point.Y = x['SHAPE'].y
array.add(point)
point.X = x['end_SHAPE'].x
point.Y = x['end_SHAPE'].y
array.add(point)
return apPolyline(array, spatial_reference=x['SHAPE'].spatial_reference)
Then I use this to update the SHAPE column in my datframe and drop all the columns that start with "end_"
sdf1['SHAPE'] = sdf1.apply(buildSegments, axis=1)
cols = [col for col in sdf1 if col.startswith('end_')]
sdf1 = sdf1.drop(columns=cols)
sdf1.spatial.to_featureclass(location=r'MyGDB\MyLineSegments', overwrite=True)
What I get is an empty geometry when I add a print statement to the custom function to print what is being returned to the SHAPE column it shows it is returning a geoprocessing object <geoprocessing describe geometry object object at 0x000001A9F576D120> how do I get the geometry from this object to update my geometry column with?
.WKTproperty, but only after being sure that GeoPandas wasn't required.