question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

empty geometry error when applying spatially enabled dataframe's to_featureclass

See original GitHub issue

Pro 2.5. When I try to execute to_featureclass on my spatially enabled dataframe I get the following run time error: The operation was attempted on an empty geometry.

I have run a script which checks for empty geometries in my dataframe and I don’t detect any.

To Reproduce Steps to reproduce the behavior:

db = r'C:/sandbox/testout.gdb'
fc_name = os.path.join(db,'test_usda2')
arcpy.env.overwriteOutput=True
df_join = pd.merge(state_df, df_csv, how='right', left_on='NAME', right_on='State')
#check for null and empty geometries
for index, row in df_join.iterrows():
    row = row.copy()
    if not pd.isnull(row["SHAPE"]):
        if row["SHAPE"].is_empty:
            print('empty geometry')
            df_join.loc[index, "SHAPE"] = -999999
    else:
         df_join.loc[index, "SHAPE"] = -999999
df_join.drop(df_join[df_join["SHAPE"] == -999999].index, inplace=True)
df_join.spatial.to_featureclass(location=fc_name)

error:

RuntimeError                              Traceback (most recent call last)
<ipython-input-333-4608aea7f523> in <module>
     13          df_join.loc[index, "SHAPE"] = -999999
     14 df_join.drop(df_join[df_join["SHAPE"] == -999999].index, inplace=True)
---> 15 df_join.spatial.to_featureclass(location=fc_name)

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\geo\_accessor.py in to_featureclass(self, location, overwrite)
   1923         return to_featureclass(self,
   1924                                location=location,
-> 1925                                overwrite=overwrite)
   1926     #----------------------------------------------------------------------
   1927     def to_table(self, location, overwrite=True):

C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\geo\_io\fileops.py in to_featureclass(geo, location, overwrite, validate)
    610 
    611         array = np.array([], np.dtype(dtypes))
--> 612         arcpy.da.ExtendTable(fc, oidfld, array, join_dummy, append_only=False)
    613 
    614         # 3. Insert the Data

RuntimeError: The operation was attempted on an empty geometry.

Screenshots If applicable, add screenshots to help explain your problem.

Expected behavior Exports to feature class successfully

Platform (please complete the following information):

  • OS: windows
  • Browser na
  • Python API Version: 1.7

Additional context Add any other context about the problem here, attachments etc.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nzjscommented, Jul 2, 2021

Can I request that improved error handling around this be added to the API? I recently ran into the above along with a separate issue #606, both errors returned were unrelated to the underlying problem.

For this issue, some of my dataframe column names were using characters unsupported in a GDB. For issue #606, some of my dataframe columns were unsupported dtypes.

I know it isn’t critical, but it might be helpful for future users of the library.

1reaction
achapkowskicommented, Jul 10, 2020

At the latest release, we added an optional sanitize column parameter when exporting data.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: System Error when exporting Spatially Enabled Data...
I'm trying to do the following: Convert a non-spatial pandas dataframe to a spatial dataframe; Export the spatial dataframe to a feature class ......
Read more >
Export ArcGIS spatially enabled dataframe to feature class
I had this issue after updating ArcGIS Pro and arcpy to v2.9. Basically if the SEDF did not have a geometry column named...
Read more >
Spatially Enabled DataFrames - Advanced Topics
We can see that the SHAPE column is of type geometry . This means that compared to the legacy SpatialDataFrame class, geometry columns...
Read more >
Automatically Convert to Esri Spatially Enabled Dataframe
I frequnetly need a Spatially Enabled Dataframe from a variety of sources, and these sources ... from arcgis.geometry import Geometry.
Read more >
Check and repair the geometry for features in an Enterprise ...
Features created using Esri Spatial types are created with ArcGIS Software and hence won't have any geometry errors.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found