# \[ANN\] KeplerGL.jl: Geospatial Visualization via Kepler.gl

**URL:** <https://discourse.julialang.org/t/ann-keplergl-jl-geospatial-visualization-via-kepler-gl/108040>\
**Category:** Package Announcements\
**Tags:** visualization, geo, blink\
**Created:** [December 25, 2023, 4:56pm UTC](https://discourse.julialang.org/t/ann-keplergl-jl-geospatial-visualization-via-kepler-gl/108040 "2023-12-25T16:56:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmboehm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmboehm/32/2263_2.png) [@jmboehm](https://discourse.julialang.org/u/jmboehm)\
**Post date:** [December 25, 2023, 4:56pm UTC](https://discourse.julialang.org/t/ann-keplergl-jl-geospatial-visualization-via-kepler-gl/108040/1 "2023-12-25T16:56:55Z")

</div>

Dear all,

Following some merry christmas hacking, I’m happy to announce a prototype of [KeplerGL.jl](https://github.com/jmboehm/KeplerGL.jl), a package to provide an interface to the javascript library [Kepler.gl](https://kepler.gl/).

 ![sf](https://global.discourse-cdn.com/julialang/original/3X/2/8/28d3875e2feaabf155b7f18fa4902bc3c2f8eb45.png)

Kepler.gl provides an easy-to-use platform to produce interactive maps: you drag & drop some CSV, JSON, or GeoJSON files into the browser window, click a few butttons to create point, line, hexbin, or polygon layers, and export your maps via html or png. It’s really very intuitive, fast, and looks terrific.

While this interactive way of creating maps is very convenient for quick inspections of geodata, it also makes it difficult to integrate into a code-based workflow. This is where the [KeplerGL.jl](https://github.com/jmboehm/KeplerGL.jl) Julia package comes in. It provides an interface to create the map layers via Julia code; the package then creates a html/javascript page that is then shown in a browser window via Blink.jl (and the Kepler.gl javascript libraries). Finally you can call a function to export static png’s. For example, the above visualization of building footprints in San Francisco is [a couple of lines of code](https://jmboehm.github.io/KeplerGL.jl/dev/examples/#Polygon:-Building-Footprints-of-San-Francisco).

Here’s how to create a simple but good-looking point map:

```julia
using KeplerGL, CSV, Colors, ColorBrewer, DataFrames

token = "<INSERT MAPBOX TOKEN HERE>"

m = KeplerGL.KeplerGLMap(token)
df = CSV.read("assets/example_data/data.csv", DataFrame)
KeplerGL.add_point_layer!(m, df, :Latitude, :Longitude,
    color = colorant"rgb(23,184,190)", color_field = :Magnitude, 
    color_scale = "quantize", 
    color_range = ColorBrewer.palette("PRGn", 6),
    radius_field = :Magnitude, radius_scale = "sqrt", 
    radius_range = [4.2, 96.2], radius_fixed = false,
    filled = true, opacity = 0.39, outline = false);
KeplerGL.render(m)

```

 ![earthquakes](https://global.discourse-cdn.com/julialang/original/3X/f/7/f768e61f7f4fea8d5a2ac9050cfae0ab959d141a.png)

At this point there are probably plenty of bugs, and the package is not feature-complete. I hope to implement at least support for all layer types that are in Kepler.gl. I’m not very familiar with Julia’s Geo ecosystem and am therefore probably not going to provide direct support for this myself, but (if there’s demand) I’m happy to merge PRs as long as the usability for non-expert users (“I have some lat/lon coordinates in a vector and want to splash this on a map”) is not affected.

Barring the discovery of some disastrous bugs, I’ll register the package in the next couple of days.

Comments and bug reports are very welcome. Thanks!

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [December 25, 2023, 6:06pm UTC](https://discourse.julialang.org/t/ann-keplergl-jl-geospatial-visualization-via-kepler-gl/108040/2 "2023-12-25T18:06:06Z")

</div>

Very nice! It would be interesting to experiment with this visualization stack in parallel to the Makie.jl stack. How would you reproduce the examples in the book using the Kepler API:

[https://juliaearth.github.io/geospatial-data-science-with-julia/02-geoviz.html](https://juliaearth.github.io/geospatial-data-science-with-julia/02-geoviz.html)

---

<div class="post-metadata">

**Author:** ![jmboehm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmboehm/32/2263_2.png) [@jmboehm](https://discourse.julialang.org/u/jmboehm)\
**Post date:** [December 25, 2023, 8:32pm UTC](https://discourse.julialang.org/t/ann-keplergl-jl-geospatial-visualization-via-kepler-gl/108040/3 "2023-12-25T20:32:48Z")

</div>

Kepler.gl can process GeoJSONs natively, but my interface doesn’t quite support it yet, so it’s a bit more cumbersome:

```julia
using KeplerGL, Colors, DataFrames, JSON3

token = "..."

# process GeoJSON
t = JSON3.read("geotable.geojson")
df = DataFrame(:geometry => string.(t[:features]))
df.colval = [1,2,3,4]

col = parse.(Colorant,["#450154", "#2f688e", "#37b679", "#fee724"])

m = KeplerGLMap(token)
KeplerGL.add_polygon_layer!(m, df, :geometry,
    color_field = :colval, color_range = col)

# lines
# seg = [Segment((-40, -10), (0, 0)), Segment((-40, 0), (-20, 10))]
df_lines = DataFrame(:orig_lon => [-40.0, -40.0], :orig_lat => [-10.0, 0.0],
    :dest_lon => [0.0, -20.0], :dest_lat => [0.0, 10.0],
    :color => [1, 4])

KeplerGL.add_line_layer!(m, df_lines, :orig_lat, :orig_lon, :dest_lat, :dest_lon,
    color_field = :color, color_range = col)

# points
# pts = [Point(-20, -10), Point(-20, 0), Point(-40, 10)]
df_points = DataFrame(:lat => [-10.0, 0.0, 10.0], :lon => [-20.0, -20.0, -40.0], :col => [1,2,3])
KeplerGL.add_point_layer!(m, df_points, :lat, :lon,
    color_field = :col, color_range = col, radius = 10.0)

# render
KeplerGL.render(m)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/5/b52a5e0853786e5b1340ad65274ed7ee68654b32.png)

---

<div class="post-metadata">

**Author:** ![jmboehm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmboehm/32/2263_2.png) [@jmboehm](https://discourse.julialang.org/u/jmboehm)\
**Post date:** [January 1, 2024, 1:54pm UTC](https://discourse.julialang.org/t/ann-keplergl-jl-geospatial-visualization-via-kepler-gl/108040/4 "2024-01-01T13:54:56Z")

</div>

The package is now registered; to install type

```julia
] add KeplerGL

```

At this point all layer types that are supported by Kepler.gl 2.5.5 are implemented (except S2 layers; I don’t think there is a package to work with [S2](http://s2geometry.io/) in Julia). The docs are in a decent state. The interface regarding map options could (and probably will) be improved, but I think the package is ready to be let out into the wild.
