spatiallly Enabled Dataframe append

3693
16
Jump to solution
01-23-2019 05:40 AM
OisinSlevin
New Contributor III

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)

0 Kudos
1 Solution

Accepted Solutions
OisinSlevin
New Contributor III

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 

View solution in original post

0 Kudos
16 Replies
JoshuaBixby
MVP Esteemed Contributor

Is it overwriting other columns or just SHAPE?  If just SHAPE, it seems like a defect that should be logged with Esri Support.

0 Kudos
OisinSlevin
New Contributor III

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

0 Kudos
simoxu
by MVP Regular Contributor
MVP Regular Contributor

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. 

0 Kudos
OisinSlevin
New Contributor III

# 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

0 Kudos
DanPatterson_Retired
MVP Emeritus

The spatially enabled dataframe doesn't have an option to create a new version from a 'template' like you can with featureclasses?

0 Kudos
OisinSlevin
New Contributor III

I'm creating a SEDF from a shape file and removing the features from it, but I keep one feature as a Template.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

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. 

0 Kudos
OisinSlevin
New Contributor III

Record_to_append must previously be a line geometry so you can overwrite the path

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

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.

0 Kudos