1.从pyecharts(数据可视化)的库中,导入Geo (地理坐标系组件)用于地图的绘制,map 函数 地图主要用于(地理区域数据)的可视化。
from pyecharts import Geo,Map
难点:需要对库的模块进行安装
2.根据已有的资料,读取csv文件。将其中的内容标题进行索引,根据用户自主选择内容来进行查询。
难点:①根据自己所需要的目录进行提取;②如何根据用户的需求来进行选取
# _*_ coding: utf-8 _*_
# @Author : 师太丶借ge吻
# @Time : 2019/6/2414:57
# @File : new_igs_station_v2.0.py.py
# @Software: PyCharm
"""
1.将程序放入到函数中
2.根据客户的更多需求来满足,输入序号后输入格式错误
3.没有实现汉英之间的相互转换
4.按照地区来进行划分
5.创建成函数
6.做成循环的,可以随时退出
7.想查单个的(①找出所有的可能性,全部列出,可能性太多了
②将填写的做成列表或字典,进行对比)
"""
import csv # 导入模块csv
import json # 导入模块json
import re
from pyecharts import Geo,Map # 从pyecharts库中,导入Geo和Map模块
files_dictionary = {} # 创建一个空的文件字典
attitude_datas = [] # 创建一个总的海拔数据的空列表
coordinate_datas = {} # 创建一个总的坐标数据的空字典
"""打开文件,挑选出自己需要的数据"""
number = 0 # 起算数据
filename = 'IGS_CSV.csv'
with open(filename) as fp: # 打开文件,并将结果文件对象存储在fp中
reader = csv.reader(fp) # 调用csv.reader(),并将存储的文件对象作为实参传递给它,创建一个与该文件相关联的阅读器
attitude_data = () # 创建一个海拔数据元祖
for x in reader: # for循环遍历该文件
if number == 0: # 当起算数据为0时
heard_row = x # 表头
else: # 当起算数据不为0时
site_information = {} # 需要的位置信息创建一个空字典
site_information[heard_row[0]] = x[0]
site_information[heard_row[1]] = x[1]
site_information[heard_row[4]] = x[4]
site_information[heard_row[5]] = x[5]
site_information[heard_row[8]] = x[8]
site_information[heard_row[9]] = x[9]
site_information[heard_row[10]] = x[10]
site_information[heard_row[20]] = x[20]
files_dictionary[number] = site_information # 有序号的位置信息加入到空的总数据字典
site_altitude = (x[0],) + (x[10],) # 海拔信息
attitude_datas.append(site_altitude) # 将海拔信息添加到空的总海拔列表
lat_long = list((x[9],) + (x[8],)) # 坐标信息
coordinate_datas[x[0]] = lat_long # 将坐标信息添加到空的总坐标列表
number += 1
print(files_dictionary)
print(attitude_datas)
print(coordinate_datas)
for i,v in enumerate(site_information,1): # for循环按照序号顺序遍历字典中的信息
print(i,'>>>>',v)
header = list(site_information) # 提取字典的标题,组成新的列表
while True:
choice = input('请您输入序号(退出:q):')
if choice.isdigit():
choice = int(choice)
if choice > 0 and choice <= len(header)-1:
choice_finish = header[choice - 1] # 选择的序号,与标题对应提取出来
information = input('%s:'%choice_finish)
# 将客户的输入进行大小写划分
if choice_finish == 'City' or choice_finish == 'Country':
information = information.title()
else:
information = information.upper()
# 想查单个的(①将输入的提取到列表中;②列表中是否含有)
elif choice == len(header):
sat_system_choice_new_result = []
sat_system_list = ['GPS','GLO','GAL','BDS','QZSS','SBAS','IRNSS','WAAS']
for num,ber in enumerate(sat_system_list,1):
print(num,'-->',ber)
sat_system_choices = input('请输入您想选择的系统编号(多系统用加号连接,退出输入q):')
if sat_system_choices != 'q':
sat_system_choices = re.sub("\D", "", sat_system_choices) # 提取字符串中的数字
for sat_system_choice in sat_system_choices:
sat_system_choice_result = sat_system_list[int(sat_system_choice) - 1]
sat_system_choice_new_result.append(sat_system_choice_result)
#选择出了想要测量的系统
sat_system_results = "+".join(sat_system_choice_new_result)
information = sat_system_results
else:
print('对不起,您输入的序号有误!')
break
# 怎样把选择出来的字典给提取出来
site_coordinate = {}
choice_attitude_datas = []
choice_coordinate_datas = {}
for keys,values in files_dictionary.items(): # for循环遍历总文件字典中的键-值
for key,value in values.items(): # for循环遍历总文件字典中的值的键-值
print(value)
print(information)
if information in value: # if判断条件
final_choice = files_dictionary[keys]
choice_coordinate_datas[final_choice['Site']] = coordinate_datas[final_choice['Site']]
choice_attitude_datas.append(attitude_datas[keys - 1])
print(choice_attitude_datas)
print(choice_coordinate_datas)
elif choice == 'q':
print('您已退出!')
break
# 把数据保存成json格式
filename = 'choice_datas.json'
with open(filename,'w') as f_obj:
json.dump(choice_coordinate_datas,f_obj)
def map_drawing():
""""根据用户选出的数据来进行绘图"""
geo = Geo("全球IGS观测站分布", "data from www.igs.org", title_color="#fff",
title_pos="center", width=1000,
height=600,background_color='#404a59')
attr, value = geo.cast(choice_attitude_datas)
geo.add_coordinate_json("choice_datas.json")
geo.add("", attr, value, visual_range=[0, 4000], maptype='world', visual_text_color="#fff",
symbol_size=6, is_visualmap=True)
geo.render("全球IGS观测站分布.html")