Search code examples
pythoncartopy

How to set offset for python cartopy geometry?


So the problem is that when I add a geometry from .shp file to the cartopy figure, there is an offset and I have no idea how to set the offset.

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')

Solution

  • I think what you are seeing is due to the low resolution land/lake data set. For maps of this scale you are probably better off using map tiles instead of the NaturalEarth land feature. There are several choices already available in cartopy, Stamen Terrain or Open Street Map might be good choices:

    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

    Or using StamenTerrain:

    Toronto Stamen

    There may be further issues regarding referencing ellipse (I notice WGS84 in the shapefile name), there is a good reference here: https://scitools.org.uk/cartopy/docs/v0.16/gallery/effects_of_the_ellipse.html.