Skip to content

kepler module

leafmap.kepler

Map

Bases: KeplerGl

The Map class inherits keplergl.KeperGl.

Returns:

Name Type Description
object

keplergl.KeperGl map object.

add_csv(in_csv, layer_name='Untitled', config=None, **kwargs)

Adds a CSV to the map.

Parameters:

Name Type Description Default
in_csv str

File path to the CSV.

required
layer_name str

The layer name to be used.. Defaults to "Untitled".

'Untitled'
config str

Local path or HTTP URL to the config file. Defaults to None.

None

add_df(df, layer_name='Untitled', config=None, **kwargs)

Adds a DataFrame to the map.

Parameters:

Name Type Description Default
df DataFrame

A Pandas DataFrame.

required
layer_name str

The layer name to be used.. Defaults to "Untitled".

'Untitled'
config str

Local path or HTTP URL to the config file. Defaults to None.

None

add_gdf(gdf, layer_name='Untitled', config=None, **kwargs)

Adds a GeoDataFrame to the map.

Parameters:

Name Type Description Default
gdf GeoDataFrame

A GeoPandas GeoDataFrame.

required
layer_name str

The layer name to be used.. Defaults to "Untitled".

'Untitled'
config str

Local path or HTTP URL to the config file. Defaults to None.

None

add_gdf_from_postgis(sql, con, layer_name='Untitled', config=None, **kwargs)

Reads a PostGIS database and returns data as a GeoDataFrame to be added to the map.

Parameters:

Name Type Description Default
sql str

SQL query to execute in selecting entries from database, or name of the table to read from the database.

required
con Engine

Active connection to the database to query.

required
layer_name str

The layer name to be used.. Defaults to "Untitled".

'Untitled'
config str

Local path or HTTP URL to the config file. Defaults to None.

None

add_geojson(in_geojson, layer_name='Untitled', config=None, **kwargs)

Adds a GeoJSON file to the map.

Parameters:

Name Type Description Default
in_geojson str | dict

The file path or http URL to the input GeoJSON or a dictionary containing the geojson.

required
layer_name str

The layer name to be used.. Defaults to "Untitled".

'Untitled'
config str

Local path or HTTP URL to the config file. Defaults to None.

None

Raises:

Type Description
FileNotFoundError

The provided GeoJSON file could not be found.

TypeError

The input geojson must be a type of str or dict.

add_kml(in_kml, layer_name='Untitled', config=None, **kwargs)

Adds a KML file to the map.

Parameters:

Name Type Description Default
in_kml str

The input file path to the KML.

required
layer_name str

The layer name to be used.. Defaults to "Untitled".

'Untitled'
config str

Local path or HTTP URL to the config file. Defaults to None.

None

Raises:

Type Description
FileNotFoundError

The provided KML file could not be found.

add_shp(in_shp, layer_name='Untitled', config=None, **kwargs)

Adds a shapefile to the map.

Parameters:

Name Type Description Default
in_shp str

The input file path to the shapefile.

required
layer_name str

The layer name to be used.. Defaults to "Untitled".

'Untitled'
config str

Local path or HTTP URL to the config file. Defaults to None.

None

Raises:

Type Description
FileNotFoundError

The provided shapefile could not be found.

add_vector(filename, layer_name='Untitled', config=None, **kwargs)

Adds any geopandas-supported vector dataset to the map.

Parameters:

Name Type Description Default
filename str

Either the absolute or relative path to the file or URL to be opened, or any object with a read() method (such as an open file or StringIO).

required
layer_name str

The layer name to use. Defaults to "Untitled".

'Untitled'
config str

Local path or HTTP URL to the config file. Defaults to None.

None

load_config(config=None)

Loads a kepler.gl config file.

Parameters:

Name Type Description Default
config str

Local path or HTTP URL to the config file. Defaults to None.

None

Raises:

Type Description
FileNotFoundError

The provided config file could not be found.

TypeError

The provided config file is not a kepler.gl config file.

save_config(out_json)

Saves a kepler.gl config file.

Parameters:

Name Type Description Default
out_json str

Output file path to the config file.

required

Raises:

Type Description
ValueError

The output file extension must be json.

TypeError

The provided filepath is invalid.

static_map(width=950, height=600, read_only=False, out_file=None, **kwargs)

Display a kepler.gl static map in a Jupyter Notebook.

Args width (int, optional): Width of the map. Defaults to 950. height (int, optional): Height of the map. Defaults to 600. read_only (bool, optional): Whether to hide the side panel to disable map customization. Defaults to False. out_file (str, optional): Output html file path. Defaults to None.

to_html(outfile=None, read_only=False, **kwargs)

Saves the map as a HTML file.

Parameters:

Name Type Description Default
outfile str

The output file path to the HTML file.

None
read_only bool

Whether to hide the side panel to disable map customization. Defaults to False.

False

to_streamlit(width=800, height=600, responsive=True, scrolling=False, **kwargs)

Renders keplergl.KeplerGl map figure in a Streamlit app.

Parameters:

Name Type Description Default
width int

Width of the map. Defaults to 800.

800
height int

Height of the map. Defaults to 600.

600
responsive bool

Whether to make the map responsive. Defaults to True.

True
scrolling bool

If True, show a scrollbar when the content is larger than the iframe. Otherwise, do not show a scrollbar. Defaults to False.

False

Raises:

Type Description
ImportError

If streamlit is not installed.

Returns:

Type Description

streamlit.components: components.html object.