省市区shp地图api下载及在地图上标点的代码实现

  1. 打开规划云网站点击“边界:高德行政区划”。
    网址:http://www.guihuayun.com/maps/region.php
  2. 点击选择要下载的区块,点击下载json文件会打不开,选择打开json文件并复制网址
  3. 下载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}")

  1. 在地图上标点的代码实现:
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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值