empty geometry error when applying spatially enabled dataframe's to_featureclassSee 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)
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.
- Created 3 years ago
- Comments:10 (4 by maintainers)
Top GitHub Comments
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.
At the latest release, we added an optional sanitize column parameter when exporting data.