- 打开规划云网站点击“边界:高德行政区划”。
网址:http://www.guihuayun.com/maps/region.php - 点击选择要下载的区块,点击下载json文件会打不开,选择打开json文件并复制网址
- 下载json文件的代码实现:
import requests
liaoning_url = 'https://geo.datav.aliyun.com/areas_v3/bound/210000_full.json'
dalian_url = 'https://geo.datav.aliyun.com/areas_v3/bound/210200_full.json'
try:
# 获取辽宁省的边界数据
liaoning_response = requests.get(liaoning_url, verify=False)
with open('liaoning.json', 'w', encoding='utf-8') as f:
f.write(liaoning_response.text)
# 获取大连市的边界数据
dalian_response = requests.get(dalian_url, verify=False)
with open('dalian.json', 'w', encoding='utf-8') as f:
f.write(dalian_response.text)
print("数据下载成功")
except requests.exceptions.RequestException as e:
print(f"数据下载失败: {e}")
- 在地图上标点的代码实现:
import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt
from shapely.geometry import Point, shape
import json
# 读取Excel数据
excel_file = 'C:/Users/llxc120401/Desktop/部规划院/袁锐工作/都市圈环线/zhandian.xlsx' # 替换为你的Excel文件路径
df = pd.read_excel(excel_file)
# 设置合理的经纬度范围
latitude_min, latitude_max = 38.7, 40.2 # 大连市纬度范围
longitude_min, longitude_max = 120.9, 123.5 # 大连市经度范围
# 过滤掉超出范围的点
df_filtered = df[(df['观测站纬度'] >= latitude_min) & (df['观测站纬度'] <= latitude_max) &
(df['观测站经度'] >= longitude_min) & (df['观测站经度'] <= longitude_max)]
# 创建GeoDataFrame
geometry = [Point(xy) for xy in zip(df_filtered['观测站经度'], df_filtered['观测站纬度'])]
gdf = gpd.GeoDataFrame(df_filtered, geometry=geometry, crs="EPSG:4326") # 设置坐标系为WGS 84
# 从本地文件读取大连市边界数据
with open('dalian.json', 'r', encoding='utf-8') as f:
dalian_json = json.load(f)
dalian_data = gpd.GeoDataFrame.from_features(dalian_json["features"], crs="EPSG:4326")
# 绘制大连市地图并标注观测站点
fig, ax = plt.subplots(1, 1, figsize=(10, 10))
dalian_data.plot(ax=ax, color='white', edgecolor='black')
gdf.plot(ax=ax, marker='o', color='red', markersize=5)
plt.title('大连市观测站点分布')
plt.show()
附:json转shp文件网址:https://mapshaper.org/