osm⽂件的读取、转换及处理
osm⽂件的读取、转换及处理
三相异步电动机的基本结构本代码是对openstreetmap 中武汉市地图的osm⽂件进⾏处理,将node进⾏提取并转换为json⽂件,然后读取经纬度,寻重复的node。
import os
运算符优先级别排序c语言import json
from lxml import etree
import xmltodict
os.chdir('your filepath')
osmfile = 'wuhan.osm'
def iter_element(file_parsed, file_length, file_write):
数据结构课程设计作品current_line = 0
try:
for event, element in file_parsed:
current_line += 1
print (current_line/float(file_length))
elem_data = string(element)
elem_dict = xmltodict.parse(elem_data, attr_prefix="", cdata_key="") if (element.tag == "node"):
elem_jsonStr = json.dumps(elem_dict["node"])
file_write.write(elem_jsonStr + "\n")
# 每次读取之后进⾏⼀次清空
element.clear()
previous() is not None:
parent()[0]
except:
pass
file_length = -1
for file_length, line in enumerate(open(osmfile, 'rU',encoding = 'utf-8')):
pass
file_length += 1
花店网站设计模板print( "length of the file:\t" + str(file_length))
file_node = open(osmfile+"_node.json","w+")
file_parsed = etree.iterparse(osmfile, tag=["node"])
iter_element(file_parsed, file_length, file_node)
file_node.close()
osm_json_file = 'D:\\360Downloads\\wuhan.osm_node.json'
list1 = []
with open(osm_json_file,encoding = 'utf-8') as f:python解析json文件
for data in f:
tulist = []
data= json.loads(data)
lat = float(data['lat'])
tulist.append(lat)
lon = float(data['lon'])
tulist.append(lon)
登录入口网址list1.append(tuple(tulist))
source = list1
from collections import defaultdict
from collections import Counter
Counter(list1)
i = 0
for k,v in Counter(list1).items():
if v == 2:
i += 1
print(k,v)
print(i)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论