Create Feature Class using Field name and Alias from File

536
2
08-15-2024 10:36 AM
Labels (1)
Paul_Duffy_Waters_of_LIFE
Occasional Contributor

Hi, 

I want to create a feature class from a file.

I want to be able to specify the field name and associated Alias based on the contents of the attached file.

Each new field is an Integer Type, with the field name to come from the cdLpaCode column and the associated alias from the indAlias column.

Is there a way of doing this in Python or Model Builder? I need to repeat the process for around a hundred files.

Thanks,

Paul

0 Kudos
2 Replies
DavidSolari
MVP Regular Contributor

Here's a simple implementation that spits out a point feature class in Web Mercator and nullable long integer fields, should be easy to alter this to suit your needs

 

from os import path
def workbook_to_fc(file_path: str, fc_path: str):
    excel = arcpy.conversion.ExcelToTable(file_path, "memory\\fields")[0]
    arcpy.management.CreateFeatureclass(*path.split(fc_path), "POINT", spatial_reference=arcpy.SpatialReference(3857))
    fields = [[name, "LONG", alias, None, None, None] for _, name, alias in arcpy.da.SearchCursor(excel, "*")]
    arcpy.management.AddFields(fc_path, fields)

 

0 Kudos
Paul_Duffy_Waters_of_LIFE
Occasional Contributor

Hi David,

Thanks for that. Unfortuntately I haven't a great deal of experience with Python yet!

If you have the time could you please indicate which elements I would need to modify?

Thanks,

Paul

0 Kudos