def gshhs_line(self, outline_color='k', domain=None, resolution='low', **kwargs): # domain is a shapely geometry (Polygon or MultiPolygon) import cartopy.gshhs as gshhs # import cartopy.spherical as spherical from matplotlib.collections import PatchCollection, LineCollection paths = [] projection = self.projection if domain is None: domain = self.map_domain(ccrs.PlateCarree()) for points in gshhs.read_gshhc(gshhs.fnames[resolution], poly=False, domain=domain): paths.extend(patch.geos_to_path(shapely.geometry.LineString(points))) # slinestring = shapely.geometry.LineString(points) # projected = projection.project_geometry(slinestring) # paths.extend(patch.geos_to_path(projected)) collection = PatchCollection([mpatches.PathPatch(pth) for pth in paths], edgecolor=outline_color, facecolor='none', transform=ccrs.PlateCarree(), **kwargs ) self.add_collection(collection, autolim=False)
def gshhs(self, outline_color='k', land_fill='green', ocean_fill='None', resolution='coarse', domain=None): import cartopy.gshhs as gshhs from matplotlib.collections import PatchCollection if ocean_fill is not None and land_fill is None: land_fill = self.outline_patch.get_facecolor() if domain is None: domain = self.ll_boundary_poly() paths = [] for points in gshhs.read_gshhc(gshhs.fnames[resolution], poly=True, domain=domain): # XXX Sometimes we only want to do lines... poly = shapely.geometry.Polygon(points[::-1, :]) projected = self.projection.project_polygon(poly) paths.extend(patch.geos_to_path(projected)) if ocean_fill is not None: self.outline_patch.set_facecolor(ocean_fill) collection = PatchCollection([mpatches.PathPatch(pth) for pth in paths], edgecolor=outline_color, facecolor=land_fill, zorder=2, ) # XXX Should it update the limits??? (AND HOW???) self.add_collection(collection)