Я не могу заставить кригинг работать в пользовательском скрипте arcgis pro. код работает, но растр кригинга не добавляется в макет при запуске пользовательского сценария. Не знаю, что я делаю неправильно. Ниже приведен мой сценарий. Скрипт работает на Python 3. Он также работает в ArcGIS Pro, но не добавляет растр в макет.
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 arguements 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
Я ожидал, что растр будет добавлен в макет проекта, но там просто написано, что геообработка прошла успешно.
Я не могу заставить кригинг работать в пользовательском скрипте arcgis pro. код работает, но растр кригинга не добавляется в макет при запуске пользовательского сценария. Не знаю, что я делаю неправильно. Ниже приведен мой сценарий. Скрипт работает на Python 3. Он также работает в ArcGIS Pro, но не добавляет растр в макет. [code]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 arguements 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 [/code] Я ожидал, что растр будет добавлен в макет проекта, но там просто написано, что геообработка прошла успешно.