AnsweredAssumed Answered

Can't export SpatialDataFrame to Shapefile

Question asked by oisins on Jan 11, 2019
Latest reply on Jan 11, 2019 by bixb0012

Hi,
I'm trying to export a SpatialDataFrame which I've imported from ArcGis Online as such:

 

gis = GIS("site_url", "username", password)

feature_layers=gis.content.get("some_id")
all_layers=feature_layers.layers #get all layers

SDF= SpatialDataFrame.from_layer(all_layers[0])

 

I need to use the SpatialDataFrame to do some spatial queries to modify the data, (text fields)

 

When I try to export to a ShapeFile I get this error:

 

SDF.to_featureclass("output_folder","output_file.shp")
>>The following rows could not be written to the table: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28

 

If I try :

SDF.to_featureclass("output_folder","output_file.shp", skip_invalid=False)

Traceback (most recent call last):
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\_data\geodataset\io\fileops.py", line 579, in to_featureclass
icur.insertRow(row)
RuntimeError: Cannot find field 'b'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<pyshell#26>", line 1, in <module>
SDF.to_featureclass("output_folder","output_file.shp",skip_invalid=False)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\_data\geodataset\geodataframe.py", line 1399, in to_featureclass
overwrite=overwrite, skip_invalid=skip_invalid)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\_data\geodataset\io\fileops.py", line 583, in to_featureclass
raise Exception("Invalid row detected at index: %s" % index)
Exception: Invalid row detected at index: 0 


If i open the file created ( no records)  the second column is missing ? and an Id column has been inserted


any ideas ? I've made sure no fields are blank,null or None , I've tried renaming the columns 

Update: I Read in a Shapefile and tried to write it back to a new shapefile in a different folder with a different name and it gives the same error

Outcomes