如何为python cartopy几何设置偏移量?

问题描述 投票:1回答:1

所以问题在于,当我将.shp文件中的几何图形添加到图表时,有一个偏移量,我不知道如何设置偏移量。

我是python的新手,所以任何帮助都表示赞赏。

picture here

import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
#from cartopy.feature import GSHHSFeature 

from cartopy.io.shapereader import Reader


canada_east = -63
canada_west = -123
canada_north = 75
canada_south = 37

standard_parallels = (49, 77)
central_longitude = -(91 + 52 / 60)

data = Reader('icitw_wgs84')

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1,
                     projection=ccrs.LambertConformal(central_longitude=central_longitude,
                                                      standard_parallels=standard_parallels))
ax.set_extent([-79.65, -79.1, 43.57, 43.87])


ax.add_feature(cfeature.LAKES.with_scale('10m'))
ax.add_feature(cfeature.LAND.with_scale('10m'))
ax.add_feature(cfeature.RIVERS.with_scale('10m'))


ax.add_geometries(data.geometries(), crs=ccrs.Geodetic(), edgecolor='k', facecolor='none')
python cartopy
1个回答
1
投票

我认为你所看到的是由于低分辨率陆地/湖泊数据集。对于此比例的地图,您最好使用地图图块而不是NaturalEarth地面特征。有多种选择已经可用,Stamen Terrain或Open Street Map可能是不错的选择:

import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs

from cartopy.io.shapereader import Reader
from cartopy.io.img_tiles import StamenTerrain, OSM

standard_parallels = (49, 77)
central_longitude = -(91 + 52 / 60)

data = Reader('citygcs')

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1,                  
                     projection=ccrs.LambertConformal(central_longitude=central_longitude,                                     
                                                      standard_parallels=standard_parallels))
ax.set_extent([-79.65, -79.1, 43.57, 43.87])

tiler = OSM()
ax.add_image(tiler, 10)

ax.add_geometries(data.geometries(), crs=ccrs.Geodetic(), edgecolor='k', 
facecolor='none')
plt.show()

Totornto OSM

或者使用StamenTerrain

Toronto Stamen

关于引用椭圆可能还有其他问题(我注意到shapefile名称中的WGS84),这里有一个很好的参考:https://scitools.org.uk/cartopy/docs/v0.16/gallery/effects_of_the_ellipse.html

将来如果你的代码示例很小并且所有数据都可用(我必须自己去找一个类似的shapefile来重现)会有所帮助,请参阅这里的指南:https://stackoverflow.com/help/mcve

© www.soinside.com 2019 - 2024. All rights reserved.