Using Python API to download Filtered Data

153
1
09-30-2022 07:34 PM
neomapper
New Contributor III

Is it possible to add a filter clause when using the Python API for exporting a feature class to file geodatabase on ArcGIS Online?

 

from time import strftime
print(strftime('%c'))

from arcgis.gis import GIS

layer_Dict = ["Service Request v411"]
itemid_Dict =['#']
saveName = ''
tempfile = strftime('Backup_%m_%d_%Y')
output = r'C:\Users\aa2zz6\Downloads'

for i, fc in enumerate(layer_Dict):
    itemid = itemid_Dict[i]
    fc_lyr = fc
    print(itemid)
    #print(FC_ID)
    outName = '{}{}'.format(fc_lyr,tempfile)
    print(saveName)
    gis = GIS('https://#.maps.arcgis.com/', '#', '#')
    dataitem = gis.content.get(itemid)
    dataitem.export(outName, 'File Geodatabase', parameters=None, wait=True)
    myexport = gis.content.search(outName, item_type='File Geodatabase')
    fgdb = gis.content.get(myexport[0].itemid)
    fgdb.download(save_path=output)
    fgdb.delete()

    
print('Script Complete at {}'.format(strftime('%c')))

 

 

0 Kudos
1 Reply
jcarlson
MVP Honored Contributor

Not doing it this way, I don't think. Could you use a layer's query method to get your subset of features, then export the FeatureSet / dataframe to a local FGDB? This would bypass creating an additional item in your GIS, too.

- Josh Carlson
Kendall County GIS
0 Kudos