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
  • НаукаНаука

Комментарии • 132

  • @nept4ne
    @nept4ne 4 года назад +7

    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ú!

    • @tech-letters
      @tech-letters  4 года назад +1

      thanks so much for the feedback :-) greetings back from germany

  • @lalitb
    @lalitb Год назад +2

    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

  • @maryhollero3048
    @maryhollero3048 3 года назад +1

    You're awesome!!! You've explained it really well and it's easy enough to understand especially got beginners like myself!!

    • @tech-letters
      @tech-letters  3 года назад

      Thank you so much for the good feedback :-)

    • @user-ht4zn7tn6k
      @user-ht4zn7tn6k 2 года назад

      @@tech-letters Is it possible to change this on android now?

  • @andrejpetrovic8240
    @andrejpetrovic8240 2 года назад +1

    Greetings from Serbia!
    Very cool and informative video!

  • @DreamingWithEyesWide
    @DreamingWithEyesWide 4 года назад +2

    Superb explanation-thanks so much for making this helpful video!

  • @tech-letters
    @tech-letters  5 лет назад +2

    thank you so much for 3000 views!!! :-)

    • @rodrigobrust7902
      @rodrigobrust7902 4 года назад

      thank you for the awesome content! My friend, how can I use the output in a website? Do you have any ideas?

  • @sudiptadas7618
    @sudiptadas7618 4 года назад +1

    So simply explained..Thanks a lot..

    • @tech-letters
      @tech-letters  4 года назад +1

      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.

  • @user-qk9sz4kw8f
    @user-qk9sz4kw8f Год назад +1

    Thank you so much!

  • @danielmonroy6874
    @danielmonroy6874 4 года назад +2

    Thank you so much! Great tutorial!

    • @tech-letters
      @tech-letters  4 года назад +1

      Happy to hear that. Thanks :-)

  • @tinyversedata4410
    @tinyversedata4410 2 года назад +3

    Hi is there any way you can use a map you have created yourself in svg format?

  • @harshithsalian3060
    @harshithsalian3060 4 года назад +1

    very useful vedio .......wish every vedio's are like this

  • @gabriellamartinez7985
    @gabriellamartinez7985 2 года назад

    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).

  • @ouiembelhadj6765
    @ouiembelhadj6765 4 года назад +1

    thank you so much ,,, quite helpful!

  • @mandata143
    @mandata143 Год назад +1

    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!

  • @huangxc8029
    @huangxc8029 4 года назад +2

    Great video! wondering if it‘s possible to highlight or color the rivers in the map? Thanks

    • @tech-letters
      @tech-letters  4 года назад

      I think it is possible if you get some geojson data / coordinates for the rivers itself.

  • @alexandraberger5182
    @alexandraberger5182 2 года назад +1

    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... 🤔

    • @tech-letters
      @tech-letters  2 года назад

      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 :-)

  • @karolinasudo1158
    @karolinasudo1158 5 лет назад +2

    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.

    • @tech-letters
      @tech-letters  5 лет назад

      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)

  • @amrirasyidi
    @amrirasyidi 4 года назад +1

    useful information, stick to the title, and straight to the point, kudos to you!

  • @juanjoerazo1710
    @juanjoerazo1710 2 года назад

    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?

  • @arundhutichowdhury1868
    @arundhutichowdhury1868 2 года назад +1

    This is very helpful. Would you suggest how do I fix the image shape according to the shape of the state?

    • @tech-letters
      @tech-letters  2 года назад

      thank you :-) I do not quite understand. Do you want to have an image that covers a whole state?

  • @Lara15111988
    @Lara15111988 5 лет назад +1

    Great!!!

  • @tonynsx
    @tonynsx 4 года назад +1

    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?

    • @tech-letters
      @tech-letters  4 года назад

      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

  • @cristhiancastrochavez5962
    @cristhiancastrochavez5962 4 года назад +1

    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!

    • @tech-letters
      @tech-letters  4 года назад

      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?

    • @cristhiancastrochavez5962
      @cristhiancastrochavez5962 4 года назад

      @@tech-letters yes. Like make a binning .. Create rectangles or hexagons to grouping lat long points.

  • @henriquechaves618
    @henriquechaves618 4 года назад

    Thanks for the explanation!
    How can I write a number above the Marker(like a circle and a number inside it)?

  • @yanyangatot875
    @yanyangatot875 4 года назад +2

    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)

  • @rubayetalam8759
    @rubayetalam8759 2 года назад

    hey, can you tell me how to make a heat map with folium?

  • @bruhlickd
    @bruhlickd 2 года назад +1

    Hey, Is It possibile using python to see the tráfic lights in a city?

    • @tech-letters
      @tech-letters  2 года назад +1

      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?

  • @vinaysingh-rs8wx
    @vinaysingh-rs8wx 2 года назад +1

    hi what should i do if i want take input from user from map

    • @tech-letters
      @tech-letters  2 года назад +1

      Use Javascript / leaflet for dynamic maps. I have some videos about it in my list

  • @UniqueNeuralEnhancement
    @UniqueNeuralEnhancement Год назад

    Can we use folium with streamlit??

  • @bextla3737
    @bextla3737 2 года назад

    Nice tutorial, how to add this icon to legend?

  • @veerabhimanyusingh779
    @veerabhimanyusingh779 4 года назад +1

    videos are really helpful. upload videos for (google earth engine) foliumgee .

    • @tech-letters
      @tech-letters  4 года назад

      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 :-)

  • @prashantdave8269
    @prashantdave8269 5 лет назад +1

    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.

    • @tech-letters
      @tech-letters  5 лет назад +1

      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

    • @prashantdave8269
      @prashantdave8269 5 лет назад +1

      Will do.. Your videos should go long way. 👍🏻 will keep an eye on the new upcomings.

  • @snipehypeff1176
    @snipehypeff1176 Год назад +1

    hello please hepl me i want to create a map of my university . can this map work go that zoom?

    • @tech-letters
      @tech-letters  Год назад

      Unfortunately not. There is a maximum zoom with folium.

  • @terryterry1655
    @terryterry1655 2 года назад +1

    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.

    • @tech-letters
      @tech-letters  2 года назад

      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.

  • @bibekanandasahoo3497
    @bibekanandasahoo3497 Год назад

    sir how can we add http images

  • @_sig.discovery_8765
    @_sig.discovery_8765 Год назад +1

    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) 😭

    • @tech-letters
      @tech-letters  Год назад

      How the hell are you trying to install it? Are you using pip?

  • @Worldnme
    @Worldnme 4 года назад +1

    what if you want to use the current location of the user

    • @tech-letters
      @tech-letters  4 года назад

      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

  • @DON9701
    @DON9701 3 года назад +1

    nice video, learnt a lot for my project.
    i am trying to link all the marker to a single marker. Is it possible ?

    • @tech-letters
      @tech-letters  3 года назад

      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?

  • @karthikganjam296
    @karthikganjam296 4 года назад +1

    can i have full draggable marker program for folium in python

    • @tech-letters
      @tech-letters  4 года назад +1

      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

  • @mohababdellatif2878
    @mohababdellatif2878 5 лет назад +1

    When I enter pip install folium, it gives an error, most probably as the folium package is not in directory, how I add it?

    • @tech-letters
      @tech-letters  5 лет назад +1

      Can you copy and post the error here? That gives me a better chance to analyze it

    • @mohababdellatif2878
      @mohababdellatif2878 5 лет назад +1

      @@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

    • @tech-letters
      @tech-letters  5 лет назад +2

      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 :-(

  • @ViajeraViajando
    @ViajeraViajando 4 года назад

    Unable to include image :(

    • @SOFTDAS
      @SOFTDAS 4 года назад

      Same as mine (ノ﹏ヽ)

  • @adnanhashem6714
    @adnanhashem6714 3 года назад +1

    hello friend can you provide me with python library for cities i need it offline

    • @tech-letters
      @tech-letters  3 года назад

      Hi there, I am not aware of any library doing this that works offline :-(

  • @00hattan
    @00hattan 4 года назад +1

    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.....

    • @tech-letters
      @tech-letters  4 года назад +1

      Hi, I will check on Sunday evening, currently I do not have my laptop with me

    • @00hattan
      @00hattan 4 года назад +1

      Sure thank you so much...

    • @tech-letters
      @tech-letters  4 года назад

      @@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

    • @akshitakhatri7389
      @akshitakhatri7389 4 года назад

      @@tech-letters hi I am facing the same issue. did you get the solution now?

  • @cswor
    @cswor 4 года назад +1

    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.

    • @tech-letters
      @tech-letters  4 года назад

      are you getting any error message? How about installing it withoud anaconda in cmd with "pip install folium"?

    • @cswor
      @cswor 4 года назад

      @@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.

  • @3srtechnolearn945
    @3srtechnolearn945 4 года назад +1

    my py program is run but map is not show

    • @tech-letters
      @tech-letters  4 года назад

      are you getting any error? did you copy my code from github or did you start from scratch?

  • @paramjeetsingh5739
    @paramjeetsingh5739 4 года назад +1

    not able to install folium in python 3.7

    • @tech-letters
      @tech-letters  4 года назад

      Are you getting any error? Are you trying with pip or conda?

  • @swkaholic
    @swkaholic 4 года назад +1

    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?

    • @tech-letters
      @tech-letters  4 года назад +1

      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?

    • @swkaholic
      @swkaholic 4 года назад +1

      @@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.

    • @tech-letters
      @tech-letters  4 года назад +1

      @@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)

    • @swkaholic
      @swkaholic 4 года назад +1

      @@tech-letters Thanks! Do you have any idea how can i do it with javascript?

    • @tech-letters
      @tech-letters  4 года назад

      @@swkaholic yes, I will provide a code snippet by today evening or latest tomorrow

  • @MsRAJDIP
    @MsRAJDIP 4 года назад +1

    Hi can u help me to build a animation with time slider of multiple lat lon precipation data on uk map.

    • @tech-letters
      @tech-letters  4 года назад +1

      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.

    • @MsRAJDIP
      @MsRAJDIP 4 года назад +1

      @@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.

    • @MsRAJDIP
      @MsRAJDIP 4 года назад +1

      @@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.

    • @tech-letters
      @tech-letters  4 года назад +1

      @@MsRAJDIP Hi, you can send it to codeanddogs@gmail.com ... Tomorrow I would have some time to check&help

    • @MsRAJDIP
      @MsRAJDIP 4 года назад

      @@tech-letters
      Sure, thanks a lot 😊

  • @alexandraberger5182
    @alexandraberger5182 2 года назад +1

    Instead of Mapbox Bright which is not available anymore, in 2022 one can go for "cartodb positron" :)

    • @tech-letters
      @tech-letters  2 года назад

      that should work. I am mostly using openstreetmap nowadays

  • @stephanieomwanda8793
    @stephanieomwanda8793 3 года назад +1

    what if the data i have is polygon rather than point

    • @stephanieomwanda8793
      @stephanieomwanda8793 3 года назад +1

      do i just plot each point individually with their coordinates or is there a way i can go about it?

    • @tech-letters
      @tech-letters  3 года назад +1

      You can make use of folium.vector_layers.Polygon(locations). See here for details: python-visualization.github.io/folium/modules.html

    • @stephanieomwanda8793
      @stephanieomwanda8793 3 года назад

      @@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

  • @mialan5227
    @mialan5227 5 лет назад +1

    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.

    • @tech-letters
      @tech-letters  5 лет назад +1

      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.

    • @mialan5227
      @mialan5227 5 лет назад +1

      @@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?

    • @tech-letters
      @tech-letters  5 лет назад +1

      @@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 :-(

    • @mialan5227
      @mialan5227 5 лет назад +1

      @@tech-letters I see, still tons thanks for the help though.

    • @tech-letters
      @tech-letters  5 лет назад

      @@mialan5227 always welcome :-)

  • @varma9921
    @varma9921 4 года назад +1

    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'

    • @tech-letters
      @tech-letters  4 года назад +1

      have you installed folium with command "pip install folium" upfront?

    • @manvendrasingh5853
      @manvendrasingh5853 4 года назад

      @@tech-letters Hi! thank you for the tutorial. I am facing the same error.
      Although i have installed it using connda.

  • @ninobach7456
    @ninobach7456 6 месяцев назад +1

    Are you from germany?

  • @techmechstuff6630
    @techmechstuff6630 4 года назад +1

    I am not able to load tiles..

    • @tech-letters
      @tech-letters  4 года назад +1

      does it give you any error message or just a blank screen? are you using jupyter or a python script?

    • @techmechstuff6630
      @techmechstuff6630 4 года назад +1

      Just a blank screen

    • @techmechstuff6630
      @techmechstuff6630 4 года назад +1

      I am using jupyter notebook

    • @tech-letters
      @tech-letters  4 года назад

      @@techmechstuff6630 have you run "pip install folium" in cmd or installed it with anaconda on your PC upfront?

    • @cswor
      @cswor 4 года назад +1

      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.