# Convert GADM.jl country file to GeoJSON.jl

**URL:** <https://discourse.julialang.org/t/convert-gadm-jl-country-file-to-geojson-jl/82654>\
**Category:** Geo\
**Tags:** question, package, plotting\
**Created:** [June 13, 2022, 3:07am UTC](https://discourse.julialang.org/t/convert-gadm-jl-country-file-to-geojson-jl/82654 "2022-06-13T03:07:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![alasaadstat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alasaadstat/32/975_2.png) [@alasaadstat](https://discourse.julialang.org/u/alasaadstat)\
**Post date:** [June 13, 2022, 3:07am UTC](https://discourse.julialang.org/t/convert-gadm-jl-country-file-to-geojson-jl/82654/1 "2022-06-13T03:07:48Z")

</div>

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

```julia
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

```

 ![Screen Shot 2022-06-13 at 11.08.45 AM](https://global.discourse-cdn.com/julialang/original/3X/8/e/8e2865991533b144c468f7fadaf50e479246dece.png)

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:

```julia
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.

---

<div class="post-metadata">

**Author:** ![joa-quim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joa-quim/32/227_2.png) [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Post date:** [June 13, 2022, 3:19am UTC](https://discourse.julialang.org/t/convert-gadm-jl-country-file-to-geojson-jl/82654/2 "2022-06-13T03:19:33Z")

</div>

Not GeoMakie but …

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

---

<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:** [June 13, 2022, 3:20am UTC](https://discourse.julialang.org/t/convert-gadm-jl-country-file-to-geojson-jl/82654/3 "2022-06-13T03:20:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alasaadstat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alasaadstat/32/975_2.png) [@alasaadstat](https://discourse.julialang.org/u/alasaadstat)\
**Post date:** [June 13, 2022, 4:07am UTC](https://discourse.julialang.org/t/convert-gadm-jl-country-file-to-geojson-jl/82654/4 "2022-06-13T04:07:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![alasaadstat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alasaadstat/32/975_2.png) [@alasaadstat](https://discourse.julialang.org/u/alasaadstat)\
**Post date:** [June 13, 2022, 4:11am UTC](https://discourse.julialang.org/t/convert-gadm-jl-country-file-to-geojson-jl/82654/5 "2022-06-13T04:11:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Balinus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/balinus/32/243_2.png) [@Balinus](https://discourse.julialang.org/u/Balinus)\
**Post date:** [March 30, 2023, 4:09pm UTC](https://discourse.julialang.org/t/convert-gadm-jl-country-file-to-geojson-jl/82654/6 "2023-03-30T16:09:00Z")

</div>

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

Cheers!

---

<div class="post-metadata">

**Author:** ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)\
**Post date:** [March 30, 2023, 4:31pm UTC](https://discourse.julialang.org/t/convert-gadm-jl-country-file-to-geojson-jl/82654/7 "2023-03-30T16:31:04Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![alasaadstat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alasaadstat/32/975_2.png) [@alasaadstat](https://discourse.julialang.org/u/alasaadstat)\
**Post date:** [April 1, 2023, 1:36am UTC](https://discourse.julialang.org/t/convert-gadm-jl-country-file-to-geojson-jl/82654/8 "2023-04-01T01:36:37Z")

</div>

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](https://github.com/alstat/BagyoData/tree/main/WP). Then I simply call these shapes in my package, [Bagyo.jl](https://github.com/alstat/Bagyo.jl), see this [line](https://github.com/alstat/Bagyo.jl/blob/d428cbfe6b9aca812291e4d5b42429c081781e35/src/constants.jl#L27). I then used GeoMakie and GeoInterface to plot these, see [here](https://github.com/alstat/Bagyo.jl/blob/master/src/vis.jl). Sample plot:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/c/bc559e60736ca2b5747c8c35d3bdaed6af707ab5.jpeg)

---

<div class="post-metadata">

**Author:** ![Balinus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/balinus/32/243_2.png) [@Balinus](https://discourse.julialang.org/u/Balinus)\
**Post date:** [April 5, 2023, 2:22pm UTC](https://discourse.julialang.org/t/convert-gadm-jl-country-file-to-geojson-jl/82654/9 "2023-04-05T14:22:55Z")

</div>

Nice map!

I will take a look. Thanks!!
