Migrating to GeoAccessor insead of SpatialDataFrame

688
2
01-14-2020 07:04 PM
MaazaMekuria
Occasional Contributor

I am a bit confused by the GeoAccessor documenation and miss the improvement made by using it instead of the the now deprecated SpatialDataFrame.  I tried to move to the geoAccessor (gac function below) but what I get is not a dataframe or anything I can convert to a feature or set the geometry column etc. 

 Image below shows a pandas dataframe iterated using df.itertuples() (i.e. for mrow in df.itertuples(): 

What I want to do is convert this row data which was originally in a feature layer (has itsown geometry) from a pandas frame again to a feature (later on featureset) after performing other operations.  How can I do that using the geoaccessor instead of using SpatialDataFrame (which was a lot more simpler)?  Since the mrow is not geometry aware, I must set the geometry column, but I could not do that via the geoaccessor even though the documentation says I can.  SpatialDataFrame gives me what I need but I want to move forward. 

0 Kudos
2 Replies
Peter_Klingman
Esri Regular Contributor
0 Kudos
carlhyde
New Contributor

Iterating through large pandas dataFrame objects is generally slow. Pandas iteration beats the whole purpose of using DataFrame. It is an anti-pattern and is something you should only do when you have exhausted every other option. It is better look for a List Comprehensions , vectorized solution or DataFrame.apply() method.

Pandas DataFrame loop using list comprehension example

result = [(x, y,z) for x, y,z in zip(df['column_1'], df['column_2'],df['column_3'])]

 

0 Kudos