CartoDB/cartoframes

MultiPolygon Not Displaying in Layer

Closed this issue · 2 comments

from cartoframes.viz import Layer
from geopandas import read_file

df=read_file('https://services9.arcgis.com/6Hv9AANartyT7fJW/arcgis/rest/services/USCounties_cases_V1/FeatureServer/0/query?f=geojson&where=1%3D1&returnGeometry=true&spatialRel=esriSpatialRelIntersects&outSR=102100&cacheHint=true')

Layer(df, basic_style(opacity=0.5), geom_col='geometry', encode_data=False)

I get a map with no polygons being displayed on the map

Hi @kristinepetrosyan

CARTOframes layers expect the projection to be epsg:4326 an the CRS in your GeoDataFrame is epsg:3857. In order to convert it you need to remove null geometries and call to_crs:

gdf = gdf.dropna().to_crs(epsg=4326)

Then you can render the GeoDataFrame, you don't need to provide geom_col since it's a GeoDataFrame with a valid default geometry column, this is useful to render DataFrames with encoded geometries (like WKB, WKT, ...).

Layer(gdf, basic_style(opacity=0.5), encode_data=False)

NOTE: the size of the entire visualization is more than 60 MB. The map is rendered correctly but it could affect the performance. If you are interested in improving the performance and reducing the size of your notebook you can try creating a 1-year CARTO free account (https://carto.com/signup/), upload your GeoDataFrame and render directly from there. You can use all the SQL PostGIS functions too.

to_carto(gdf, 'my_table', credentials)
Layer('my_table', basic_style(opacity=0.5))