@@ -952,16 +952,23 @@ def json_style(style_cnt, line_color, line_weight, line_opacity,
952952
953953 @iter_obj ('image_overlay' )
954954 def image_overlay (self , data , opacity = 0.25 , min_lat = - 90.0 , max_lat = 90.0 ,
955- min_lon = - 180.0 , max_lon = 180.0 , image_name = None , filename = None ):
956- """Simple image overlay of raster data from a numpy array. This is a lightweight
957- way to overlay geospatial data on top of a map. If your data is high res, consider
958- implementing a WMS server and adding a WMS layer.
959-
960- This function works by generating a PNG file from a numpy array. If you do not
961- specifiy a filename, it will embed the image inline. Otherwise, it saves the file in the
962- current directory, and then adds it as an image overlay layer in leaflet.js.
963- By default, the image is placed and stretched using bounds that cover the
964- entire globe.
955+ min_lon = - 180.0 , max_lon = 180.0 , image_name = None , filename = None ,
956+ data_projection = 'mercator' ):
957+ """Simple image overlay of raster data from a numpy array. This is a
958+ lightweight way to overlay geospatial data on top of a map.
959+ If your data is high res, consider implementing a WMS server
960+ and adding a WMS layer.
961+
962+ This function works by generating a PNG file from a numpy
963+ array. If you do not specifiy a filename, it will embed the
964+ image inline. Otherwise, it saves the file in the current
965+ directory, and then adds it as an image overlay layer in
966+ leaflet.js. By default, the image is placed and stretched
967+ using bounds that cover the entire globe. By default, we
968+ assume that your data is in geodetic projection and thus
969+ project it to web mercator for display purposes. If you are
970+ overlaying a non-georeferenced image, set data_projection to
971+ None.
965972
966973 Parameters
967974 ----------
@@ -976,10 +983,12 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
976983 max_lon: float, default 180.0
977984 image_name: string, default None
978985 The name of the layer object in leaflet.js
979- filename: string, default None
986+ filename: string or None , default None
980987 Optional file name of output.png for image overlay. If None, we use a
981988 inline PNG.
982-
989+ data_projection: string or None, default 'mercator'
990+ Used to specify projection of image. If None, do no projection
991+
983992 Output
984993 ------
985994 Image overlay data layer in obj.template_vars
@@ -988,7 +997,7 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
988997 -------
989998 # assumes a map object `m` has been created
990999 >>> import numpy as np
991- >>> data = np.random.random((100,100 ))
1000+ >>> data = np.random.random((180,360 ))
9921001
9931002 # to make a rgba from a specific matplotlib colormap:
9941003 >>> import matplotlib.cm as cm
@@ -1000,12 +1009,16 @@ def image_overlay(self, data, opacity=0.25, min_lat=-90.0, max_lat=90.0,
10001009
10011010 # put it only over a single city (Paris)
10021011 >>> m.image_overlay(data, min_lat=48.80418, max_lat=48.90970, min_lon=2.25214, max_lon=2.44731)
1003-
1004- """
10051012
1013+ """
10061014 if isinstance (data , str ):
10071015 filename = data
10081016 else :
1017+ assert data_projection in [None , 'mercator' ]
1018+ # this assumes a lat x long array
1019+ # with 2x as many points in long as lat dims.
1020+ if data_projection is 'mercator' :
1021+ data = utilities .geodetic_to_mercator (data )
10091022 try :
10101023 png_str = utilities .write_png (data )
10111024 except Exception as e :
0 commit comments