当前位置:网站首页>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 .
边栏推荐
- equals()与hashCode()
- windows安装mysql8(5分钟)
- 深度学习之线性代数
- ZABBIX 5.0: automatically monitor Alibaba cloud RDS through LLD
- Zabbix 5.0:通过LLD方式自动化监控阿里云RDS
- [user defined type] structure, union, enumeration
- 「精致店主理人」青年创业孵化营·首期顺德场圆满结束!
- [yolov5 6.0 | 6.1 deploy tensorrt to torch serve] environment construction | model transformation | engine model deployment (detailed packet file writing method)
- mongodb客户端操作(MongoRepository)
- 重上吹麻滩——段芝堂创始人翟立冬游记
猜你喜欢

城联优品入股浩柏国际进军国际资本市场,已完成第一步

【批处理DOS-CMD命令-汇总和小结】-字符串搜索、查找、筛选命令(find、findstr),Find和findstr的区别和辨析

How to judge whether an element in an array contains all attribute values of an object
![[user defined type] structure, union, enumeration](/img/a5/d6bcfb128ff6c64f9d18ac4c209210.jpg)
[user defined type] structure, union, enumeration

windows安装mysql8(5分钟)

Five different code similarity detection and the development trend of code similarity detection
![[C language] dynamic address book](/img/e7/ca1030a1099fe1f59f5d8dd722fdb7.jpg)
[C language] dynamic address book

深度学习之线性代数

基于SSM框架的文章管理系统

Lombok 同时使⽤ @Data 和 @Builder 的坑,你中招没?
随机推荐
Interface master v3.9, API low code development tool, build your interface service platform immediately
《安富莱嵌入式周报》第272期:2022.06.27--2022.07.03
深度学习之线性代数
Part 7: STM32 serial communication programming
【批處理DOS-CMD命令-匯總和小結】-字符串搜索、查找、篩選命令(find、findstr),Find和findstr的區別和辨析
windows安装mysql8(5分钟)
dynamic programming
Service asynchronous communication
集合(泛型 & List & Set & 自定义排序)
浅谈测试开发怎么入门,如何提升?
在jupyter中实现实时协同是一种什么体验
View remote test data and records anytime, anywhere -- ipehub2 and ipemotion app
Article management system based on SSM framework
Equals() and hashcode()
Summary of being a microservice R & D Engineer in the past year
Levels - UE5中的暴雨效果
Policy Gradient Methods
学习使用代码生成美观的接口文档!!!
QT tutorial: creating the first QT program
城联优品入股浩柏国际进军国际资本市场,已完成第一步
https://xiangyuecn.gitee.io/areacity-jsspider-statsgov/