当前位置:网站首页>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 .
边栏推荐
- 筑梦数字时代,城链科技战略峰会西安站顺利落幕
- [daily problem insight] prefix and -- count the number of fertile pyramids in the farm
- Are you ready to automate continuous deployment in ci/cd?
- Win10 startup error, press F9 to enter how to repair?
- 什么是时间
- New feature of Oracle 19C: automatic DML redirection of ADG, enhanced read-write separation -- ADG_ REDIRECT_ DML
- Data processing of deep learning
- How to judge whether an element in an array contains all attribute values of an object
- [force buckle]41 Missing first positive number
- Learn self 3D representation like ray tracing ego3rt
猜你喜欢

如何判断一个数组中的元素包含一个对象的所有属性值
![[Niuke classic question 01] bit operation](/img/f7/e3a482c379ec9bbdb453a05e5e08cb.jpg)
[Niuke classic question 01] bit operation

【软件逆向-自动化】逆向工具大全

View remote test data and records anytime, anywhere -- ipehub2 and ipemotion app

Understand the misunderstanding of programmers: Chinese programmers in the eyes of Western programmers

重上吹麻滩——段芝堂创始人翟立冬游记

JS+SVG爱心扩散动画js特效

The way of intelligent operation and maintenance application, bid farewell to the crisis of enterprise digital transformation

Threejs image deformation enlarge full screen animation JS special effect

Are you ready to automate continuous deployment in ci/cd?
随机推荐
How to judge whether an element in an array contains all attribute values of an object
Advanced learning of MySQL -- basics -- multi table query -- subquery
[yolov5 6.0 | 6.1 deploy tensorrt to torch serve] environment construction | model transformation | engine model deployment (detailed packet file writing method)
Equals() and hashcode()
【批处理DOS-CMD命令-汇总和小结】-跳转、循环、条件命令(goto、errorlevel、if、for[读取、切分、提取字符串]、)cmd命令错误汇总,cmd错误
【YoloV5 6.0|6.1 部署 TensorRT到torchserve】环境搭建|模型转换|engine模型部署(详细的packet文件编写方法)
Understand the misunderstanding of programmers: Chinese programmers in the eyes of Western programmers
Interface (interface related meaning, different abstract classes, interface callback)
【JokerのZYNQ7020】AXI_EMC。
Data analysis course notes (V) common statistical methods, data and spelling, index and composite index
ZABBIX 5.0: automatically monitor Alibaba cloud RDS through LLD
C9高校,博士生一作发Nature!
Matlab learning notes
Chapter 5 DML data operation
学习光线跟踪一样的自3D表征Ego3RT
QT tutorial: creating the first QT program
Attention SLAM:一种从人类注意中学习的视觉单目SLAM
Address information parsing in one line of code
Learn self 3D representation like ray tracing ego3rt
Model-Free Control
https://xiangyuecn.gitee.io/areacity-jsspider-statsgov/