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")
Answer
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")
No comments:
Post a Comment