Python - Create Maps with Folium and Leaflet
HTML-код
- Опубликовано: 8 авг 2024
- Creation of Maps, Markers and Custom Markers with Python Folium and Leaflet.js.
In case of any questions, just drop a comment.
Please subscribe if you like my video(s).
The code is uploaded to github:
github.com/code-and-dogs/foli...
Documentation can be found here:
Latlong: www.latlong.net/
Folium: github.com/python-visualizati...
Jupyter: jupyter.org/
Latitude & Longitute information: • How to read Latitude a...
#python #python3 #folium #leaflet #leaflet.js #javascript #100daysofcode
#coding #webdev - Наука
A lot of thanks for sharing Code & Dogs, this was my first time using python, I learned because of your tutorial how to install folium and practice maps, greetings from Perú!
thanks so much for the feedback :-) greetings back from germany
I had an amazing experience, before using python I used to think it's not for common people like me but I enjoyed a lot while practicing folium Marker. Thank you so much for simplifying python for us
Thanks for the amazing feedback :-)
You're awesome!!! You've explained it really well and it's easy enough to understand especially got beginners like myself!!
Thank you so much for the good feedback :-)
@@tech-letters Is it possible to change this on android now?
Greetings from Serbia!
Very cool and informative video!
Superb explanation-thanks so much for making this helpful video!
Thank you for the feedback :-)
thank you so much for 3000 views!!! :-)
thank you for the awesome content! My friend, how can I use the output in a website? Do you have any ideas?
So simply explained..Thanks a lot..
Thank you so much for the feedback! :-) Would highly appreciate it, if you could give me a subscription. This will help me a lot in provide more content.
Thank you so much!
Thank you so much! Great tutorial!
Happy to hear that. Thanks :-)
Hi is there any way you can use a map you have created yourself in svg format?
very useful vedio .......wish every vedio's are like this
thank you :-)
Thank you so much for creating this! It has been super helpful. I was wondering how would we go about adding multiple points at once in the map and color coding them based on another column? For example, I have a map of weather events, and would like to plot the points of the weather events and color code them using another variable that is True or False (so using two colors).
thank you so much ,,, quite helpful!
Thank you :-)
if it wasn't because of chatgpt i would not know this kind of library. currently working as a data processor (most likely GIS but without coding). this might help me alot! thank you!
Great video! wondering if it‘s possible to highlight or color the rivers in the map? Thanks
I think it is possible if you get some geojson data / coordinates for the rivers itself.
Thank you very much!
I yet now wondering, how can I display several markers, if their latitude and longitude is stored in pandas dataframe... I can use iteritems() to iterate over the columns to get the lon and lat values, but how do I provide these values into Markers arguments... 🤔
Hey Alexandra, I did a video combining pandas & python in this series: ruclips.net/p/PL2UmzTIzxgL4GUqBPhGcpMe5BTOp0Ovqv
I guess, it is the last one, but don't remember by heart :-)
Hi, is there any possibility to input coordinates from user? for example: user input coordinates of place which he/she would like to see. I need sth like that definitely.
Hi, there are some options. Either you read your input into variables like latitude = input("Enter your latitude"), longitude = input("Enter your longitude") ... and use this when creating the map (folium.Map([latitude, longitude)... or there are some API which can even translate an adress to lat & long. However, Folium is not very dynamic. If you want to make use of users location (e.g. you can take it from your users browser) or change it dynamically, I would suggest to use Javascript & Leaflet.js. I am currently just making a video series about it (changing coordinates on the map in real-time)
useful information, stick to the title, and straight to the point, kudos to you!
Thanks for the feedback :-)
Does it accepts an svg image file? i tried to use one but the map doesnt show it, but if i use a jpeg file it runs normaly. Anyone?
This is very helpful. Would you suggest how do I fix the image shape according to the shape of the state?
thank you :-) I do not quite understand. Do you want to have an image that covers a whole state?
Great!!!
Is there a way to add different tiles to the map? For example, I have a Geo Tiff image how would I add it to the map?
hmm I don't know :-( but I found this. It looks someone tried the same here
www.researchgate.net/post/How_to_plot_a_raster_datageotiff_in_Folium_for_interactive_maps
Hi. Great video!, one question. I have a lot of lat long points, so im trying to make a grid, maybe 50mx50m, to have a mean or the median of this points into a single grid. Do you know How can I make this? Thanks!
just to make sure I get your question. You have different markers all over the map. Now you want to draw a rectangle on this map and the program should calculate the median of all points in this rectangle?
@@tech-letters yes. Like make a binning .. Create rectangles or hexagons to grouping lat long points.
Thanks for the explanation!
How can I write a number above the Marker(like a circle and a number inside it)?
custom marker might do it
Great video, I have one question, how about if I want to use picture as an icon but the picture is in internet ( I don't download it)
you can use ImageAsync instead of Image
hey, can you tell me how to make a heat map with folium?
Hey, Is It possibile using python to see the tráfic lights in a city?
That's possible if we have a source for this data. We would need a data source that provides traffic light locations. Perhaps from some governmental or city office page?
hi what should i do if i want take input from user from map
Use Javascript / leaflet for dynamic maps. I have some videos about it in my list
Can we use folium with streamlit??
Nice tutorial, how to add this icon to legend?
videos are really helpful. upload videos for (google earth engine) foliumgee .
thanks. will have a look at this soon. currently i am moving to a new town and have no time to make more videos :-( next month there will be new ones :-)
Hi.. Your video was simple and easy to learn. I am new in python. Is it possible for you to include one feature related to Layer Control. I am unable to find any good stuff on it. I am having 1 list of markers and want it to get it included in the Layer control. So that based on the option selection, respective group of markers are shown.
Hi, thanks for the feedback. Yes, I can do that, but unfortunately not within the next weeks. I am currently on travel for my regular job :-( want to spend much more time producing videos in future and put it on top of my list
Will do.. Your videos should go long way. 👍🏻 will keep an eye on the new upcomings.
hello please hepl me i want to create a map of my university . can this map work go that zoom?
Unfortunately not. There is a maximum zoom with folium.
Hi , how can we track mobile of rider delivering our goods (appreciate real time tracking pls).Thx in advance. Also,if able to create a smartphone app for this. input of Pickup and Dropoff by user..with iput of mobile by rider if they accept the order.
That's much more complex, but possible. Checkout my video series about "real time maps".
You would need an app on the server, hosting the map, providing the app. The clients / riders must send their data to the server.
sir how can we add http images
HELLOPLS HELP ME😭😖. I want install jupyter or other packages but in most of them i have the same problem! [WinError 225] says: unable to complete the action. The file contains a virus or potentially unwanted software. The error always appears after the written:" Using cached MarkupSafe-2.1.1.tar.gz (18kb) 😭
How the hell are you trying to install it? Are you using pip?
what if you want to use the current location of the user
I think this will not be possible with Folium, as it is static. With Javascript leaflet it is possible to get the users location e.g. From the browser
nice video, learnt a lot for my project.
i am trying to link all the marker to a single marker. Is it possible ?
What do you mean with link? A line on the map from one marker to another one? Or if you click on one marker that the map zooms to another one?
can i have full draggable marker program for folium in python
I think this is not possible with folium, as it is not dynamic. It will generate a file and thats it. However you can do it with javascript, just check out this video ruclips.net/video/hRoiG4ZIzeM/видео.html
When I enter pip install folium, it gives an error, most probably as the folium package is not in directory, how I add it?
Can you copy and post the error here? That gives me a better chance to analyze it
@@tech-letters C:\Users\dell\Anaconda3\Scripts>pip install folium
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting folium
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/folium/
Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/folium/
Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/folium/
Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/folium/
Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/folium/
Could not fetch URL pypi.org/simple/folium/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/folium/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
Could not find a version that satisfies the requirement folium (from versions: )
No matching distribution found for folium
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Could not fetch URL pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
hmm for me this does not look like a folium specific issue. Can you import any other library like pandas or numpy? Otherwise I found some notes here: stackoverflow.com/questions/41328451/ssl-module-in-python-is-not-available-when-installing-package-with-pip3 ... perhaps that helps?! never saw that error before :-(
Unable to include image :(
Same as mine (ノ﹏ヽ)
hello friend can you provide me with python library for cities i need it offline
Hi there, I am not aware of any library doing this that works offline :-(
Hi i am using Mapbox bright but I think that functionality is deprecated can you show how can I use mabpox bright because I am just getting blank map with all zoom level also.....
Hi, I will check on Sunday evening, currently I do not have my laptop with me
Sure thank you so much...
@@00hattan I just checked and it is really strange.
The official folium documentation (python-visualization.github.io/folium/quickstart.html) says it should work with mapbox like in below snippet, but only with API key from mapbox.com. I created one, but it does not work in this way, although it should (just replace pk.xxx with your access token from mapbox.com)
folium.Map(location=[45.372, -121.6972],
zoom_start=12,
tiles='"{s}.tiles.mapbox.com/v4/wtgeographer.2fb7fc73/{z}/{x}/{y}.png?access_token=pk.xxx',
attr='XXX Mapbox Attribution')
What makes me wonder is that mapbox brigth tiles in the official documentation are also not loaded properly. (check python-visualization.github.io/folium/quickstart.html and there command [12]. It seems to be a general issue with folium in combination with Mapbox Brigth. Also in this overview all mapbox brigth tiles disappeared meanwhile:
python-graph-gallery.com/288-map-background-with-folium/
I think I can't help with this issue :-( Sorry
@@tech-letters hi I am facing the same issue. did you get the solution now?
Recently (past 2 weeks) have had problem with Anaconda such that cannot install new packages such as folium. Tried several fixes but best I can tell it is a problem with conda and the way it names directory/paths. May work on Linux, but Win 10 is a no go if you need to install new packages. Anaconda folks need to fix it. I'm using PyCharm which seems to work.
are you getting any error message? How about installing it withoud anaconda in cmd with "pip install folium"?
@@tech-letters thanks for the reply. I do get an error message from conda: failed to create process. pip seems to work (or pip3). I have run in to the need to run as administrator and take care of that. I've uninstalled and reinstalled Anaconda. No help. Based on googling, it seems the Anaconda folks have a naming problem. Someone suggested might fix it by finding the script and adding "" around a location name but I don't consider that a fix. I'd almost prefer buying a drive and installing Linux to dual boot. PyCharm is working fine so at least I get familiar with PyCharm.
BTW, good folium video. Enjoyed it.
my py program is run but map is not show
are you getting any error? did you copy my code from github or did you start from scratch?
not able to install folium in python 3.7
Are you getting any error? Are you trying with pip or conda?
i have made a map with data from an xml file and a list of the markers with html i want somehow to open popup of the marker when it is clicked in the list can you help?
Let me unsure I understand correctly: you successfully placed the markers on the map. Now you click on on the source of the marker in the xml file and the marker pop-up on the map opens automatically?
@@tech-letters i have successfully created the map and placed the markers(the coordinate of the markers are in an xml file)
and i have created a list of the coordinates in an html file .I want to click on the list and open the popup of the markers whose coordinates where clicked.
@@swkaholicok, got it, thanks. I think this is possible, but I think not with Python Folium, as it is not dynamic. However it should be possible with Javascript, e.g. Leaflet JS. To check if a list item is clicked you could use onclick event (www.w3schools.com/jsref/event_onclick.asp) and open the respective marker popup with marker.bindPopup(popupContent).openPopup(); (leafletjs.com/reference-1.5.0.html#popup)
@@tech-letters Thanks! Do you have any idea how can i do it with javascript?
@@swkaholic yes, I will provide a code snippet by today evening or latest tomorrow
Hi can u help me to build a animation with time slider of multiple lat lon precipation data on uk map.
Hi, I am not sure if I understand correctly. What kind of animation do you mean? Can you give me more details. Will try to help then.
@@tech-letters I have to create a visulization on change of climate data over year on a region.
I have the data of date, lat, lon, precipitation rate. Lat lon are from uk. I am able to plot on a single time stamp. But I have to create a animation with multiple time stamp with a slider.
@@tech-letters my email id is khan.rajdip@ gmail.com
If u share ur id I will be able to share my work till now
I am almost halfway done
Little help will be very appreciated.
@@MsRAJDIP Hi, you can send it to codeanddogs@gmail.com ... Tomorrow I would have some time to check&help
@@tech-letters
Sure, thanks a lot 😊
Instead of Mapbox Bright which is not available anymore, in 2022 one can go for "cartodb positron" :)
that should work. I am mostly using openstreetmap nowadays
what if the data i have is polygon rather than point
do i just plot each point individually with their coordinates or is there a way i can go about it?
You can make use of folium.vector_layers.Polygon(locations). See here for details: python-visualization.github.io/folium/modules.html
@@tech-letters thank you, but i was wondering if you had a video on it or you could make one because im a beginner and i needed sth to follow along to
This is amazing! Could this map to be used offline? Also I would like to ask that is it possible to program it into a exe file or html.file to be used offline? Thank you very much indeed.
Thanks for the feedback, highly appreciate it :-) Yes, you can use it offline. You can simply save the map as html file with map.save('index.html'). It will generate a html file and you can use it for whatever you want. You can also check out my github link in the description (github.com/code-and-dogs/foliumSuperheros/blob/master/script.py) where I did the same.
@@tech-letters Thanks a million for the reply. Just want to be sure, If I am editing and putting different markers on the map, I would still need Internet access for the Map on the leaflet js, is that right?
@@mialan5227 that's correct. Unfortunately, Folium needs internet (Web Tile Service (WTS)) to generate/render the map. There is no offline cache or something similar available for this in Folium :-(
@@tech-letters I see, still tons thanks for the help though.
@@mialan5227 always welcome :-)
Please do the needful
import folium
m = folium.Map(location=[16.715891, 78.028351], zoom_start=15)
m
ModuleNotFoundError Traceback (most recent call last)
in
----> 1 import folium
2
3 m = folium.Map(location=[16.715891, 78.028351], zoom_start=15)
4 m
ModuleNotFoundError: No module named 'folium'
have you installed folium with command "pip install folium" upfront?
@@tech-letters Hi! thank you for the tutorial. I am facing the same error.
Although i have installed it using connda.
Are you from germany?
Yes :-)
I am not able to load tiles..
does it give you any error message or just a blank screen? are you using jupyter or a python script?
Just a blank screen
I am using jupyter notebook
@@techmechstuff6630 have you run "pip install folium" in cmd or installed it with anaconda on your PC upfront?
Code & Dogs will take care of you, but I had a problem with Python displaying a blank (all gray) window and none of my map or popups. I'm fairly certain in my case it had to do with the use of tiles = 'Mapbox Bright' in an example. Try not giving a tiles parameter. I think it will default and see if you get the map. Then can find a suitable tiles value.