Search code examples
geolocationmapsgeospatialgeojsonfolium

Json file does not load on a folium map


I am working on creating a map with the demarcation of neighborhoods in the city of São Paulo through the folium.

For that I have a json file with all the neighborhoods in the link below:

https://github.com/DaniloPaula/TCC/blob/master/src/bairros_sp.json

So, I made the code below to get this json file and add it to the map

import json
import folium

bairros_sp = 'bairros_sp.json'
geo_json_data = json.load(open(bairros_sp))
mapa = folium.Map(width=600, height=400, location=[-23.5475, -46.63611], control_scale=True)
mapa

folium.GeoJson(geo_json_data,
               style_function=lambda feature: {
                              'fillColor': 'green',
                              'color': 'darkred',
                              'weight': 0.5,
}).add_to(mapa)
mapa

However, I don't have any changes to the map with the addition of the json file.

Can someone help me?

Thank you guys :)


Solution

  • To plot the data on a Folium map, you need to be sure your GeoJson file has the same Geographic coordinate system as Folium (EPSG: 4326). Add this code before folium.Map line.

    # check the coordinate system of your GeoJson file
    geo_json_data.crs 
    
    # and convert it to Folium's coordinate system
    geo_json_data = geo_json_data.to_crs(epsg=4326)