Skip to main content

A tool to add basemap in matplotlib

Project description

plot_map

plot_map是一个基于matplotlib的工具,在用geopandas或者pyplot绘制地理图形的时候,你可以用plot_map来添加地图底图

安装

pip install plot-map

使用方法

地图底图加载

只需要用以下代码:

import plot_map
#设定显示范围
bounds = [lon1,lat1,lon2,lat2]  
plot_map.plot_map(plt,bounds,zoom = 12,style = 4)  

参数

参数 描述
bounds 底图的绘图边界,[lon1,lat1,lon2,lat2] (WGS84坐标系) 其中,lon1,lat1是左下角坐标,lon2,lat2是右上角坐标
zoom 底图的放大等级,越大越精细,加载的时间也就越久,一般单个城市大小的范围,这个参数选取12到16之间
style 地图底图的样式,可选1-7,1-6为openstreetmap,7是mapbox
imgsavepath 瓦片地图储存路径,设置路径后,会把地图下载到本地的文件夹下,使用时也会优先搜索是否有已经下载的瓦片,默认的存放路径是C:\
printlog 是否显示日志

绘制指北针和比例尺的功能plotscale

为底图添加指北针和比例尺

plot_map.plotscale(ax,bounds = bounds,textsize = 10,compasssize = 1,accuracy = 2000,rect = [0.06,0.03])  

参数

参数 描述
bounds 底图的绘图边界,[lon1,lat1,lon2,lat2] (WGS84坐标系) 其中,lon1,lat1是左下角坐标,lon2,lat2是右上角坐标
textsize 标注文字大小
compasssize 标注的指北针大小
accuracy 标注比例尺的长度
unit 'KM','km','M','m' 比例尺的单位
style 1或2,比例尺样式
rect 比例尺在图中的大致位置,如[0.9,0.9]则在右上角

效果

栅格化(渔网)

import plot_map
#设定范围
bounds = [lon1,lat1,lon2,lat2]
grid,params = plot_map.rect_grids(bounds,accuracy = 500)

即可生成研究范围内的方形栅格 输入参数

参数 描述
bounds 底图的绘图边界,[lon1,lat1,lon2,lat2] (WGS84坐标系) 其中,lon1,lat1是左下角坐标,lon2,lat2是右上角坐标
accuracy 栅格大小

输出

参数 描述
grid 栅格的GeoDataFrame,其中LONCOL与LATCOL为栅格的编号,HBLON与HBLAT为栅格的中心点坐标
params 栅格参数,分布为(lonStart,latStart,deltaLon,deltaLat)栅格左下角坐标与单个栅格的经纬度长宽

GPS数据对应栅格编号

输入数据的经纬度列与栅格参数,输出对应的栅格编号

data['LONCOL'],data['LATCOL'] = plot_map.GPS_to_grids(data['Lng'],data['Lat'],params)

栅格编号对应栅格中心点经纬度

输入数据的栅格编号与栅格参数,输出对应的栅格中心点

data['HBLON'],data['HBLAT'] = plot_map.grids_centre(data['LONCOL'],data['LATCOL'],params)

火星坐标系互转

坐标互转,基于numpy列运算

data['Lng'],data['Lat'] = plot_map.wgs84tobd09(data['Lng'],data['Lat'])  
data['Lng'],data['Lat'] = plot_map.wgs84togcj02(data['Lng'],data['Lat'])  
data['Lng'],data['Lat'] = plot_map.gcj02tobd09(data['Lng'],data['Lat'])  
data['Lng'],data['Lat'] = plot_map.gcj02towgs84(data['Lng'],data['Lat'])  
data['Lng'],data['Lat'] = plot_map.bd09togcj02(data['Lng'],data['Lat'])  
data['Lng'],data['Lat'] = plot_map.bd09towgs84(data['Lng'],data['Lat'])  

经纬度计算距离

输入起终点经纬度,获取距离(米),基于numpy列运算

data['distance'] = plot_map.getdistance(data['Lng1'],data['Lat1'], data['Lng2'],data['Lat2'])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plot_map-0.2.0.tar.gz (10.1 kB view details)

Uploaded Source

File details

Details for the file plot_map-0.2.0.tar.gz.

File metadata

  • Download URL: plot_map-0.2.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.6.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for plot_map-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9161d5da67e409bec565f579f32788d63e1dae078d6956da2a46a4e8dfdd8152
MD5 26f527d4058aa99fdeec235e8508257a
BLAKE2b-256 8a02a1325ab329c040ec606f4008ba40e131a400efa9fae62ee773d7170bee18

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page