I've created a blank spatially Enabled Dataframe with columns,
I'm attempting to append an a row to the Dataframe, which I'm doing successfully,
but as I append a row it overwrites the SHAPE column of all previous rows.
sdf.append(some_row, ingore_index=True)
Solved! Go to Solution.
Answer For this is when setting a geometry when appending to the SDF:
record_to_append.SHAPE=geometry.Geometry({'paths': [new_line], 'spatialReference': {'wkid': 29903, 'latestWkid': 29903}}
fixed this issue
Is it overwriting other columns or just SHAPE? If just SHAPE, it seems like a defect that should be logged with Esri Support.
Its just SHAPE,
have to write a cheat for writing back to arc online where I record the SHAPE in a standard python list and insert it into the json for uploading
I would double check the code that constructs the geometry for each row to append.
The append function for SDF is actually from standard Pandas DataFrame, which is pretty robust and unlikely to have a bug for this basic function. Anyway, hard to say without seeing the code.
# currently reading in a shapefile to get headers (saves creating the Spatially enabled DataFrame from scratch)
# I remove all rows but keep a deep copy of one record called record_template
# make a record to set values on
record_to_append=record_template.copy(deep=True)
# in code generating new_line using shapely linemerge (taking multiple line sections making one long route)
# for this example I took a sample see below
new_line = [[306572.786, 227598.16], [306581.202, 227591.756999999], [306585.583, 227587.403999999], [306589.315, 227583.198999999]]
record_to_append.SHAPE['paths']=[new_line]
record_to_append.Name="Some Value"
# attempting to use deep copy to fix the issue (no change)
SDF=SDF.append(record_to_append.copy(deep=True),ignore_index=True)
# I've also attempted to put the record into a dict but with the same result
dict_to_append=record_to_append.to_dict()
SDF=SDF.append(dict_to_append,ignore_index=True)
# When I view the records the Name value will change per record as expected, but the SHAPE value of all
# records is always equal to the most recent record appended
The spatially enabled dataframe doesn't have an option to create a new version from a 'template' like you can with featureclasses?
I'm creating a SEDF from a shape file and removing the features from it, but I keep one feature as a Template.
I am crafting an example to replicate your issue, but I am getting hung up on:
record_to_append.SHAPE['paths']=[new_line]
Trying to manipulate the geometry of the SHAPE column that way always generates a KeyError.
Record_to_append must previously be a line geometry so you can overwrite the path
My mistake. It wasn't the issue you describe, in terms of being a line geometry, I simply created/extracted the working record incorrectly and was working with a data frame still instead of a series. Once I got the record to the correct data type, the error accessing paths went away.