Я пытаюсь прочитать данные из API CDC 500 city для интеграции в более широкий пространственный анализ.Я пишу скрипт на python, используя arcpy и пару других библиотек.
Три больших шага: 1. считывание и преобразование данных в правильный формат 2. объединение данных в шейп-файл переписного участка 3. табулирование пересечения для пересчета на уровень ZCTA
Однако есть некоторыепроблема форматирования, и он не может выполнить инструмент таблицы соединений.
Я новичок в python, но я пробовал читать данные с помощью response.read (), а также использовать библиотеку json с json.dumps () и json.loads (), но ни один из них не кажетсяделать то, что я хочу.
Вот что у меня есть сейчас:
Url="https://chronicdata.cdc.gov/resource/47z2-4wuh.csv"
Query='?PlaceName='
SelectedCity=raw_input('Enter the city of interest')
#define function to check for valid input
def hasNumbers(inputString):
return any(char.isdigit() for char in inputString)
#create if then statement to print an error if the input is not a string
#will need to change the elif statement to identify special characters
#We could just pull in all the data, convert to point shapefile and then clipped to area of interest....
if hasNumbers(SelectedCity) == False:
Request=Url+Query+SelectedCity.title()
print('You\'re API request URL:' + Request)
else:
print("That input does not match any possible city name")
#open the request defined above
response=requests.get(Request)
#read file to json
Json=json.dumps(response.content)
saveData = open("jsonOutput.json", "wt")
saveData.write(Json)
saveData.close()
censusTract=tkFileDialog.askopenfilename(parent= tkObj,title='Select City Census Tract File')
myMessage = 'Census Tract={0}'.format(censusTract)
print(myMessage)
#fieldmapping
fieldmappings = arcpy.FieldMappings()
fieldmappings.addTable(censusTract)
fieldmappings.addTable(saveData)
zipFieldIndex = fieldmappings.findFieldMapIndex('GEOID')
fieldmap = fieldmappings.getFieldMap(zipFieldIndex)
#Get the output field's properties as a field object
field = fieldmap.outputField
#Rename the field and pass the updated field object back into the field map
field.name = 'GEOID'
field.aliasName = 'GEOID'
fieldmap.outputField = field
#create input names
inlayer=censusTract
infield="GEOID"
jointable=response
joinfield="TractFIPS"
CDCshape = arcpy.AddJoin_management(inlayer,infield,jointable,joinfield)
Результатом этого должен быть шейп-файл с данными городов CDC 500 ИЛИ фрейм данных, которым можно манипулировать с пандами или другими библиотеками изатем присоединяется к шейп файлу.