🗂️ Batch Processing and Copying Feature Classes from CSV (ArcPy Script)
This Python script uses ArcPy to automate the process of copying feature classes from various spatial data sources to a geodatabase, using metadata from a CSV file. The script performs several validations, sanitizes names, checks paths, and ensures that all relevant data (e.g., fields like OriginalName, DIA_ID, DIA_Date) are added to the copied feature classes.
🔑 Key Features:
-
Sanitize Feature Class Names: Automatically removes unwanted characters from feature class names.
-
Validate Feature Class Paths: Checks if paths are accessible, not exceeding the Windows path limit, and whether the data format is supported.
-
Spatial Data Check: Ensures that only spatial data is copied (non-spatial data is skipped).
-
Add Metadata: Adds relevant metadata fields like
OriginalName,OriginalPath,DIA_ID, andDIA_Dateto the feature classes. -
Handle Errors Gracefully: Catches and logs any errors during the copy process, providing detailed messages for debugging.
🧑💻 Python Script:
🧑💻 How It Works:
-
CSV Input: The script reads metadata from a CSV file.
-
Feature Class Copying: It copies the feature classes from their input paths to output GDBs, ensuring data validity.
-
Field Management: Adds necessary fields and populates them with metadata from the CSV file.
-
Error Handling: Logs failed paths for further review.
Sample Input CSV:
Shape File Path Theme ID DIA_Date C:\Data\Environmental\Area1.shp C:\Data\Environmental\Area1.shp Environmental 1001 01/05/2020 C:\Data\Environmental\Area2.shp C:\Data\Environmental\Area2.shp Environmental 1002 03/12/2021 C:\Data\Environmental\Water.shp C:\Data\Environmental\Water.shp Water 1003 11/22/2022 C:\Data\Environmental\Soil.shp C:\Data\Environmental\Soil.shp Environmental 1004 06/14/2020 C:\Data\WaterResources\River.shp C:\Data\WaterResources\River.shp Water 1005 08/18/2021 C:\Data\WaterResources\Lake.shp C:\Data\WaterResources\Lake.shp Water 1006 09/01/2019 CSV Column Explanation:
-
Shape: The full path to the input feature class (Shapefile or other formats).
-
File Path: The location of the file on your system, which may be used as additional metadata.
-
Theme: The thematic grouping or category for the feature class (e.g., Environmental, Water, etc.).
-
ID: A unique identifier for the feature class, which could correspond to specific metadata or other cataloging information.
-
DIA_Date: The date associated with the feature class data (e.g., the date it was created, modified, or captured).
How It Relates to the Script:
-
Shape: The path to the spatial data file (Shapefile or feature class). -
File Path: Used to store the file path as metadata in the output feature classes. -
Theme: Grouped by the script into separate geodatabases for organization. -
ID: Added to the feature class as a field if present. -
DIA_Date: Added as a date field and parsed using multiple formats.✅ Conclusion:
This script automates copying spatial data to organized geodatabases, ensuring all fields and metadata are correctly updated while handling any issues gracefully.
-