当前位置:网站首页>Provincial and urban level three coordinate boundary data CSV to JSON
Provincial and urban level three coordinate boundary data CSV to JSON
2022-07-07 00:56:00 【Little shopkeeper selling sesame oil】
Sometimes when we draw the following map , Frame a city , Or the area of the county :

At this time, when coding and drawing , We need corresponding administrative districts json Format boundary coordinate set .
My last article wrote , Use python, utilize request Tools , Open from Gaode map API Obtain the longitude and latitude coordinate sets of the boundaries of various administrative regions in China .
Obtain the latitude coordinates of all administrative regions in China in batches ( To the county level )_ The blog of the little shopkeeper who sells sesame oil -CSDN Blog This article USES the python, utilize request Tools , Open from Gaode map API Obtain the longitude and latitude coordinate sets of the boundaries of various administrative regions in China . Administrative districts are most subdivided into county and district levels .https://blog.csdn.net/qq_58832911/article/details/125617715 But some areas with the same level and the same name , Will use the same boundary . This is a little bug.
This article is about , Public coordinate data set conversion is used Json Format , Implement access json Format boundary coordinate set .
csv Data sources are freely available :

You can also download my online disk :
link :https://pan.baidu.com/s/1AU7sFHoBQBtWT3lMBZAZHg
Extraction code :ucv9
csv What the data looks like :
Purpose : Convert to this format json Format

import pandas as pd
import json
import re
# read ok_geo.csv csv file
def read_csv(file_name):
df = pd.read_csv(file_name, encoding='utf-8')
# Create a national dictionary
country_dict = {"name": "China", "border": None, "area": []}
# For experiments n Control the number of cycles
n = 0
for index, row in df.iterrows():
# Determine whether it is a primary address
if row["deep"] == 0:
# Create a provincial dictionary
province_dict = {"name": None, "center": None, "border": None, "area": []}
# Assign a province dictionary
province_dict["name"] = row["name"]
# Get the provincial coordinate center
province_dict["center"] = [float(i) for i in row["geo"].split(" ")]
# print(province_dict["center"])
province_border = row["polygon"]
# Press "," Division , Then divide according to the space , Convert floating point type
province_border = [[float(i) for i in re.split(" |;", j)] for j in province_border.split(",")]
province_dict["border"] = province_border
# Add the provincial dictionary to the national dictionary area in
country_dict["area"].append(province_dict)
elif row["deep"] == 1:
# Create a city dictionary
city_dict = {"name": None, "center": None, "border": None, "countyArea": []}
# Assignment City dictionary
city_dict["name"] = row["name"]
try:
# Get the city coordinate center
city_dict["center"] = [float(i) for i in row["geo"].split(" ")]
except:
city_dict["center"] = None
# Get the city boundary
try:
city_border = row["polygon"]
# Press "," Division , Then divide according to the space , Convert floating point type
city_border = [[float(i) for i in re.split(' |;', j)] for j in city_border.split(",")]
except:
city_border = None
city_dict["border"] = city_border
# Judge which province it belongs to
belong_to_p = row["ext_path"].split(" ")[0]
# print(belong_to_p)
# Look up the province dictionary in the list of provinces in the national dictionary name Property value and belong_to_p The index of the list of dictionaries in the same province
for i, x in enumerate(country_dict["area"]):
if x["name"] == belong_to_p:
# Add city dictionary to provincial dictionary area in
p_index = i
break
# print(p_index)
country_dict["area"][p_index]["area"].append(city_dict)
else:
# Create a county dictionary
district_dict = {"name": None, "center": None, "border": None}
# Assign County dictionary
district_dict["name"] = row["name"]
# Get the county coordinate center
try:
district_dict["center"] = [float(i) for i in row["geo"].split(" ")]
except:
district_dict["center"] = []
# Get boundary coordinates
try:
district_border = row["polygon"]
# Press "," Division , Then divide according to the space , Convert floating point type
district_border = [[float(i) for i in re.split(' |;', j)] for j in district_border.split(",")]
except:
district_border = []
district_dict["border"] = district_border
# Judge which province it belongs to
belong_to_p, belong_to_c= row["ext_path"].split(" ")[0], row["ext_path"].split(" ")[1]
# print(belong_to_p)
# Look up the province dictionary in the list of provinces in the national dictionary name Property value and belong_to_p The index of the list of dictionaries in the same province
for i, x in enumerate(country_dict["area"]):
if x["name"] == belong_to_p:
# Add the county dictionary to the city dictionary countyArea in
p_index = i
break
# print(p_index)
# Judge which city it belongs to
for i, x in enumerate(country_dict["area"][p_index]["area"]):
if x["name"] == belong_to_c:
c_index = i
break
# print(c_index)
country_dict["area"][p_index]["area"][c_index]["countyArea"].append(district_dict)
# print(country_dict)
print(" The second " + str(n) + " Secondary cycle ," + " The processing address is :" + row["ext_path"])
n += 1
if n==3:
break
# print(country_dict)
# write in json file
with open('demo.json', 'w', encoding='utf-8') as f:
json.dump(country_dict, f, ensure_ascii=False)
if __name__ == "__main__":
read_csv('ok_geo.csv')
passresult :

