尧图网络 高端网站定制 · 原创设计
免费咨询热线
400-888-6620
免费获取方案
Python3实例分享_经纬度转换为地区和地址
Python3实例分享_经纬度转换为地区和地址说明创建一个csv文件源代码说明创建一个逗号分隔的CSV格式的文件命名为address.csv填写经纬度信息执行代码结果保存在dis.csv创建一个csv文件address.csvLongitudeLatitude120.1076835.91555120.3623136.13871119.7917335.58356…………源代码importcsvimporttimeimportosimportrequests## 判断字符串是否是小数defDataCheck():starttimetime.time()i0print(数据检查中)print()withopen(address.csv)asf:readercsv.reader(f)next(f)forrowinreader:longirow[0]latirow[1]if(longi.split(.)[0]).isdigit()and(lati.split(.)[0]).isdigit():Noneelse:print(reader.line_num1,行中的(,longi,)(,lati,)格式检查不通过请修改后再试)ii1print()print(总计,reader.line_num1,行)ifi0:print(检查完成未发现错误)else:print(检查完成发现错误,i,个)endtimetime.time()print(用时,round(endtime-starttime,2),秒)os.system(pause)## 纠偏## https://lbs.amap.com/api/webservice/guide/api/convert API链接defrecorrect(locationX):#纠偏API函数parameters{locations:locationX,key:your-key,coordsys:gps}base_urlhttps://restapi.amap.com/v3/assistant/coordinate/convertresponserequests.get(urlbase_url,paramsparameters)info_newGPSresponse.json()returninfo_newGPS[locations]defsplit(lst):#数据按照二十个一组进行处理new_lst[]new[lst[i:i20]foriinrange(0,len(lst),20)]i0foriinrange(len(new)):# print(提取中: {:.0f}%.format(i / len(new) * 100))a|.join(str(m)forminnew[i])new_lst.append(a)print(CSV文件读取完成: 100%)returnnew_lstdefDealData(lst):#分列后进行处理查询new_lstsplit(lst)print(每 20 个站点查询并转换一次一共需要查询,len(new_lst),次预计需要,int(len(new_lst)),秒)result_list[]new_result_combine[]foriinrange(len(new_lst)):print(第,i1,次查询中...)block1new_lst[i]# print(检查,block1)resultrecorrect(block1)# print(纠偏经纬度为,result)result_list.append(result)#print(最终结果为,result_list)new_result_combinezip(result_list)# print(new_result_combine)new_result_listlist(new_result_combine)# print(转换结果,new_result_list)returnnew_result_listdefRecorrectV4():starttimetime.time()print(高德坐标转换)print()lst[]withopen(address.csv)asf:readercsv.reader(f)next(f)forrowinreader:longirow[0]latirow[1]locationlongi,lati lst.append(location)new_result_listDealData(lst)withopen(newGPS.csv,w,newline)asf:writercsv.writer(f)writer.writerows(new_result_list)endtimetime.time()print(查询完成)print(用时,round(endtime-starttime,2),秒)print(纠偏成高德坐标系结果已经保存到newGPS.csv)print()os.system(pause)##获取地址deflo_to_addr(location):#经纬度转地址parameters{location:location,key:your-key,batch:true}base_urlhttps://restapi.amap.com/v3/geocode/regeoresponserequests.get(urlbase_url,paramsparameters)info_siteresponse.json()# 地区路径info_site[regeocode][addressComponent][district]# 地址路径info_site[formatted_address]returninfo_site[regeocodes]defGetAddV4():starttimetime.time()print(从高德API获取地区中...)withopen(newGPS.csv)asf:readercsv.reader(f)# for row in reader:# # 行号从1开始# print(reader.line_num, row)dis_from_location_list[]address_from_location_list[]longi_list[]lati_list[]location_list[]forrowinreader:locationrow[0]# print(location)locationlocation.replace(;,|)resultlo_to_addr(location)fornuminrange(0,20):try:DataPartresult[num]exceptIndexError:breakaddreDataPart[formatted_address]disDataPart[addressComponent][district]# print(检查:,DataPart)# print(地址:,addre)# print(地区:, dis)address_from_location_list.append(addre)dis_from_location_list.append(dis)# print(address_from_location_list)# print(dis_from_location_list)dis_from_location_list.insert(0,地区)address_from_location_list.insert(0,地址)result_combinezip(dis_from_location_list,address_from_location_list)result_listlist(result_combine)print()print(输出结果\n,result_list)print()withopen(dis.csv,w,newline)asf:writercsv.writer(f)writer.writerows(result_list)endtimetime.time()print(用时,round(endtime-starttime,2),秒)print(结果已经保存到dis.csv)print()os.system(pause)#主程序入口if__name____main__:DataCheck()RecorrectV4()GetAddV4()使用高德“逆地理编码API”从经纬度反推地区每日调用上限为6000次API链接https://lbs.amap.com/api/webservice/guide/api/georegeo/
RELATED

