Reputation: 1
I can't get the kriging to work in a arcgis pro custom script. the code works but the kriging raster is not added to the layout when the custom script is run. Not sure what I am doing wrong, Below is my script. The script runs in Python 3. It also runs in ArcGIS Pro but it does not add the raster to the layout.
import arcpy
import pandas as pd
import sys
import os
# Get input files
ems_call_data_xls = sys.argv[1] # Path to the .xls file
county_boundary = sys.argv[2] # County boundary layer
project_name = sys.argv[3] # Required argument for the ArcGIS Pro project
# Check if XLS file exists
if not os.path.isfile(ems_call_data_xls):
sys.exit(f"File not found: {ems_call_data_xls}")
# Check if county boundary layer exists
if not arcpy.Exists(county_boundary):
sys.exit(f"County boundary not found: {county_boundary}")
# Open ArcGIS Pro project file
try:
aprx = arcpy.mp.ArcGISProject(project_name)
print(f"Opened project: {project_name}")
except Exception as e:
sys.exit(f"Error opening project: {e}")
# Set workspace output directory for feature class and raster
output_directory = r"C:\GIS_540\Project\DataFiles"
arcpy.env.workspace = output_directory
# Read the Excel file and filter for Delta and Echo
data = pd.read_excel(ems_call_data_xls)
filtered_data = data[data["MedicalPriorityLevel"].isin(["Delta", "Echo"])]
# Check for required columns in data
if 'geox' not in filtered_data.columns or 'geoy' not in filtered_data.columns or 'time_minutes' not in filtered_data.columns:
sys.exit("Filtered data must include 'geox', 'geoy', and 'time_minutes' columns.")
# Print the filtered data for verification
print(f"Number of records after filtering: {len(filtered_data)}")
print(filtered_data.columns)
print(filtered_data.head()) # Display the first few rows
# Define the name for the output feature class
output_fc_name = "medical_priority_points"
output_fc = os.path.join(output_directory, output_fc_name)
# Get the spatial reference of the county boundary
spatial_ref = arcpy.Describe(county_boundary).spatialReference
# Create a point feature class from the filtered data using the spatial reference of the county boundary
arcpy.management.CreateFeatureclass(arcpy.env.workspace, output_fc_name, "POINT", spatial_reference=spatial_ref)
# Add necessary fields to the feature class
arcpy.management.AddField(output_fc, "MedPrio", "TEXT")
arcpy.management.AddField(output_fc, "TimeMin", "DOUBLE")
# Insert points into the feature class
with arcpy.da.InsertCursor(output_fc, ['SHAPE@XY', 'MedPrio', 'TimeMin']) as cursor:
for _, row in filtered_data.iterrows():
cursor.insertRow([(row['geox'], row['geoy']), row['MedicalPriorityLevel'], row['time_minutes']])
print(f"Inserted row: {row['geox'], row['geoy'], row['MedicalPriorityLevel'], row['time_minutes']}")
# Check the number of records inserted
rows = arcpy.management
# Use the following arguments C:\GIS_540\Project\DataFiles\EMS_2QTR2023.xls C:\GIS_540\Project\DataFiles\county_bnd\county_bnd.shp C:\GIS_540\Project\DataFiles\MyProject1.aprx
I was expecting the raster to be added to the project layout but it just says that the geoprocessing ran successful.
Upvotes: 0
Views: 17