I am trying to generate a leaflet Choropleth map as in https://pypi.python.org/pypi/folium.
I am importing a shapefile as a geoDataframe which later on I am converting to a json file that I can input in the folium choropleth function. I am passing the geoframe.geometry field to the geo_path input and a specific geoframe.data to color out the different polygon coming as geometry.
I get this error:
'File "C:\Python27\lib\site-packages\folium\folium.py", line 606, in choropleth
geo_data = open(geo_path)
IOError: [Errno 2] No such file or directory: '{"type": "FeatureCollection", "features": [{"geometry": {"type": "Polygon", "coordinates": [[[-8719814.090035686,'
My code:
import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import style
import shapely as sh
import numpy as np
import random
import folium
lotes = gpd.read_file("shapefiles/reProj/Lotes_Datos_epsg3857_SM.shp")
lotes.crs = {'init' : 'epsg:3857'}
geoPath = lotes.geometry.to_json()
data1 = lotes.Area_Total.to_json()
mapa = folium.Map([0, -78], zoom_start=3, tiles='Stamen Toner',API_key='wrobstory.map-12345678')
mapa.choropleth(geo_path=geoPath, data=data1,
columns=['Lote', 'data1'],
key_on='feature.id',
fill_color='YlGn',
fill_opacity=0.7, line_opacity=0.2,
legend_name='data1')
mapa
mapa.save(outfile = 'shapefiles/reProj/test.html')
My coding level is beginner.
Any ideas?
shapefile: https://www.dropbox.com/s/ztvcr0qar4870ht/Lotes_Datos_epsg3857_SM.shp?dl=0
Best Answer
The first issue (There may be others) is that geo_path expects a file, you want geo_str, which just expects a string.