1
我在嘗試使用Python提取shapefile表中每年不爲零的最小值時遇到問題。我的表格有「工作站ID」,「經度」,「緯度」和年份字段,其中F是第一個字母。例如:F1970,F1971,F1972 ...我打算循環遍歷每年的字段,然後將每年的所有值從最小值排序到最大值,然後得到第一條記錄不等於零,因爲我只想要值大於零。到目前爲止,我只能得到第一個記錄,即零。任何人都可以告訴我如何修改代碼,並獲得第一個最小值不爲零?非常感謝![我想獲得站點ID,經度和緯度與每年的最小值對應]Python - 如何獲得shapefile表中每年字段中不爲零的最小值?
# Obtain the list of all fields in the attribute table of the shapefile "Station"
fields=arcpy.ListFields(Station)
# Construct a for loop to iterate through all the year attribute in the input feature class,in order to find the record with the minimum value in each year.
for field in fields:
year=str(field.name)
# find the year field
if ("F" in year):
where=year+" ASCENDING"
# Process: Sort
arcpy.Sort_management(Station, outputFC, where, "UR")
rows = arcpy.SearchCursor(outputFC)
row=rows.next
for row in rows:
# only got me the first record in each year, which is zero.
value=row.getValue(year)
stationID= row.getValue("Station_ID")
obsLon= row.getValue("Longitude")
obsLat=row.getValue("Latitude")
row=rows.next()
break
del row,rows