【问题标题】:How to set offset for python cartopy geometry?如何为 python cartopy 几何设置偏移量?
【发布时间】:2018-09-16 17:58:00
【问题描述】:

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

我是 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】:

    我认为您所看到的是低分辨率的陆地/湖泊数据集。对于这种比例的地图,您最好使用地图图块而不是 NaturalEarth 土地要素。 cartopy 中已有多种选择,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()
    

    或者使用StamenTerrain:

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

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

    【讨论】:

    • 另外,你知道如何改变OSM的瓦片吗?我环顾四周,但并没有真正理解发生了什么。所以我必须使用类似的东西: url(可选)——指向瓦片源并包含 {x}、{y} 和 {z} 的 URL。如:(‘server.arcgisonline.com/ArcGIS/rest/services’‘World_Shaded_Relief/MapServer/tile/{z}/{y}/{x}.jpg’) 但我应该实现吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多