Select to view content in your preferred language

How to display recently created layers in GDB?

614
2
01-23-2023 10:31 AM
Labels (3)
Davec43
Occasional Contributor

I have a script that creates a GDB then join's two layers, saves that layer to a GDB, displays the newly created joined layer, splits it by attributes and saves the output into the newly created GDB. The issue I'm running into now is I don't know how to pull all the layers out of the GDB. After line 19 is where I don't know what to do next. I don't get any errors but it also doesn't add it to the map.

Since the layer is named by the attribute its split by it'll change with every data set and so will the amount of layers created. The output of the split also has to go to a GDB or folder (unless you know of another way) because I'll be splitting another layer which will have the same attributes and if their outputs are sent to the same location, it adds a "0" to the end of the duplicate layer and makes the future processes fail.

import os
import sys
import arcpy
#Paramaters
Database_Path = arcpy.GetParameterAsText(0) # Database Path for RTL/Tracks GDB
Existing_GDB = arcpy.GetParameterAsText(1) # Path to working GDB
Tracks_Join = arcpy.GetParameterAsText(2) # Path to working GDB
#Create RTL/TRACKS GDB
arcpy.management.CreateFileGDB(Database_Path, "RTL.gdb")
arcpy.management.CreateFileGDB(Database_Path, "Tracks.gdb")
#Joins and paths
FP1 = os.path.abspath(Existing_GDB)
FP2 = os.path.join(Database_Path, "Tracks.gdb")
outputFile1 =  fr"{FP1}\Tracks_Joined"
outputFile2 =  fr"{FP1}\Tracks_Joined"
#ArcPy Execution for Tracks
arcpy.management.CopyFeatures(Tracks_Join, fr"{FP1}\Tracks_Joined")
arcpy.management.JoinField("Tracks_Joined", "Event", "Points_Filtered", "Event", None)
arcpy.analysis.SplitByAttributes("Tracks_Joined", FP2, "CL")
arcpy.env.workspace = FP2
datasets = arcpy.ListDatasets(feature_type='feature')
datasets = [''] + datasets if datasets is not None else []
for ds in datasets:
    for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
        path = os.path.join(arcpy.env.workspace, ds, fc)
        print(path)
arcpy.SetParameterAsText(3, outputFile1)

 

0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor

Hi @Davec43, can you elaborate on what you are trying to do when you want to pull the layers out of the geodatabase?  Are you looking to perform further processing on these feature classes?

0 Kudos
Davec43
Occasional Contributor

Further processing mainly adjusting symbology, grouping (of the two split layers points/lines) and packaging.

0 Kudos