简体   繁体   中英

The position does not match while overlapping the image on the map using folium

This code is draft

bounds_lat = np.array([34.884427, 35.389037])
bounds_lon = np.array([128.761718, 129.305605])


folium.raster_layers.ImageOverlay(image=image_path,
                                  bounds=[[bounds_lat[0], bounds_lon[0]], [bounds_lat[1], bounds_lon[1]]],                            
                                  mercator_project=True,
                                  opacity=0.3).add_to(map)

在此处输入图像描述 My image was incorrectly overlaid in map, so add the mercator_project=True

change the code

bounds_lat = np.array([34.884427, 35.389037])
bounds_lon = np.array([128.761718, 129.305605])


folium.raster_layers.ImageOverlay(image=image_path,
                                  bounds=[[bounds_lat[0], bounds_lon[0]], [bounds_lat[1], bounds_lon[1]]],
                                  mercator_project=True,
                                  opacity=0.3).add_to(map)

error occurred在此处输入图像描述 please help me

Reading the docs yielded the following:

image (string, file or array-like object) – The data you want to draw on the map. * If string, it will be written directly in the output file. * If file, it's content will be converted as embedded in the output file. * If array-like, it will be converted to PNG base64 string and embedded in the output.

This means you can use both a path to an image or an image array :

But for mercator_project the documentation says:

mercator_project (bool, default False.) – Used only for array-like image. Transforms the data to project (longitude, latitude) coordinates to the Mercator projection. Beware that this will only work if image is an array-like object.

So you must first load the image into an array :

from PIL import Image

image_array= Image.open(image_path)

Or use any other image processing library ( OpenCV eg.).

Then you can do:


folium.raster_layers.ImageOverlay(image=image_array,
                                  bounds=[[bounds_lat[0], bounds_lon[0]], [bounds_lat[1], bounds_lon[1]]],
                                  mercator_project=True,
                                  opacity=0.3).add_to(map)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM