Skip to content

Commit

Permalink
Merge pull request #125 from MakieOrg/jeremiahpslewis-jpsl/geojson-0.6
Browse files Browse the repository at this point in the history
Jeremiahpslewis jpsl/geojson 0.6
  • Loading branch information
SimonDanisch authored Sep 21, 2022
2 parents 99ff4de + 045a340 commit 27c708a
Show file tree
Hide file tree
Showing 19 changed files with 237 additions and 214 deletions.
33 changes: 9 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
tags: '*'
jobs:
test:
name: Tests, Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
name: Tests, Julia ${{ matrix.version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -34,19 +34,7 @@ jobs:
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- name: Install custom deps
run: |
julia --project=@. -e 'using Pkg;pkg"add Makie#master CairoMakie#master GLMakie#master MakieCore#master ImageMagick"'
- uses: actions/cache@v1
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: actions/upload-artifact@v3
Expand All @@ -57,8 +45,6 @@ jobs:
docs:
name: Build and deploy documentation
runs-on: ubuntu-latest
if: always()
needs: test
steps:
- name: Install binary dependencies
run: sudo apt-get update && sudo apt-get install -y xorg-dev mesa-utils xvfb libgl1 freeglut3-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev libxext-dev
Expand All @@ -67,14 +53,13 @@ jobs:
uses: actions/download-artifact@v3
- uses: julia-actions/setup-julia@latest
with:
version: '1.6'
- name: Install custom deps
run: |
julia --project=@. -e 'using Pkg;pkg"add Makie#master MakieCore#master CairoMakie#master GLMakie#master"'
- name: Install dependencies
run: |
julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); pkg"add Makie#master MakieCore#master CairoMakie#master GLMakie#master"; Pkg.instantiate()'
julia --project=docs/ -e 'using CairoMakie'
version: '1'
- uses: julia-actions/cache@v1
- run: |
julia --project=docs -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # If authenticating with GitHub Actions token
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ stuff.jl
src/oldsrc
src/experimental

docs/src/images
test_images/
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
Colors = "0.12"
Downloads = "1"
GeoInterface = "0.5, 1.0"
GeoJSON = "0.5"
GeometryBasics = "0.4.1"
GeoJSON = "0.6"
GeometryBasics = "0.4.4"
ImageIO = "0.6"
Makie = "0.17.1"
Proj = "1.0"
Expand Down
7 changes: 3 additions & 4 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
GeoJSON = "61d90e0f-e114-555e-ac52-39dfb47a3ef9"
GeoMakie = "db073c08-6b98-4ee5-b6a4-5efafb3259c6"
# Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
# GraphMakie = "1ecd5474-83a3-4783-bb4f-06765db800d2"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
# LightOSM = "d1922b25-af4e-4ba3-84af-fe9bea896051"
# OSMMakie = "76b6901f-8821-46bb-9129-841bc9cfe677"

[compat]
Documenter = "0.27"
80 changes: 41 additions & 39 deletions docs/generate_examples.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Generate examples.md, which holds a lot of the examples
using Base64

example_title_pairs = [
"Contourf" => "contourf.jl",
Expand All @@ -12,51 +11,54 @@ example_title_pairs = [
"GraphMakie with GeoMakie" => "graph_on_usa.jl",
]

io = open(joinpath("docs", "src", "examples.md"), "w")
example_path(files...) = abspath(joinpath(@__DIR__, "..", "examples", files...))
doc_src(files...) = abspath(joinpath(@__DIR__, "src", files...))

assetpath = mkpath(joinpath("docs", "src", "assets"))
if !isdir(doc_src("images"))
mkpath(doc_src("images"))
end

for ext in example_title_pairs
open(doc_src("examples.md"), "w") do io

title = first(ext)
example = last(ext)
for ext in example_title_pairs
title = first(ext)
example = last(ext)

filepath = joinpath("examples", example)
filepath = example_path(example)
!isfile(filepath) && continue
println("Including example: $(filepath)")
name = splitext(example)[1] * ".png"
img = doc_src("images", name)

!isfile(filepath) && continue
println(" running example!")
include(filepath)
CairoMakie.save(img, Makie.current_figure(); px_per_unit=2)

test_image_dir = "test_images"
base64data = Base64.base64encode(read(joinpath(test_image_dir, splitext(example)[1] * ".png")))
cp(joinpath(test_image_dir, splitext(example)[1] * ".png"), joinpath(assetpath, splitext(example)[1]*".png"))
println(io, "## $title")
println()
println(io, "```julia")
println(io, readchomp(filepath))
println(io, "```\n")
println(io, "![$title](images/$name)")
println(io)
end

println(io, "## $title")
println()
println(io, "```julia")
println(io, readchomp(filepath))
println(io, "```\n")
println(io, "```@raw html")
println(io, "<img src=\"$(joinpath("..", "assets", splitext(example)[1]*".png"))\" alt=\"$title\"></img>") # data:image/png;base64,$(base64data)\
println(io, "```\n")

end
# Special case for rotating Earth
# since we want a slow video, but
# the generated one would be quite fast.
println(io, "## Rotating Earth")

println(io, "```julia\n$(read(example_path("rotating_earth.jl"), String))\n```\n")
println(io,
"""
```@raw html
<video controls autoplay loop>
<source src="https://user-images.githubusercontent.com/32143268/165003843-db5984f0-9ccf-49f7-847e-88fd63e80bb4.mp4" type="video/mp4">
Your browser does not support this video.
</video>
```
""")

# Special case for rotating Earth
# since we want a slow video, but
# the generated one would be quite fast.
println(io, "## Rotating Earth")

println(io, "```julia\n$(read(joinpath("examples", "rotating_earth.jl"), String))\n```\n")
println(io,
"""
```@raw html
<video controls autoplay loop>
<source src="https://user-images.githubusercontent.com/32143268/165003843-db5984f0-9ccf-49f7-847e-88fd63e80bb4.mp4" type="video/mp4">
Your browser does not support this video.
</video>
```
"""
)
println()

close(io)
println(io)
end
6 changes: 4 additions & 2 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Documenter, GeoMakie
using Documenter, GeoMakie, CairoMakie
CairoMakie.activate!()

# invoke some geomakie things to be sure
GeoMakie.coastlines()
Expand All @@ -21,6 +22,7 @@ makedocs(;
"Examples" => "examples.md"
],
sitename="GeoMakie.jl",
authors="Makie.jl contributors")
authors="Makie.jl contributors",
strict=true)