相关推荐

国家中小学智慧教育平台电子课本下载工具:三步获取PDF教材的实用方法

国家中小学智慧教育平台电子课本下载工具:三步获取PDF教材的实用方法

国家中小学智慧教育平台电子课本下载工具:三步获取PDF教材的实用方法 【免费下载链接】tchMaterial-parser 国家中小学智慧教育平台 电子课本下载工具,帮助您从智慧教育平台中获取电子课本的 PDF 文件网址并进行下载,让您更方便地获取课本内容…

📅 2026/11/24 13:33:03
企业级JVM智能代理框架深度解析:Embabel Agent如何重构AI应用开发范式

企业级JVM智能代理框架深度解析:Embabel Agent如何重构AI应用开发范式

企业级JVM智能代理框架深度解析:Embabel Agent如何重构AI应用开发范式 【免费下载链接】embabel-agent Agent framework for the JVM. Pronounced Em-BAY-bel /ɛmˈbeɪbəl/ 项目地址: https://gitcode.com/gh_mirrors/em/embabel-agent Embabel Agent是由…

📅 2026/11/24 10:38:18
python中的字典

python中的字典

创建字典定义用{ } 或者dict(),元素用,号隔开字典是无序的(有序还是无序要看是否有索引)1. 字典的定义 student01 {"name": "小王", "age": 18, "gender": "男", "heigh…

📅 2026/11/12 3:37:39
MORE NEWS

更多资讯

📰

福建考电工证哪里报名,含金量真的高吗?

福建考电工证哪里报名,含金量真的高吗? 你是不是也在纠结, 福建考电工证哪里报名 ?网上一搜一堆信息,但又怕被中介坑?别急,我来帮你理清楚,从报名到考证,再到证书含金量,一文说透,别再踩坑。 为什么福建考电工证要慎重选择报名渠道?…

📰

石家庄市电工证报考良心建议:学历不高也能报上名,关键看这几点

石家庄市电工证报考良心建议:学历不高也能报上名,关键看这几点 你是不是也担心学历不高,石家庄市电工证报考会卡在报名门槛上?别急,我来给你讲讲真相。其实, 石家庄市电工证报考…

📰

工地太忙根本没时间复习考试?电工证在国网考的干货全在这儿

工地太忙根本没时间复习考试?电工证在国网考的干货全在这儿 工地太忙根本没时间复习考试,但电工证在国网考的含金量又不能忽视。很多人因为工作强度大、时间紧张,往往忽略了证书的复审和考试准备,结果到了关键时刻才发现证书过期或者考试不过,耽误了项目…

📰

学机电需要电工证吗?官方报名入口在哪?

学机电需要电工证吗?官方报名入口在哪? 你是不是也遇到过这样的情况:想从事机电相关工作,但不知道是否需要电工证?报名时被各种培训机构忽悠,生怕被坑?别担心,这篇内容就是为你量身定制的,从报名到考试,从备考到证书管理,全干货,一网打尽,带你一…

📰

电工证科四考试多久拿证?别再被中介骗了,手把手教你避坑

电工证科四考试多久拿证?别再被中介骗了,手把手教你避坑 不知道去哪报名怕被中介坑?现在电工证科四考试越来越多,但很多人不知道怎么报名,怕花冤枉钱还拿不到证。特别是安阳的建筑工人,想要考电工证科四考试,首先得知道多久拿证、怎么报名、流程是啥,…

📰

深圳电工证外观最新政策解读:内部消息透露外省证如何转过来

深圳电工证外观最新政策解读:内部消息透露外省证如何转过来 之前考的证在外省能不能转过来?这几乎是所有在外地打工的特种作业人员最关心的问题。特别是像你在安阳从事房建工程的电工,手里拿着外省的电工证,担心在深圳工作时会不会“白搭”。而最近内部消…

TODAY

今日更新

THIS WEEK

本周精选

THIS MONTH

本月热门

读完文章,想聊聊您的网站?

告诉我们您的行业与需求,资深顾问一对一梳理方案与报价,全程免费。

📞 💬