以下是我的问题:
创建一个名为“numSchools”的函数,用于计算特定类型的学校。该函数应具有三个输入参数,(1) 工作区字符串,(2) shapefile 名称字符串,(3) 设施类型字符串(例如“HIGH SCHOOL”),以及一个输出参数, (1) shapefile 中该设施类型的学校数量的整数。
import arcpy
shapefile = "Schools.shp"
work = r"c:\Scripts\Lab 6 Data"
sTyp = "HIGH SCHOOL"
def numSchools(work, shapefile, sTyp):
whereClause = "\"FACILITY\" = 'HIGH SCHOOL' " # where clause for high schools
field = ['FACILITY']
searchCurs = arcpy.SearchCursor(shapefile, field, whereClause)
row = searchCurs.next()
for row in searchCurs:
# using getValue() to get the name of the high school
value = row.getValue("NAME")
high_schools = [row[0] for row in arcpy.SearchCursor(shapefile, field, whereClause)]
count = arcpy.GetCount_management(high_schools)
return count
numSchools(work, shapefile, sTyp)
print ("There are a total of: "),count
所以这是我运行完美的代码,但它是通过脚本完成的。我需要把它包装成一个python函数。(我的弱点)。我的代码的最后一行似乎有一些问题。`
我不太确定如何格式化最后一行代码以阅读(共有 29 所高中),同时包含必要的参数。