Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Erro no Choropleth (relacionado em CRS)

---------------------------------------------------------------------------
CRSError                                  Traceback (most recent call last)
<ipython-input-192-bf1be4a3d3a5> in <module>
      1 base = folium.Map([y,x], zoom_start=11, tiles='OpenStreetMap')
----> 2 folium.Choropleth(rj).add_to(base)
      3 base

~\anaconda3\lib\site-packages\folium\features.py in __init__(self, geo_data, data, columns, key_on, bins, fill_color, nan_fill_color, fill_opacity, nan_fill_opacity, line_color, line_weight, line_opacity, name, legend_name, overlay, control, show, topojson, smooth_factor, highlight, **kwargs)
   1287                 smooth_factor=smooth_factor)
   1288         else:
-> 1289             self.geojson = GeoJson(
   1290                 geo_data,
   1291                 style_function=style_function,

~\anaconda3\lib\site-packages\folium\features.py in __init__(self, data, style_function, highlight_function, name, overlay, control, show, smooth_factor, tooltip, embed, popup, zoom_on_click, marker)
    497         self.marker = marker
    498 
--> 499         self.data = self.process_data(data)
    500 
    501         if self.style or self.highlight:

~\anaconda3\lib\site-packages\folium\features.py in process_data(self, data)
    539             self.embed = True
    540             if hasattr(data, 'to_crs'):
--> 541                 data = data.to_crs('EPSG:4326')
    542             return json.loads(json.dumps(data.__geo_interface__))
    543         else:

~\anaconda3\lib\site-packages\geopandas\geodataframe.py in to_crs(self, crs, epsg, inplace)
    532         else:
    533             df = self.copy()
--> 534         geom = df.geometry.to_crs(crs=crs, epsg=epsg)
    535         df.geometry = geom
    536         df.crs = geom.crs

~\anaconda3\lib\site-packages\geopandas\geoseries.py in to_crs(self, crs, epsg)
    407 
    408         # skip transformation if the input CRS and output CRS are the exact same
--> 409         if _PYPROJ_VERSION >= LooseVersion("2.1.2") and pyproj.CRS.from_user_input(
    410             self.crs
    411         ).is_exact_same(pyproj.CRS.from_user_input(crs)):

~\anaconda3\lib\site-packages\pyproj\crs\crs.py in from_user_input(value, **kwargs)
    464         Parameters
    465         ----------
--> 466         proj_dict : str
    467             PROJ params in dict format.
    468 

~\anaconda3\lib\site-packages\pyproj\crs\crs.py in __init__(self, projparams, **kwargs)
    311 
    312         Returns
--> 313         -------
    314         CRS
    315         """

pyproj\_crs.pyx in pyproj._crs._CRS.__init__()

CRSError: Invalid projection: +init=epsg:4326 +type=crs: (Internal Proj Error: proj_create: no database context specified)

Meu pyproj está na versão '3.1.0'.

1 resposta
solução!

Oii Igor, como você está?

Peço desculpas pela demora em obter um retorno.

Pelo log de erro algum problema de inconsistência foi encontrado ao tentar fazer a conversão para o CRS 4326 e uma das razões é que desde o lançamento do curso até a data atual a forma apresentada de converter o CRS se tornou obsoleta e será removida em versões futuras da biblioteca.

A forma antiga era como mostro a seguir:

crs = {'init': 'epsg:4326'}
rj.to_crs(crs, inplace = True)

Porém, tente fazer da seguinte forma:

rj =rj.to_crs(epsg=4326)

Após essa correção tente executar novamente.

Deixo abaixo o código completo desta aula:

%matplotlib inline
import pandas as pd
import geopandas as gpd
import folium

rj = gpd.read_file('../01.Dados/Mapas/RJ-MUNIC/RJ-MUNIC.shp')
geo_dados = gpd.read_file('../01.Dados/Mapas/RJ-DATASET/DATASET.shp')
setor = gpd.read_file('../01.Dados/Mapas/RJ-SETOR/RJ-SETOR.shp')
bairro = gpd.read_file('../01.Dados/Mapas/RJ-BAIRRO/RJ-BAIRRO.shp')

setor = setor.fillna(0)

rj =rj.to_crs(epsg=4326)
print(rj.crs)
rj.head()

rj = rj.to_crs(epsg=32723)

valores_centroid = rj.centroid.to_crs(epsg=4326)
valores_centroid

x = valores_centroid.x.iloc[0]
y = valores_centroid.y.iloc[0]
x, y


rj = rj.to_crs(epsg=4326)
rj

base = folium.Map([y,x], zoom_start=11, tiles='OpenStreetMap')
folium.Choropleth(rj).add_to(base)
base

Qualquer dúvida estou por aqui.

Grande abraço e bons estudos!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software