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 = “https://raw.githubusercontent.com/meherGill/geojson_suburbs/main/suburbsModified.geojson
geomap = choropleth(DataFrame(Postal = [“2603”,“2604”,“2605”]);geojson = link, locations=“Postal”, featureidkey = “properties.id”)
plot(geomap,Layout(landcolor=“#F0DC82”))

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))
end

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

filename

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",
    projection=attr(type="eckert4",scale=0.9,rotation=attr(roll=2)),
    lonaxis=attr(range=[-15,60], showgrid=true),
    lataxis=attr(range=[35,72], showgrid=true),
    resolution="50", # alt. "110" or "50", in km/mm
    showland=true,
    showocean=true,
    oceancolor="rgb$(Colors.color_names["lightskyblue2"])",
    lakecolor="rgb$(Colors.color_names["lightsteelblue"])",
    landcolor="rgb$(Colors.color_names["lightgrey"])",
    countrycolor="rgb$(Colors.color_names["darkblue"])",
    countrywidth=1,
    subunitwidth=1,
)
layout = Layout(;title="Europe Levels", showlegend=false, geo=geo)
plot(scattergeo(), layout)

1 Like