My script tool works within ArcGIS Pro but I receive an SyntaxError:invalid syntax when trying to use my GP Service within WebApp Builder. It's a simple tool and I don't know what the problem is. Any feedback would be appreciated. Cheers
#-------------------------------------------------------------------------------
# Name: BufferSummarize.py
# Purpose: Park, Farmers Market Buffer analysis utilizing Summarize Within
# analysis to display Raw indicator values
#
# Author:
#
# Created:
# Copyright:
# Licence:
#-------------------------------------------------------------------------------
import arcpy
def BufferSummarize(Select_Input_Feature="FarmersMarkets", Select_County_Feature="Franklin", Enter_Distance_value_or_field="2 Miles", Output_Buffer_Feature="C:\\Project\\ArcGIS_Pro\\Project.gdb\\FeatureBuffer", Select_Year="Year2010", Select_Domain="Social and Economic",Domain_Summary_Output_Feature="C:\\Project\\ArcGIS_Pro\\Project.gdb\\DomainSummary"): # BufferSummarize
# To allow overwriting outputs change overwriteOutput option to True.
arcpy.env.overwriteOutput = True
# Process: Select Layer By Location (Select Layer By Location) (management)
Output_Feature_and_County_Selection_Feature = arcpy.management.SelectLayerByLocation(in_layer=Select_Input_Feature, overlap_type="INTERSECT", select_features=Select_County_Feature, selection_type="NEW_SELECTION", invert_spatial_relationship="NOT_INVERT")
# Process: Buffer (Buffer) (analysis)
arcpy.analysis.Buffer(in_features=Output_Feature_and_County_Selection_Feature, out_feature_class=Output_Buffer_Feature, buffer_distance_or_field=Enter_Distance_value_or_field, line_side="FULL", line_end_type="ROUND", dissolve_option="NONE", method="PLANAR")
# Conditional if statement for Domain Selection summary fields
if Select_Domain == 'Education':
Summary_Fields = [["ED_APENR", "MEAN"], ["ED_ATTAIN", "MEAN"], ["ED_COLLEGE", "MEAN"], ["ED_ECENROL", "MEAN"], ["ED_HSGRAD", "MEAN"], ["ED_MATH", "MEAN"], ["ED_READING", "MEAN"], ["ED_SCHPOV", "MEAN"], ["ED_TEACHXP", "MEAN"], ["ED_PRXECE", "MEAN"], ["ED_PRXHQECE", "MEAN"]]
elif Select_Domain == 'Health and Environment':
Summary_Fields = [['HE_FOOD', 'MEAN'], ['HE_GREEN', 'MEAN'], ['HE_HEAT', 'MEAN'], ['HE_HLTHINS', 'MEAN'], ['HE_OZONE', 'MEAN'], ['HE_PM25', 'MEAN'], ['HE_VACANCY', 'MEAN'], ['HE_WALK', 'MEAN'], ['HE_SUPRFND', 'MEAN'], ['HE_RSEI', 'MEAN']]
elif Select_Domain == 'Social and Economic':
Summary_Fields = [['SE_POVRATE', 'MEAN'], ['SE_PUBLIC', 'MEAN'], ['SE_HOME', 'MEAN'], ['SE_OCC', 'MEAN'], ['SE_MHE', 'MEAN'], ['SE_EMPRAT', 'MEAN'], ['SE_JOBPROX', 'MEAN'], ['SE_SINGLE', 'MEAN']]
elif Select_Domain == 'Population':
Summary_Fields = [['aian', 'SUM'], ['api', 'SUM'], ['black', 'SUM'], ['hisp', 'SUM'], ['other2', 'SUM'], ['nonwhite', 'SUM'], ['white', 'SUM'], ['total', 'SUM']]
# Process: Summarize Within Domain (Summarize Within) (analysis)
Output_Grouped_Table_1_ = ""
arcpy.analysis.SummarizeWithin(in_polygons=Output_Buffer_Feature, in_sum_features=Select_Year, out_feature_class=Domain_Summary_Output_Feature, keep_all_polygons="ONLY_INTERSECTING", sum_fields=Summary_Fields, sum_shape="NO_SHAPE_SUM", shape_unit="SQUAREKILOMETERS", group_field="", add_min_maj="NO_MIN_MAJ", add_group_percent="NO_PERCENT", out_group_table=Output_Grouped_Table_1_)
if __name__ == '__main__':
# Global Environment settings
with arcpy.EnvManager(workspace=r"C:\Project\ArcGIS_Pro\Project.gdb"):
Select_Input_Feature = arcpy.GetParameter(0)
Select_County_Feature = arcpy.GetParameter(1)
Enter_Distance_value_or_field = arcpy.GetParameterAsText(2)
Output_Buffer_Feature = arcpy.GetParameterAsText(3)
Select_Year = arcpy.GetParameter(4)
Select_Domain = arcpy.GetParameterAsText(5)
Domain_Summary_Output_Feature = arcpy.GetParameterAsText(6)
BufferSummarize(Select_Input_Feature,Select_County_Feature,Enter_Distance_value_or_field,Output_Buffer_Feature,Select_Year,Select_Domain,Domain_Summary_Output_Feature)
Hey James,
From the code block you pasted; it looks like you are using the code from a tool inside a toolbox that runs locally. Once you run that and share it as a geoprocessing service, that code gets copied over to the GIS server you chose to host it on. During that process, the code gets changed to run in the Enterprise environment instead of the ArcGIS Pro environment. One of the things that happens when you do that is that any hard coded file paths get converted and I think that is where the issue is occurring with your tool.
You can fix this in a multitude of ways, but the one that is probably the best is to refactor your code to use the scratch gdb as an environment instead of pathing directly to the gdb on your C drive.
Here is a link to some documentation on the scratch gdb: Scratch GDB (Environment setting)—ArcGIS Pro | Documentation