deploy && deploydocs(; repo="github.com/MakieOrg/GeoMakie.jl", target="build", push_preview=true)
18 changes: 12 additions & 6 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ You can install it from the REPL like so:
## GeoAxis
Using GeoMakie.jl is straightforward, although it does assume basic knowledge of the Makie.jl ecosystem.

GeoMakie.jl provides an axis for plotting geospatial data, [`GeoAxis`](@ref), and also the function [`geo2basic`](@ref) that converts an output of GeoJSON to a polygon appropriate for plotting. Both are showcased in the examples below.
GeoMakie.jl provides an axis for plotting geospatial data, [`GeoAxis`](@ref). Both are showcased in the examples below.

```@docs
GeoAxis
geo2basic
```

## Gotchas
Expand Down Expand Up @@ -111,12 +110,11 @@ using GeoMakie.GeoJSON
countries_file = download("https://datahub.io/core/geo-countries/r/countries.geojson")
countries = GeoJSON.read(read(countries_file, String))
n = length(GeoInterface.features(countries))
n = length(countries)
hm = poly!(ax, countries; color= 1:n, colormap = :dense,
strokecolor = :black, strokewidth = 0.5, overdraw = true,
strokecolor = :black, strokewidth = 0.5,
)
# cb2 = Colorbar(fig[1,3], hm; label = "countries index", height = Relative(0.65))
translate!(hm, 0, 0, 100) # move above surface plot
fig
```
Expand All @@ -129,3 +127,11 @@ However, with **GLMakie**, which is much faster, these methods do not work; if y
`surface!(ga, lonmin..lonmax, latmin..latmax, ones(size(img)...); color = img, shading = false)`.

To plot a scalar field, simply use `surface!(ga, lonmin..lonmax, latmin..latmax, field)`. The `..` notation denotes an interval which Makie will automatically sample from to obtain the x and y points for the surface.



## API

```@docs
GeoMakie.geoformat_ticklabels
```
6 changes: 4 additions & 2 deletions examples/field_and_countries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
using Makie, CairoMakie, GeoMakie
import Downloads
using GeoMakie.GeoJSON
using GeometryBasics
using GeoInterface

# https://datahub.io/core/geo-countries#curl # download data from here
worldCountries = GeoJSON.read(read(Downloads.download("https://raw.githubusercontent.com/johan/world.geo.json/master/countries.geo.json"), String))
n = length(GeoMakie.GeoInterface.features(worldCountries))
n = length(worldCountries)
lons = -180:180
lats = -90:90
field = [exp(cosd(l)) + 3(y/90) for l in lons, y in lats]


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

ax = GeoAxis(
Expand All @@ -23,6 +24,7 @@ ax = GeoAxis(
)

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

hm2 = poly!(
ax, worldCountries;
Expand Down
6 changes: 4 additions & 2 deletions examples/italy.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
using CairoMakie, GeoMakie
using GeoMakie.GeoJSON
using Downloads
using GeometryBasics
using GeoInterface

# Acquire data
it_states = Downloads.download("https://github.com/openpolis/geojson-italy/raw/master/geojson/limits_IT_provinces.geojson")
geo = GeoJSON.read(read(it_states, String))
basic = GeoMakie.geo2basic(geo)

fig = Figure()
ga = GeoAxis(fig[1, 1]; dest = "+proj=ortho +lon_0=12.5 +lat_0=42", lonlims=(12, 13), latlims = (40, 44))
plot!.(ga, basic; strokecolor = :blue, strokewidth = 1, color = (:blue, 0.5), shading = false);
poly!(ga, geo; strokecolor = :blue, strokewidth = 1, color = (:blue, 0.5), shading = false);
datalims!(ga)

fig
4 changes: 2 additions & 2 deletions examples/old/tick_locator_experiment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ function test_tickpad()
xlimits = (lmin[1], lmax[1])
ylimits = (lmin[2], lmax[2])

_xtickvalues, _xticklabels = Makie.MakieLayout.get_ticks(LinearTicks(7), identity, GeoMakie.geoformat_ticklabels, xlimits...)
_ytickvalues, _yticklabels = Makie.MakieLayout.get_ticks(LinearTicks(7), identity, GeoMakie.geoformat_ticklabels, ylimits...)
_xtickvalues, _xticklabels = Makie.get_ticks(LinearTicks(7), identity, GeoMakie.geoformat_ticklabels, xlimits...)
_ytickvalues, _yticklabels = Makie.get_ticks(LinearTicks(7), identity, GeoMakie.geoformat_ticklabels, ylimits...)

_xtickpos_in_inputspace = Point2f.(_xtickvalues, ylimits[1])
_ytickpos_in_inputspace = Point2f.(xlimits[1], _ytickvalues)
Expand Down
2 changes: 1 addition & 1 deletion examples/specialized/graph_on_usa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ states_geo = GeoJSON.read(read(states, String))
# Get rid of Alaska
filter!((x->!(x.properties["name"] ("Alaska", "Hawaii", "Puerto Rico"))), states_geo.features)

n = length(GeoInterface.features(states_geo))
n = length(states_geo)

#g = wheel_graph(10)
gpos = Dict(
Expand Down
38 changes: 24 additions & 14 deletions examples/world_population.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
# This example was contributed by Martijn Visser (@visr)
using Makie, CairoMakie, GeoMakie
using GeoMakie.GeoJSON
using GeometryBasics
using Downloads

source = "+proj=longlat +datum=WGS84"
dest = "+proj=natearth2"

fig = Figure(resolution = (1000,500))
ga = GeoAxis(
fig[1, 1];
source = source,
dest = dest,
)

ga.xticklabelsvisible[] = false
ga.yticklabelsvisible[] = false

url = "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/"
land = Downloads.download(url * "ne_110m_land.geojson")
land_geo = GeoJSON.read(read(land, String))
poly!(ga, land_geo, color=:black)

pop = Downloads.download(url * "ne_10m_populated_places_simple.geojson")
pop_geo = GeoJSON.read(read(pop, String))
scatter!(ga, GeoMakie.geo2basic(pop_geo), color="lightgrey", markersize=1.2)

fig
begin
fig = Figure(resolution = (1000,500))
ga = GeoAxis(
fig[1, 1];
source = source,
dest = dest
)

ga.xticklabelsvisible[] = false
ga.yticklabelsvisible[] = false
poly!(ga, land_geo, color=:black)
popisqrt = map(pop_geo) do geo
popi = geo.pop_max
popi > 0 ? sqrt(popi) : 0.0
end
mini, maxi = extrema(popisqrt)
size = map(popisqrt) do popi
normed = (popi .- mini) ./ (maxi - mini)
return (normed * 20) .+ 1
end
scatter!(ga, pop_geo, color=popisqrt, markersize=size)
fig
end
Loading

0 comments on commit 27c708a

Please sign in to comment.