当前位置:网站首页>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')
pass
result :
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 .
边栏推荐
- Address information parsing in one line of code
- 5种不同的代码相似性检测,以及代码相似性检测的发展趋势
- String comparison in batch file - string comparison in batch file
- 【软件逆向-求解flag】内存获取、逆变换操作、线性变换、约束求解
- [daily problem insight] prefix and -- count the number of fertile pyramids in the farm
- The way of intelligent operation and maintenance application, bid farewell to the crisis of enterprise digital transformation
- Advanced learning of MySQL -- basics -- multi table query -- external connection
- Equals() and hashcode()
- What kind of experience is it to realize real-time collaboration in jupyter
- What is time
猜你喜欢
批量获取中国所有行政区域经边界纬度坐标(到县区级别)
Chapter II proxy and cookies of urllib Library
【软件逆向-求解flag】内存获取、逆变换操作、线性变换、约束求解
Interface master v3.9, API low code development tool, build your interface service platform immediately
详解OpenCV的矩阵规范化函数normalize()【范围化矩阵的范数或值范围(归一化处理)】,并附NORM_MINMAX情况下的示例代码
5种不同的代码相似性检测,以及代码相似性检测的发展趋势
Deeply explore the compilation and pile insertion technology (IV. ASM exploration)
Installation and testing of pyflink
用tkinter做一个简单图形界面
equals()与hashCode()
随机推荐
Service asynchronous communication
Distributed cache
Advanced learning of MySQL -- basics -- multi table query -- subquery
Advanced learning of MySQL -- basics -- transactions
What is time
Mujoco produces analog video
批量获取中国所有行政区域经边界纬度坐标(到县区级别)
Leetcode (547) - number of provinces
Configuring the stub area of OSPF for Huawei devices
随时随地查看远程试验数据与记录——IPEhub2与IPEmotion APP
Equals() and hashcode()
Zynq transplant ucosiii
学习使用代码生成美观的接口文档!!!
[software reverse - solve flag] memory acquisition, inverse transformation operation, linear transformation, constraint solving
Leetcode(547)——省份数量
Alexnet experiment encounters: loss Nan, train ACC 0.100, test ACC 0.100
详解OpenCV的矩阵规范化函数normalize()【范围化矩阵的范数或值范围(归一化处理)】,并附NORM_MINMAX情况下的示例代码
通过串口实现printf函数,中断实现串口数据接收
Five different code similarity detection and the development trend of code similarity detection
学习光线跟踪一样的自3D表征Ego3RT