Add JoinDFtoFC_2() which doesn't use arcpy.da.ExtendTable().

parent 1ac32368
......@@ -1343,6 +1343,39 @@ def JoinDFtoFC(df, in_fc, join_id, target_id=False, out_fc='', overwrite=True, f
print("Created {} from input dataframe and {} file.".format(os.path.basename(out_fc), os.path.basename(in_fc)))
return(out_fc)
def JoinDFtoFC_2(df, in_fc, join_id, target_id=False, out_fc='', overwrite=True, fill=-99999, verbose=True):
"""Join pandas dataframe to feature class."""
if not target_id:
target_id=join_id
# If out_fc specified, initialize output FC with a copy of input
if not len(out_fc):
out_fc = in_fc
else:
arcpy.FeatureClassToFeatureClass_conversion(in_fc, arcpy.env.workspace, out_fc)
if overwrite:
fwa.DeleteExtraFields(out_fc, [target_id])
# Use arcpy.da.ExtendTable() to join DF
if df.index.name in df.columns:
df.index.name = 'index'
df.index.name
# Convert DF to NP array
df_filtered = df.select_dtypes(exclude=['object'])
arr = df_filtered.fillna(fill).to_records()
colnames = list(df_filtered.columns)
# Convert NP array to Arc table
out_tbl = os.path.join(arcpy.env.scratchGDB, out_fc+'_tbl')
arcpy.Delete_management(out_tbl) # delete if already exists
arcpy.da.NumPyArrayToTable(arr, out_tbl)
# Join table from DF to the copy of the extended transects.
arcpy.JoinField_management(out_fc, target_id, out_tbl, target_id, colnames)
if verbose:
print("Created {} from input dataframe and {} file.".format(os.path.basename(out_fc), os.path.basename(in_fc)))
return(out_fc)
def DFtoFC(df, out_fc, spatial_ref, id_fld='', xy=["seg_x", "seg_y"], keep_fields=[], fill=-99999):
"""Create FC from DF; default only copies X,Y,ID fields
using too many fields with a large dataset will fail"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment