make a notebook for image_overlay
andrewgiessel opened this issue · 10 comments
I'll do it with a PR that but just leaving it here for now.
@andrewgiessel how about this one:
We still need one where the projection is needed to correct the image array.
@koldunovn We need to add the legend now!
Looks good!
Here is a png of an array that is in geodetic and needs to be projected to mercator to display correctly.
data = plt.imread('temps.png')
map1 = folium.Map(location=[0,0], zoom_start=1)
map1.image_overlay(temps, opacity=0.5, data_projection=None)
# vs
map2 = folium.Map(location=[0,0], zoom_start=1)
map2.image_overlay(temps, opacity=0.5, data_projection=True) #using current 0.1.6 syntax
I am re-thinking and I believe it is better to avoid any re-projection inside folium. Lets just say it needs the image in Web Mercator
and leave the transformation to the user. We can easily create example with your geodetic_to_mercator()
, rasterio
or cartopy
. I will try this image later with rasterio
and cartopy
.
I added an example warping the array with cartopy
import cartopy.crs as ccrs
from cartopy.img_transform import warp_array
source_extent = [lon.min(), lon.max(), lat.min(), lat.max()]
new_data = warp_array(colored_data,
target_proj=ccrs.GOOGLE_MERCATOR,
source_proj=ccrs.PlateCarree(),
target_res=data.shape,
source_extent=source_extent,
target_extent=None,
mask_extrapolated=False)
However, we cannot warp images with cartopy (See https://github.com/SciTools/cartopy/blob/master/lib/cartopy/img_transform.py#L93-L120). rasterio
can warp images, but have an awkward API that I still haven't figure out.
!convert GS.png -trim gulf_stream.png
this does not work on windows. convert
is a windows command to convert a hard drive to another format. Isn't there a way to do this in python?
there a way to do this in python?
Probably yes. Using PIL or Pillow. I will take a look at it.
Two new way: http://nbviewer.ipython.org/github/ocefpaf/folium_notebooks/blob/master/test_image_overlay_gulf_stream.ipynb
Trimming with PIL/Pillow and plotting directly from the array without creating another image.
@andrewgiessel I am closing this. But feel free to send more example to this repo 😉
@ocefpaf, this requires folium 0.1.6. Can you make a folium 0.1.6 release so I can submit a PR to the ioos conda-recipes?
Folium v0.1.6
still needs some polishing. I am aiming for this weekend...