Soooo 我一直在编写从 ArcGIS Blueprints 中获取的脚本:
http://file.allitebooks.com/20151230/ArcGIS%20Blueprints.pdf
它应该将地理定位的推文转换为地理数据库。我的 Twitter Streaming API 已经可以运行了,并且一直在使用不同的方法来提取 x/y,但是每隔一段时间就会不断地回到这个脚本,希望我可以让它运行但没有运气。我陷入“列表索引超出范围”错误。如果有人足够亲切地提供一些关于如何解决这个错误的想法,我将永远感激不尽。如果没有别的,这项努力利用了我在 Python 和 Arcpy 方面的缺点,希望从长远来看它能让我变得更好。现在,我肯定想从这个脚本和我投入的工作中获得一些成果。谢谢!
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import arcpy
import sys
import time
consumer_key = 'xxx'
consumer_secret = 'xxx'
token_key = 'xxx'
token_secret = 'xxx'
class StdOutListener(StreamListener):
def __init__(self, start_time, featureClass, time_limit):
super(StdOutListener, self).__init__()
self.time = start_time
self.limit = time_limit
self.featureClass = featureClass
def on_status(self, status):
while (time.time() - self.time) < self.limit:
if status.geo is not None:
dictCoords = status.geo
listCoords = dictCoords['coordinates']
latitude = listCoords[0]
longitude = listCoords[1]
cursor =arcpy.da.InsertCursor(self.featureClass,"SHAPE@XY"))
cursor.insertRow([(longitude,latitude)])
print(str(listCoords[0]) + "," + str(listCoords[1]))
return True
else:
print "No coordinates found"
return True
start_time = time.time()
arcpy.env.workspace = "c:\ArcGIS_Blueprint_Python\data\Twitter\TweetInformation.gdb" "
def main():
try: #new
featureClass = sys.argv[1]
monitorTime = sys.argv[2]
monitorTime = monitorTime * 3600
sr = arcpy.SpatialReference(4326)
arcpy.env.overwriteOutput = True
arcpy.CreateFeatureclass_management(arcpy.env.workspace,
featureClass, "POINT", spatial_reference=sr)
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(token_key, token_secret)
stream = Stream(auth, StdOutListener(start_time, featureClass,
time_limit=monitorTime)) #172800
stream.filter(track=['car'])
except Exception as e:
print(e.message)
if __name__ == '__main__':
main()