python高德 查询县_Python获取高德地图POI

# -*- encoding: utf-8 -*-

# coding:utf-8

from xlwt import Workbook

from tempfile import TemporaryFile

import urllib.request

import xml.dom.minidom as minidom

import xlwt

#结果目录

inforst = '/home/yuhz/PycharmProjects/untitled2/POI/'

file_name = 'result.txt' # write result to this file

#keyword = 'XXX' urllib.parse.quote(keyword)

url_amap = 'http://restapi.amap.com/v3/place/text?&keywords=&types=010800&city=370600&citylimit=true&&output=xml&offset=20&page=1&key=&extensions=base'

#facility_type = r'types=170300' # factory facilities

#region = r'city=120113' # beichen of tianjin

each_page_rec = 20 # results that displays in one page

which_pach = r'page=1' # display which page

xml_file = 'tmp.xml' # xml filen name

#写入Excel(定义Excel表头)

book = Workbook()

sheet1 = book.add_sheet('Sheet 1')

row1 = sheet1.row(0)

row1.write(0,'CORPNAME')

row1.write(1,'ADDRESS')

row1.write(2,'TEL')

row1.write(3,'pname')

row1.write(4,'cityname')

row1.write(5,'adname')

row1.write(6,'location')

sheet1.col(0).width = 10000

sheet1.col(1).width = 10000

sheet1.col(2).width = 10000

sheet1.col(3).width = 5000

sheet1.col(4).width = 5000

sheet1.col(5).width = 5000

sheet1.col(6).width = 5000

#自动换行

style = xlwt.easyxf('align: wrap on')

# get html by url and save the data to xml file

def getHtml(url):

page = urllib.request.urlopen(url)

html = page.read()

try:

# open xml file and save data to it

with open(xml_file, 'wb') as xml_file_handle:

xml_file_handle.write(html)

except IOError as err:

print("IO error: " + str(err))

return -1

return 0

# phrase data from xml

def parseXML(index):

total_rec = 1 # record number

# open xml file and get data record

try:

with open(file_name, 'a') as file_handle:

dom = minidom.parse(xml_file)

root = dom.getElementsByTagName("response") # The function getElementsByTagName returns NodeList.

for node in root:

total_rec = node.getElementsByTagName("count")[0].childNodes[0].nodeValue

pois = node.getElementsByTagName("pois")

for poi in pois[0].getElementsByTagName('poi'):

name = poi.getElementsByTagName("name")[0].childNodes[0].nodeValue

try:

address = poi.getElementsByTagName("address")[0].childNodes[0].nodeValue

except IndexError:

address = ""

try:

tel = poi.getElementsByTagName("tel")[0].childNodes[0].nodeValue

except IndexError:

tel = ""

try:

pname = poi.getElementsByTagName("pname")[0].childNodes[0].nodeValue

except IndexError:

pname = ""

try:

cityname = poi.getElementsByTagName("cityname")[0].childNodes[0].nodeValue

except IndexError:

cityname = ""

try:

adname = poi.getElementsByTagName("adname")[0].childNodes[0].nodeValue

except IndexError:

adname = ""

location = poi.getElementsByTagName("location")[0].childNodes[0].nodeValue

#写入Excel

index = index + 1

row1 = sheet1.row(index)

row1.write(0, name, style)

row1.write(1, address, style)

row1.write(2, tel, style)

row1.write(3, pname, style)

row1.write(4, cityname, style)

row1.write(5, adname, style)

row1.write(6, location, style)

except IOError as err:

print

"IO error: " + str(err)

return total_rec

if __name__ == '__main__':

index = 0

if getHtml(url_amap) == 0:

print

'parsing page 1 ... ...'

# parse the xml file and get the total record number

total_record_str = parseXML(index)

total_record = int(total_record_str)

if (total_record % each_page_rec) != 0:

page_number = total_record / each_page_rec + 2

else:

page_number = total_record / each_page_rec + 1

# retrive the other records

for each_page in range(2, int(page_number)):

index = index + 20

print('parsing page ' + str(each_page) + ' ... ...')

url_amap = url_amap.replace('page=' + str(each_page - 1), 'page=' + str(each_page))

getHtml(url_amap)

total_record_str = parseXML(index)

total_record = int(total_record_str)

if total_record == 0:

