Search code examples
pythonpython-3.xpython-2.7folium

Folium Python points frames above the other demarcations


I need help I need I am trying to paint geolocation points in folium I have already extracted the coordinate column with the name of each neighborhood, the data is from geojson with the coordinates of the neighborhoods of Bogotá Colombia, the data is as follows: https://mapas.bogota.gov.co/?l=654&e=-74.1863908628869,4.563431330695553,-74.02159594101212,4.639403318876315,4686&b=7256&p=-74.10193346542607,4.615791272873822,4686# enter image description here

Then I pass it to the folium as follows:

# cargamos los puntos de cordenadas para las localidades de las ciudades
df_loc = pd.read_json("poligonos-localidades.json")
# cargamos los puntos de cordenadas para las barrios de las ciudad
with open('scat_geojson.geojson', encoding='utf-8-sig') as f:
    dct = json.load(f)
coord_barrios = dict()
coordenadas = []
for datos in dct['features']:
    coord_barrios.setdefault(correct, coordenadas)
    correct = datos['properties']['SCANOMBRE'].replace(" ", "_")
    for bar_coord in datos['geometry']['coordinates']:
        #coordenadas = []
        for p in bar_coord:
            for q in p:
                coordenadas.append(tuple(reversed(q)))
# creamos el objeto de mapa
mapObj = folium.Map(location=[4.6406458,-74.0613249],
                    zoom_start=10, tiles="Stamen Toner")
weight = 2

folium.PolyLine(coordenadas, color="Yellow", weight=weight).add_to(mapObj)
folium.LayerControl().add_to(mapObj)
mapObj

Now comes my problem and it is that when the data is mounted this happens:

enter image description here

It adds the points to me, but it puts them with lines crossing over the other points. It is supposed that I should only do the enclosing of the neighborhoods of the city of Bogotá.

I hope you can guide me, I thank you in advance, thank you very much.


Solution

  • To solve the previous question, do the following since folium has a package that is geojson which receives the .geojson and paints the polygons for us, easier code right away:

    loc_bog = gpd.read_file("dataset/localidades-bogota.geojson")
    style_loc = {'fillColor':"#ff000020", "color":"#000000"}
    loc_layer = folium.GeoJson(
        loc_bog,
        name = "Localidades",
        show=False,
        style_function=lambda x:style_loc,
        tooltip = folium.GeoJsonTooltip(
            fields=["LocCodigo","LocNombre"],
            aliases=["N°", "Nombre: "],
            localize = True
        )).add_to(mapObj)
    

    I hope someone helps