Shapes from geojson on geo map with Plotly

I want to plot a geojson with multiple geojsons as a geo map with Plotly. I tried to convert an existing Python example to Julia but without success. The code below is just one example and I’ve also tested the same structure with different geojsons or not setting featureidkey. One thing I noticed was that the Julia documentation on choropleth does not mention a color option which is usually set in Python.

using PlotlyJS, DataFrames

link = “
geomap = choropleth(DataFrame(Postal = [“2603”,“2604”,“2605”]);geojson = link, locations=“Postal”, featureidkey = “”)

For context: As I’ve explained in a previous post, I want to change the projection of the resulting map. Therefore, creating a mapbox map is unfortunately not an option. I’ve also noticed that there are other packages for plotting shapes in Julia but none of them seem well maintained and offer the same range of formatting options.

What is the problem with GMT.jl? Anything that I can help or, perhaps, improve?

I want the function to be part of a package and therefore dependence on an external tool is a problem unfortunately.

Realized the best way is to write a function myself. The code below uses the Proj package to translate lat/lon in x/y coordinates for different projections. Then I create shapes for plotting with Plots.

using Plots, JSON, Proj
u = “country”
getShp_json = JSON.parsefile(u * “.geojson”)

trans = Proj.Transformation(“EPSG:4326”, “+proj=eck4 +axis=neu”)

allShp_arr = Plots.Shape

for shp in collect(values(getShp_json[“features”])), subShp in shp[“geometry”][“coordinates”], subSubShp in subShp
shp_arr = map(z → trans(z[1], z[2]), subSubShp)
push!(allShp_arr, Plots.Shape(shp_arr))

Plots.plot(allShp_arr,ticks = false, axis = false, legend = false, color = “#d9d9d9”)


Just for comparison. This is one way of doing it with GMT

coast(DCW=(name=:UN150, pen=0.5, fill=:gray70), region=(-12,45,35,75),
         proj="eck4", frame=:none, show=true)

You can do something very similar entirely within PlotlyJS (Colors is just used for convenience):

using PlotlyJS
using Colors

geo = attr(scope="europe",
    lonaxis=attr(range=[-15,60], showgrid=true),
    lataxis=attr(range=[35,72], showgrid=true),
    resolution="50", # alt. "110" or "50", in km/mm
layout = Layout(;title="Europe Levels", showlegend=false, geo=geo)
plot(scattergeo(), layout)

1 Like