0

I am trying to export/copy a feature service to a local geodatabase where I can work on it locally.

I have provided the code below. I keep getting an "Object: Error in executing tool" for the last line where I am trying to copy the feature.

from arcgis.gis import GIS
from arcgis.features.use_proximity import create_buffers

import arcpy

#########################################################################################

GDB_Name = input("Name Geodatabase")

Folder_Input = input("Provide Folder Path of Project")

Item_ID = input("Provide item ID")


#########################################################################################

gis = GIS("http://arcgis.com", "XXXXXXXX", "XXXXXXXXXXX")

search_results = gis.content.search('{}'.format(Item_ID))

Trail_Data = search_results[0]

WorkspaceGDB = arcpy.CreateFileGDB_management(Folder_Input, '{}.gdb'.format(GDB_Name))
print("GDB created")

arcpy.env.workspace = r'{}'.format(WorkspaceGDB)

arcpy.CopyFeatures(Trail_Data, "Area_Trail_Data")
  • 1
    Simply, your Trial_Data is a pointer to an ArcGIS Python API item. This is not valid input to the CopyFeatures tool. You're on the right track, but this workflow, as-is will not work without coming at this from another angle. – KHibma Aug 13 at 14:58
  • I'm going to try and download the "searched item" as a shapefile, then locate the newly downloaded shapefile, and try to copy from there. I will update the post if this workflow works. – P. Shutler Aug 13 at 18:55
0

Using your Trail_Data variable:

# select all features
query = Trail_Data.query(where='1=1')

# save selected features to specified geodatabase
query.save("path_to_geodatabase", "new_feature_class_name")

I am constantly confused by the ArcGIS API for Python, but from what I gather, your Trail_Data variable is a Feature Collection and the query result is a Feature Set. The Feature Set can be saved directly to a file geodatabase.

0

So I figured it out. The issue I was having is that I wasn't referencing down all the way to the REST API URL. Once you give it the feature service URL page to your feature service then it works fine.

Code provided below:

from arcgis.gis import GIS

import arcpy

gis = GIS("http://arcgis.com", "XXXXXXXXX", "XXXXXXXXXXX")
print("Credentials Verified")


########################################################################################################################

GDB_Name = input("Name Geodatabase: ")

Folder_Input = input("Provide Folder Path of Project: ")

REST_URL_for_Feature = input("Provide : REST Item URL")

Feature_Class_Name = input("Provide Name for New Feature Class: ")

########################################################################################################################

WorkspaceGDB = arcpy.CreateFileGDB_management(Folder_Input, '{}.gdb'.format(GDB_Name))

arcpy.env.workspace = r'{}'.format(WorkspaceGDB)

print("GDB Created")
########################################################################################################################

arcpy.CopyFeatures_management(REST_URL_for_Feature, Feature_Class_Name)

print("Features copied to geodatabase")
print("Process Finished")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.