0

I have a simple script that I want to use to export multiple hosted feature layers at once. This is my code:

import arcpy

fcList = arcpy.GetParameterAsText(0)  #input hosted feature layers 
out_workspace = arcpy.GetParameterAsText(1)  #output geodatabase
p_info = arcpy.GetParameterAsText(2)  #project name text to append onto input layer name
arcpy.overwriteOutput = True

proj = arcpy.mp.ArcGISProject('CURRENT') #set project

#export all the feature services to a geodatabase

for fc in fcList:
    outputFeatures = fc + '_' + p_info
    arcpy.conversion.FeatureClassToFeatureClass(fcList, out_workspace, outputFeatures)

I am getting these errors:

ERROR 000732: Input Features: Dataset 'Data Point';'Ground Control Point layer' does not exist or is not supported ERROR 000354: The name contains invalid characters Failed to execute (FeatureClassToFeatureClass).

I know that feature layers are supported in ArcGIS Pro 2.8 since I can use them as inputs for the Feature Class to Feature Class tool. I have a Basic License, when I export feature layers to gdb using the regular tool, I get the Message Warning #001102, You must have at least the Standard License to run this tool with the specified data. The data exports fine though, so I tend to ignore this message. None of the feature layers have attachments.

To fix this script, do I need to specify the workspace?

enter image description here

I have a parameter for the input features (fcList), which is a multivalue. I do not have an "in" workspace parameter. I only have the output gdb as a workspace parameter.

Is my issue related to the fact that I am working with feature layers, or I have not set the workspace?

1 Answer 1

2

I have achieved similar in the past with the below code. I have commented but let me know if anything needs clarification. Basically it uses a combination of the ArcGIS Python API and ArcPy to access the feature services and export layers to feature classes in a gdb.

from arcgis import GIS
import arcpy

## set to True if you want any attachments to also be exported
## a lot faster to ignore any attachments if they are not needed as output
arcpy.env.maintainAttachments = False

## access AGOL
conn = GIS("home")

## you could change this to a list of feature service ids and iterate to
## export them to gdb
## get the item ID from the Feature Service page on AGOL, it is in the URL
## bar at the top of the browser 
fs_id = "INSERT ITEM ID"

## gdb path to export to
out_gdb = r"INSERT GDB PATH"

## get the fs content, here is where you could loop through multiple feature
## service ids and export
item = conn.content.get(fs_id)

## use item.tables if interested in non-spatial tables
for lyr in item.layers:
    ## you might need to use the string replace function and replace any
    ## spaces with underscores as fc naming wont allow spaces and the
    ## feature class to feature class tool will fail.
    fc_name = lyr.properties.name
    ## at this point you could use an if statement if you are only interested 
    ## in layers with a certain name
    print(fc_name)
    ## get direct url to the layer within the feature service
    fc = lyr.url
    ## export to gdb
    arcpy.FeatureClassToFeatureClass_conversion(fc, out_gdb, fc_name)
2
  • Thank you for the suggestion. Is it possible to use the GetParameterAtText for the fs_id? Example: fs_id = GetParameterAsText(). I cannot hard code the input. I want the tool user to be able to choose the feature services to pass to Feature Class to Feature Class. That is the crux for me.
    – sparky
    Aug 24, 2021 at 16:33
  • Yes, you can have it as a single input for one feature service or as multiple input, you will just need to add in code to handle the loop/iteration of the multiple id entries. Aug 24, 2021 at 20:29

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.