# How to filter geojson files?

**URL:** <https://discourse.julialang.org/t/how-to-filter-geojson-files/108599>\
**Category:** Visualization\
**Tags:** geo, makie, geomakie\
**Created:** [January 9, 2024, 11:55pm UTC](https://discourse.julialang.org/t/how-to-filter-geojson-files/108599 "2024-01-09T23:55:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![math4mad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/math4mad/32/49486_2.png) [@math4mad](https://discourse.julialang.org/u/math4mad)\
**Post date:** [January 9, 2024, 11:55pm UTC](https://discourse.julialang.org/t/how-to-filter-geojson-files/108599/1 "2024-01-09T23:55:12Z")

</div>

I just want to try `GeoMakie.jl` package

follow this page:  
csv :[economic-growth](https://ourworldindata.org/economic-growth)  
map:[geojson](https://datahub.io/core/geo-countries#resource-geo-countries_zip)

gdp.csv file include 173 countries and region , but geojson include 255 feature

how to alignment data ? how to fill color?

```Julia
#import package ....
path="./vis/data/countries.geojson"
json_str = read(path, String)
worldCountries = GeoJSON.read(json_str)
#n = length(worldCountries)

df=@pipe CSV.File("./vis/data/gdp-per-capita-penn-worldtable.csv")|>DataFrame
ys=2019
df=@chain df begin
   @clean_names
   @filter(year== !!ys)
   
end

lons = -180:180
lats = -90:90
field = [exp(cosd(l)) + 3(y/90) for l in lons, y in lats]

fig = Figure(size = (1200,800), fontsize = 22)

ax = GeoAxis(
    fig[1,1];
    dest="+proj=wintri",
    title = "World GDP",
    tellheight = true,
)

hm1 = surface!(ax, lons, lats, field)
translate!(hm1, 0, 0, -10)

hm2 = poly!(
    ax, worldCountries;
    color= ?,
    colormap = Reverse(:plasma),
    strokecolor = :black,
    strokewidth = 0.25
)

#fig

```

---

<div class="post-metadata">

**Author:** ![math4mad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/math4mad/32/49486_2.png) [@math4mad](https://discourse.julialang.org/u/math4mad)\
**Post date:** [January 12, 2024, 2:08am UTC](https://discourse.julialang.org/t/how-to-filter-geojson-files/108599/2 "2024-01-12T02:08:34Z")

</div>

finally solved this problem,  
actually it’s data problem , not plot problem

briefly routine is :

1. load geosjon and data
2. transform geojson to dataframe ,and just select column `ISO_A3`
3. cause geojso has 255 rows , and data just 178 rows, so we `@left_join(geo_df, df,"ISO_A3")`
4. fill missing gdp with zero :`@pipe df.gdp|>coalesce.(_, 0)`
5. plot map

```Julia

## 1. load package 
using Makie, CairoMakie, GeoMakie
import Downloads
using GeoMakie.GeoJSON
using GeometryBasics
using GeoMakie.GeoInterface
using CSV,DataFrames, Tidier,Pipe
using StatsBase

## 2. load geojson 
path="./vis/plots-gallery-data/countries.geojson"
json_str = read(path, String)
worldCountries = GeoJSON.read(json_str)
n = length(worldCountries)
geo_df = @chain DataFrame(worldCountries) @select(ISO_A3)

## 3. load gdp data
df=@pipe CSV.File("./vis/plots-gallery-data/gdp-per-capita-penn-world-table.csv")|>DataFrame|>transform(_,"GDP per capita (output, multiple price benchmarks)"=>"gdp")|>select(_,Not("GDP per capita (output, multiple price benchmarks)"))
ys=2019
df=@chain df begin
   @clean_names
   @filter(year== !!ys)
   @rename(ISO_A3=code)
 end

## 4. join dataframes by "ISO_A3"
df=@left_join(geo_df, df,"ISO_A3")
df.gdp=@pipe df.gdp|>coalesce.(_, 0)

## 5. plot map 
lons = -180:180
lats = -90:90
field = [exp(cosd(l)) + 3(y/90) for l in lons, y in lats]
n,_=size(df)

function plot_map()
    fig = Figure(size = (1200,800), fontsize = 22)

ax = GeoAxis(
    fig[1,1];
    dest="+proj=wintri",
    title = "World GDP",
    tellheight = true,
)

hm1 = surface!(ax, lons, lats, field)
translate!(hm1, 0, 0, -10)

hm2 = poly!(
    ax, worldCountries;
    color=df.gdp,
    colormap = Reverse(:plasma),
    strokecolor = :black,
    strokewidth = 0.25
)
cb = Colorbar(fig[1,2]; colorrange = (1, n), colormap = Reverse(:plasma), label = "variable, color code", height = Relative(0.65))
fig
end
plot_map()

```

 ![display](https://global.discourse-cdn.com/julialang/original/3X/6/d/6d829dcf34cee2597cf6d9c37937bd61731745bb.png)
