- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 41198 个
- 通用积分
- 2.6173
- 学术水平
- 7 点
- 热心指数
- 5 点
- 信用等级
- 5 点
- 经验
- 2201 点
- 帖子
- 198
- 精华
- 1
- 在线时间
- 36 小时
- 注册时间
- 2015-6-1
- 最后登录
- 2024-3-3
|
- # -*- coding: utf-8 -*-
- # ---------------------------------------------------------------------------
- # Chapter2Model1.py
- # Created on: 2017-01-26 04:26:31.00000
- # (generated by ArcGIS/ModelBuilder)
- # Description:
- # ---------------------------------------------------------------------------
- #Import libraries
- import arcpy
- import csv
- # if uncommented, the next line allows for overwriting existing files with output. Be careful!
- arcpy.env.overwriteOutput = True
- # Local variables:
- Bus_Stops = r"C:\Projects\SanFrancisco.gdb\SanFrancisco\Bus_Stops"
- CensusBlocks2010 = r"C:\Projects\SanFrancisco.gdb\SanFrancisco\CensusBlocks2010"
- Inbound71 = r"C:\Projects\SanFrancisco.gdb\Chapter2Results\Inbound71"
- Inbound71_400ft_buffer = r"C:\Projects\SanFrancisco.gdb\Chapter2Results\Inbound71_400ft_buffer"
- Intersect71Census = r"C:\Projects\SanFrancisco.gdb\Chapter2Results\Intersect71Census"
- # Process: Select
- arcpy.Select_analysis(Bus_Stops,
- Inbound71,
- "NAME = '71 IB' AND BUS_SIGNAG = 'Ferry Plaza'")
-
- # Process: Buffer
- arcpy.Buffer_analysis(Inbound71,
- Inbound71_400ft_buffer,
- "400 Feet", "FULL", "ROUND", "NONE", "")
-
- # Process: Intersect
- arcpy.Intersect_analysis([Inbound71_400ft_buffer,CensusBlocks2010],
- Intersect71Census, "ALL", "", "INPUT")
- # Organize the census block population using a dictionary
- # The stop ID is the key and the census block populations are added to a list as the value
- dataDictionary = {}
- with arcpy.da.SearchCursor(Intersect71Census, ["STOPID","POP10"]) as cursor:
- for row in cursor:
- busStopID = row[0]
- pop10 = row[1]
- if busStopID not in dataDictionary.keys():
- dataDictionary[busStopID] = [pop10]
- else:
- dataDictionary[busStopID].append(pop10)
- #Create an output CSV spreadsheet. Check the folder path to be sure it's legal
- with open(r'C:\Projects\Averages.csv', 'wb') as csvfile:
- csvwriter = csv.writer(csvfile, delimiter=',')
- for busStopID in dataDictionary.keys():
- popList = dataDictionary[busStopID]
- averagePop = sum(popList)/len(popList)
- data = [busStopID, averagePop]
- csvwriter.writerow(data)
- print "Data Analysis Complete"
复制代码
|
|