I'm running a script to process an attached zipped shapefile, which converts it to a featureset to append into a hosted feature service. When processing the zipped shapefile, I'm running into an error when using the pandas.DataFrame.spatial.from_featureclass method. Here's the error that I'm getting:
Column SHAPE does not exist
Here's the extract of my code:
def extract_geometry_from_shp(layer, objectid, attachmentid):
#download shapefile and create a featureset.
import pandas as pd
from arcgis.features import GeoAccessor, GeoSeriesAccessor
attachment_folder = os.path.join(os.getcwd(), "attachments")
file_path = download_attachment(layer=layer, oid=objectid, attachmentid=attachmentid, download_folder=attachment_folder)
extract_path = os.path.join(attachment_folder, f"{objectid}_{attachmentid}")
logger.info(f"extracting shapefile(s) to {extract_path}")
shutil.unpack_archive(file_path, extract_path)
logger.info(f"extracted shapefile(s)")
for shp_file in os.listdir(extract_path):
if shp_file.endswith(".shp"):
shp_file = os.path.join(extract_path, shp_file)
logger.info(f"converting to featureset - shapefile: {shp_file}")
sdf = pd.DataFrame.spatial.from_featureclass(shp_file)
logger.debug(sdf.tail())
f_set = sdf.spatial.to_featureset()
logger.debug(f_set)
return f_set
To further clarify, I am running this in an ArcGIS Notebook. This used to work last year, but seems to not be working any more.
Further, the zipped shapefiles are able to be added using the "Add Data" tool in a Web Appbuilder product we have.
Thoughts?