Convert GADM.jl country file to GeoJSON.jl

Hi, I would like to convert the loaded GADM.jl country polygon file to GeoJSON.jl so that I can plot this using GeoMakie.jl. I am aware that MeshViz.jl supports well the GADM.jl, but I would like to customize the plot and hence I want to use GeoMakie.jl. From the examples in GeoMakie.jl and the GeoPlots of BeautifulMakie, most of them load GeoJSON file from some links hosting the file, and this is what I follow at the moment. Example

using CairoMakie
using Colors
using GeoMakie
using GeoJSON
using Downloads
ph_geojson = "https://raw.githubusercontent.com/faeldon/philippines-json-maps/master/geojson/country/lowres/country.0.001.json";
phmap = Downloads.download(ph_geojson);
geo = GeoJSON.read(read(phmap, String));
geo
function plotPH()
	fig = Figure(resolution = (1050, 800), fontsize = 22);
	ax = GeoAxis(fig[1, 1], dest="+proj=gall +lon_0=150 +lat_0=10",
		lonlims=(100, 200), latlims=(-5, 60), coastlines=true, 
		coastline_attributes=(color=:black, linewidth=0.35, fill=:black))
	poly!(ax, geo, color=colorant"#85754e",
		strokecolor = :black, strokewidth = 0.35)
	colsize!(fig.layout, 1, Aspect(1, 2.0))
	fig
end

I would like to change the code above and use the shapefile from GADM.jl for plotting the country above. Is it possible? I know I can get the coordinates of the country as follows:

using GADM
ph = GADM.coordinates("PHL")

But I don’t know how to proceed to convert this to GeoJSON file and plot it like the one above.

I should emphasize though that I am not a Geographer, and I apologize for my basic understanding.

Not GeoMakie but …

https://www.generic-mapping-tools.org/GMT.jl/dev/gallery/GADM/gadm/

1 Like

GADM.jl returns a table with geometries that follow the GeoInterface.jl so you shouldn’t need to convert to GeoJSON.jl if I am not mistaken. If you want to use MeshViz.jl then you probably want GeoTables.jl instead to load the GeoInterface.jl geometries as Meshes.jl geometries, which are Julia geometries with a more rich set of functions.

Notice that MeshViz.jl is just a set of Makie recipes, that means that you can customize the axis and plots the same way you would with GeoMakie.jl or any Makie set of recipes.

1 Like

Thanks @joa-quim, I have indeed used GMT.jl in one of my paper (currently under review), and it was easy to setup, but this time I prefer to try out GeoMakie.jl.

Thanks @juliohm, I did try to look into the codes of MeshViz.jl, I’m still trying to understand it and hoping to reuse part of it for my codes.

If you found a solution, please post it, I would be happy to reuse such a solution!

Cheers!

We have GeoInterfaceMakie.jl now, probably someone just needs a dependency on it in ArchGDAL.

So you don’t need to convert to GeoJSON to plot, but if you want GeoJSON you can convert any GeoInterface geometries to GeoJSON with GeoInterface.convert(GeoJSON, geom)

Probably the best thing for now is getting GeometryBasics geometries with GeoInterface.convert(GeometryBasics, geom) and those will plot natively in Makie.

(Yes this is an internal GeoInterface.jl convert method, and it converts to the package as well as the type, so you don’t need to know the package geometry types)

1 Like

Hi @Balinus, I decided not to use GADM.jl for my base map and then convert it to GeoJSON. Instead, I skipped that process, and simply created GeoJSON files for the maps I want to plot, and saved it in my repo here. Then I simply call these shapes in my package, Bagyo.jl, see this line. I then used GeoMakie and GeoInterface to plot these, see here. Sample plot:

2 Likes

Nice map!

I will take a look. Thanks!!