I am currently attempting to create a script to download shapefiles from ArcGIS Online to my local drive before adding it to an aprx project and thereafter uploading it to a ArcGIS portal/enterprise.

All the above I have managed by downloading them as shapefiles -> convert .shp to feature class (in gdb) and then uploading it to the aprx.

However, when I run the script the symbology do not tag along. I have tried finding methods of downloading lyrx files from AGOL without any luck.

Do any of you know of a way to download the symbology from AGOL and merge them with the shapefile or feature class?

Here's the most relevant functions in the code I've used:

def agol_login(AGOL_url,AGOL_user,AGOL_pw):
    # gis_q = AGOL_url + ', ' + AGOL_user + ', ' + AGOL_pw
    print('AGOL login')
    gis = GIS(AGOL_url,AGOL_user,AGOL_pw)
    return gis

def createGDB():
    if folder_exist(path to gdb):
        gdb = 'testpath'
        gdb = arcpy.CreateFileGDB_management(path to folder, gdb)

def folder_exist(path):
    if arcpy.Exists(path):
        print(path + " Exist")
        return True
        print(path + " does not exist")
        return False

def downloadUserItem2(item, export_location, downloadFormat):
    # type: (object, object) -> object
        name = item.title.replace(" ", "_")
        result = item.export(name.format(item.type), downloadFormat)

        zip_path = export_location + "\\" + name + ".zip"
        zip_file = ZipFile(zip_path)

    except Exception as e:

def SHPtoGDB():
    # Set the workspace for ListFeatureClasses
    arcpy.env.workspace = "path to folder"
    # Use the ListFeatureClasses function to return a list of shapefiles.
    featureclasses = arcpy.ListFeatureClasses()
    # Copy shapefiles to a file geodatabase
    for fc in featureclasses:
            fc, os.path.join("path to gdb",

def AddFCtoAPRX():
    arcpy.env.workspace = "path to gdb"
    datasets = arcpy.ListDatasets(feature_type='feature')
    datasets = [''] + datasets if datasets is not None else []
    rootPath_aprx = 'path to aprx folder'
    aprx = arcpy.mp.ArcGISProject(rootPath_aprx + 'TestWMS.aprx')
    aprxMap = aprx.listMaps("Map")[0]
    for ds in datasets:
        for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
            path = os.path.join(arcpy.env.workspace, ds, fc)
            print ("List of feature classes:")
                test = aprxMap.addDataFromPath(path)
                print("Feature Classes added to Arcgis Pro..")
    print("APRX path is:")

def UploadtoPortal():
    rootPath_aprx = 'C:\\Users\\ESSE\\Documents\\ArcGIS\\Projects\\TestWMS\\'
    aprx = arcpy.mp.ArcGISProject(rootPath_aprx + 'TestWMS.aprx')
    m = aprx.listMaps('Map')[0]
    arcpy.mp.CreateWebLayerSDDraft(m, rootPath_aprx + 'TestWMS.sddraft', 'Map', 'MY_HOSTED_SERVICES', 'FEATURE_ACCESS')
    arcpy.StageService_server(rootPath_aprx + 'TestWMS.sddraft', rootPath_aprx + 'TestWMS.sd')
    print("Uploading Service Definition to Portal...")
    arcpy.UploadServiceDefinition_server(rootPath_aprx + 'TestWMS.sd', 'My Hosted Services')
  • What is the downloadFormat being used in this chunk: result = item.export(name.format(item.type), downloadFormat) – KHibma Jun 21 '19 at 12:01
  • Shapefile, then added to gdb afterwards. – Sineik Jun 21 '19 at 12:03
  • I can't add an answer as this is on-hold. But in short, you wont get the symbology via any sort of Extract on a feature service.. None of those formats include symbology. You'd need to ingest the service layers themselves into your map (they'd retain symbology). Or the real long way would be to look at the JSON making up the symbology of the layers in a webmap, and somehow convert that into symbols inside ArcGIS Pro. – KHibma Jun 21 '19 at 12:17
  • SHP do not contain any symbology and depending on the case the symbols might only exist in the web map or layer item and not that the service level and you would need to extract the JSON there. – Russ Roberts Jun 21 '19 at 14:31
  • Is there a specific reason you want to download and convert then re-upload to Portal instead of adding the items directly to the portal via the 'Add Item > From the Web' utility or as @KHibma mentions just adding them to a map and sharing them as a service from there? – landocalrissian Jun 21 '19 at 15:37

Your Answer

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

Browse other questions tagged or ask your own question.