json Download address of the file .( But I hope you can run the code by yourself )
link :https://pan.baidu.com/s/13RDBSmI0RSQHXllRr3Ke3Q
Extraction code :homc
Only for communication and discussion . Not for commercial purposes .
边栏推荐
- 浅谈测试开发怎么入门,如何提升?
- Deeply explore the compilation and pile insertion technology (IV. ASM exploration)
- 【批處理DOS-CMD命令-匯總和小結】-字符串搜索、查找、篩選命令(find、findstr),Find和findstr的區別和辨析
- Alexnet experiment encounters: loss Nan, train ACC 0.100, test ACC 0.100
- 深度学习简史(一)
- Amazon MemoryDB for Redis 和 Amazon ElastiCache for Redis 的内存优化
- Trace tool for MySQL further implementation plan
- [force buckle]41 Missing first positive number
- 深度学习之环境配置 jupyter notebook
- View remote test data and records anytime, anywhere -- ipehub2 and ipemotion app
猜你喜欢

ZYNQ移植uCOSIII

Deep learning environment configuration jupyter notebook
深入探索编译插桩技术(四、ASM 探秘)

Mujoco second order simple pendulum modeling and control

Stm32f407 ------- DAC digital to analog conversion

How engineers treat open source -- the heartfelt words of an old engineer

【批處理DOS-CMD命令-匯總和小結】-字符串搜索、查找、篩選命令(find、findstr),Find和findstr的區別和辨析

Zynq transplant ucosiii

Attention SLAM:一種從人類注意中學習的視覺單目SLAM

Dell笔记本周期性闪屏故障
随机推荐
Tencent cloud webshell experience
Model-Free Control
Learn self 3D representation like ray tracing ego3rt
Chapter 5 DML data operation
Stm32f407 ------- DAC digital to analog conversion
Common shortcuts to idea
浅谈测试开发怎么入门,如何提升?
重上吹麻滩——段芝堂创始人翟立冬游记
[daily problem insight] prefix and -- count the number of fertile pyramids in the farm
【批处理DOS-CMD命令-汇总和小结】-查看或修改文件属性(ATTRIB),查看、修改文件关联类型(assoc、ftype)
腾讯云 WebShell 体验
5种不同的代码相似性检测,以及代码相似性检测的发展趋势
Matlab learning notes
C9高校,博士生一作发Nature!
Link sharing of STM32 development materials
QT tutorial: creating the first QT program
第四篇,STM32中断控制编程
stm32F407-------SPI通信
stm32F407-------DAC数模转换
新手如何入门学习PostgreSQL?
https://xiangyuecn.gitee.io/areacity-jsspider-statsgov/