26 kepler gl
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# !pip install leafmap
# !pip install leafmap
In [2]:
Copied!
import leafmap.kepler as leafmap
import leafmap.kepler as leafmap
Create an interactive map. You can specify various parameters to initialize the map, such as center
, zoom
, height
, and widescreen
.
In [3]:
Copied!
m = leafmap.Map(center=[40, -100], zoom=2, height=600, widescreen=False)
m
m = leafmap.Map(center=[40, -100], zoom=2, height=600, widescreen=False)
m
Save the map to an interactive html. To hide the side panel and disable map customization. Set read_only=False
In [4]:
Copied!
m.to_html(outfile="../html/kepler.html", read_only=False)
m.to_html(outfile="../html/kepler.html", read_only=False)
Display the interactive map in a notebook cell.
In [5]:
Copied!
# m.static_map(width=950, height=600, read_only=True)
# m.static_map(width=950, height=600, read_only=True)
Add a CSV to the map. If you have a map config file, you can directly apply config to the map.
In [6]:
Copied!
m = leafmap.Map(center=[37.7621, -122.4143], zoom=12)
in_csv = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/hex_data.csv"
config = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/hex_config.json"
m.add_csv(in_csv, layer_name="hex_data", config=config)
m
m = leafmap.Map(center=[37.7621, -122.4143], zoom=12)
in_csv = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/hex_data.csv"
config = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/hex_config.json"
m.add_csv(in_csv, layer_name="hex_data", config=config)
m
Save the map configuration as a JSON file.
In [7]:
Copied!
m.save_config("cache/config.json")
m.save_config("cache/config.json")
Save the map to an interactive html.
In [8]:
Copied!
m.to_html(outfile="../html/kepler_hex.html")
m.to_html(outfile="../html/kepler_hex.html")
Add a GeoJSON to the map.
In [9]:
Copied!
m = leafmap.Map(center=[20, 0], zoom=1)
lines = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/cable_geo.geojson"
m.add_geojson(lines, layer_name="Cable lines")
m
m = leafmap.Map(center=[20, 0], zoom=1)
lines = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/cable_geo.geojson"
m.add_geojson(lines, layer_name="Cable lines")
m
In [10]:
Copied!
m.to_html("../html/kepler_lines.html")
m.to_html("../html/kepler_lines.html")
Add a GeoJSON with US state boundaries to the map.
In [11]:
Copied!
m = leafmap.Map(center=[50, -110], zoom=2)
polygons = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/us_states.json"
m.add_geojson(polygons, layer_name="Countries")
m
m = leafmap.Map(center=[50, -110], zoom=2)
polygons = "https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/us_states.json"
m.add_geojson(polygons, layer_name="Countries")
m
In [12]:
Copied!
m.to_html("../html/kepler_states.html")
m.to_html("../html/kepler_states.html")
Add a shapefile to the map.
In [13]:
Copied!
m = leafmap.Map(center=[20, 0], zoom=1)
in_shp = "https://github.com/opengeos/leafmap/raw/master/examples/data/countries.zip"
m.add_shp(in_shp, "Countries")
m
m = leafmap.Map(center=[20, 0], zoom=1)
in_shp = "https://github.com/opengeos/leafmap/raw/master/examples/data/countries.zip"
m.add_shp(in_shp, "Countries")
m
In [14]:
Copied!
m.to_html("../html/kepler_countries.html")
m.to_html("../html/kepler_countries.html")
Add a GeoPandas GeoDataFrame to the map.
In [15]:
Copied!
import geopandas as gpd
import geopandas as gpd
In [16]:
Copied!
gdf = gpd.read_file(
"https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/world_cities.geojson"
)
gdf = gpd.read_file(
"https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/world_cities.geojson"
)
In [17]:
Copied!
gdf
gdf
Out[17]:
name | sov_a3 | latitude | longitude | pop_max | geometry | |
---|---|---|---|---|---|---|
0 | Bombo | UGA | 0.58330 | 32.53330 | 75000 | POINT (32.53330 0.58330) |
1 | Fort Portal | UGA | 0.67100 | 30.27500 | 42670 | POINT (30.27500 0.67100) |
2 | Potenza | ITA | 40.64200 | 15.79900 | 69060 | POINT (15.79900 40.64200) |
3 | Campobasso | ITA | 41.56300 | 14.65600 | 50762 | POINT (14.65600 41.56300) |
4 | Aosta | ITA | 45.73700 | 7.31500 | 34062 | POINT (7.31500 45.73700) |
... | ... | ... | ... | ... | ... | ... |
1244 | Rio de Janeiro | BRA | -22.92502 | -43.22502 | 11748000 | POINT (-43.22502 -22.92502) |
1245 | Sao Paulo | BRA | -23.55868 | -46.62502 | 18845000 | POINT (-46.62502 -23.55868) |
1246 | Sydney | AUS | -33.92001 | 151.18518 | 4630000 | POINT (151.18518 -33.92001) |
1247 | Singapore | SGP | 1.29303 | 103.85582 | 5183700 | POINT (103.85582 1.29303) |
1248 | Hong Kong | CHN | 22.30498 | 114.18501 | 7206000 | POINT (114.18501 22.30498) |
1249 rows × 6 columns
In [18]:
Copied!
m = leafmap.Map(center=[20, 0], zoom=1)
m.add_gdf(gdf, "World cities")
m
m = leafmap.Map(center=[20, 0], zoom=1)
m.add_gdf(gdf, "World cities")
m
In [19]:
Copied!
m.to_html("../html/kepler_cities.html")
m.to_html("../html/kepler_cities.html")