2024-09-01
Python
00

Python

handlebars
import cmath import json import requests from geopandas import GeoDataFrame,GeoSeries from shapely.geometry import shape, Polygon, MultiPoint,Point import matplotlib.pyplot as plt import numpy as np import pandas as pd def get_zjk_df(): """ 张家口 :return: """ url = "https://geo.datav.aliyun.com/areas_v2/bound/130700.json" r = requests.get(url) b = shape(r.json()['features'][0]['geometry']) geodf = GeoDataFrame([{'geometry': b}], crs="EPSG:4326") return geodf a=""" 115.503 40.419 115.63025 40.22925 115.72225 40.08925 115.78275 39.96275 115.824 39.851 115.862 39.74475 115.899 39.63675 115.9335 39.5265 115.95975 39.4155 115.975 39.306 115.974 39.20675 115.959 39.12975 115.93325 39.07725 115.89825 39.04325 115.86125 39.028 115.827 39.03175 115.79725 39.04425 115.781 39.0655 115.7795 39.09725 115.78725 39.13525 115.80775 39.1865 115.851 39.24625 115.9285 39.312 116.04525 39.3845 116.19325 39.46125 116.353 39.54275 116.5025 39.6265 116.64025 39.70825 116.77675 39.78975 116.92275 39.86725 117.0855 39.945 117.2595 40.0265 117.44625 40.115 117.6475 40.2025 117.856 40.2845 118.06225 40.355 118.263 40.4185 118.449 40.48875 118.63075 40.5655 118.8145 40.6455 119.0 40.72825 119.1935 40.814 119.3765 40.912 119.56275 41.02025 119.75525 41.13875 119.9655 41.26175 120.18925 41.3805 120.42075 41.491 120.66425 41.592""" a=a.splitlines() a=list(filter(lambda x:len(x)>5,a)) lon=list(map(lambda x:float(x.split()[0]),a)) lat=list(map(lambda x:float(x.split()[1]),a)) geodf = get_zjk_df() ax=geodf.plot(color='white', edgecolor='black') fblock=[] for i in zip(lon,lat): fblock.append(Point(i)) fblock_df = GeoSeries(fblock) fblock_df.plot(ax=ax, marker='o', color='red', markersize=5) # 显示与保存 plt.title("zjk") plt.xlabel('lon') plt.ylabel('lat') plt.grid() plt.savefig("./nihao.svg") plt.show()
如果对你有用的话,可以打赏哦
打赏
ali pay
wechat pay

本文作者:Dong

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC。本作品采用《知识共享署名-非商业性使用 4.0 国际许可协议》进行许可。您可以在非商业用途下自由转载和修改,但必须注明出处并提供原作者链接。 许可协议。转载请注明出处!