break

else:

print

'error: fail to get xml from amap'

# 保存Excel

book.save(inforst + 'result.xls')

book.save(TemporaryFile())

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 高德POI是指高德地图的兴趣点(Points of Interest,POI)数据。Python是一种广泛使用的编程语言。那么,Python如何与高德POI数据进行交互呢? 首先,我们可以使用Python的requests库向高德POI接口发送HTTP请求,以获取POI数据。我们需要使用高德的开发者密钥,将其作为参数添加到请求中。通过设置请求的经纬度、半径、关键词等参数,可以获取特定区域、特定类型的POI数据。 接着,我们可以使用Python的json库对返回的JSON格式数据进行解析和处理。通过解析,我们可以获取POI的名称、地址、经纬度、电话等相关信息,并根据需要进行进一步的处理和分析。 在获取POI数据后,我们可以将其展示在地图上,借助Python的地图可视化库(如folium)实现。通过将POI的经纬度坐标添加到地图上,可以方便地查看POI分布情况,并进行可视化分析。 此外,我们还可以使用Python的机器学习和数据挖掘库对POI数据进行分析。例如,可以使用聚类算法对POI进行聚类分析,找出具有相似特征的POI群组。或者,可以使用文本挖掘技术对POI的描述文本进行情感分析,了解用户对POI的评价情况。 总之,Python提供了丰富的工具和库,可以方便地获取、解析和分析高德POI数据。通过Python的强大功能,我们可以更好地利用和分析POI数据,以满足不同领域的需求,如地理信息分析、城市规划等。 ### 回答2: Python 高德POI是一个基于Python编程语言的高德地图兴趣点服务接口。POI即兴趣点(Points of Interest),是指地图上的特定地点,例如餐馆、商场、景点等。 使用Python高德POI,我们可以通过调用相应的接口获得特定位置周边的兴趣点信息。首先,我们需要在高德地图开放平台上获取API密钥,然后使用Python的HTTP库发送HTTP请求到高德POI的接口地址,将API密钥和其他参数一起传递给接口。接口会返回一个JSON格式的响应,其中包含了周边兴趣点的相关信息,如名称、地址、经纬度等。 在Python中使用高德POI可以实现很多功能,比如查找指定位置附近的餐馆,或者根据用户输入的关键词搜索特定类型的兴趣点。我们可以根据返回的兴趣点信息,对其进行处理和分析,比如绘制地图、计算距离等。 Python高德POI的使用非常灵活,我们可以根据自己的需求定制特定的功能。此外,高德POI也提供了批量操作接口,允许我们一次性获取多个位置周围的兴趣点信息,方便进行大规模的数据处理和分析。 总而言之,Python高德POI是一个强大的工具,能够帮助我们在Python环境中轻松实现与高德地图相关的兴趣点服务。无论是进行实时地理位置数据处理,还是进行地理信息系统开发,Python高德POI都能够提供便捷而高效的解决方案。 ### 回答3: Python高德POI是一个用于访问和使用高德地图Python库。POI代表兴趣点(Point of Interest),它是指地图上的特定位置或区域,如酒店、餐厅、景点等。 使用Python高德POI,我们可以通过API获取各种POI的详细信息。首先,我们需要在高德地图开发者平台上申请一个API密钥。然后,我们可以使用该密钥访问高德地图的API。 要使用Python高德POI,我们首先需要安装它的库文件。可以使用pip命令在命令行中运行"pip install amap"来安装。安装好之后,我们可以在Python脚本中导入amap模块,然后使用其中的函数和类进行地图操作。 例如,我们可以使用amap的search函数在指定的城市中搜索特定类型的POI。我们可以指定查询关键词和城市名称,并设置一些可选参数,如搜索半径、搜索结果数量等。执行查询后,我们可以获取到符合条件的POI的信息,如名称、地址、坐标等。 除了搜索,Python高德POI还提供了其他功能,如地点周边搜索、路径规划等。我们可以使用amap的相关函数来实现这些操作,以满足不同的需求。 总的来说,Python高德POI是一个强大的工具,可以帮助我们在Python中方便地访问和使用高德地图POI数据。无论是开发地图导航应用程序,还是进行地理位置分析,都可以使用Python高德POI来简化我们的工作,并提供丰富的地图数据支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值