-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add GeoInterfaceMakie * fix * fix * fix * fix * fix * fix * fix * fix * fix tests * fix * fix * fix * replace Makie by MakieCore where possible * drop Makie dependency * make Makie a test only dependency
- Loading branch information
Showing
8 changed files
with
285 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: GeoInterfaceMakie CI | ||
on: | ||
pull_request: | ||
paths-ignore: | ||
- 'docs/**' | ||
- '*.md' | ||
branches: | ||
- main | ||
- breaking-release | ||
push: | ||
paths-ignore: | ||
- 'docs/**' | ||
- '*.md' | ||
branches: | ||
- main | ||
- breaking-release | ||
tags: '*' | ||
|
||
concurrency: | ||
group: makie-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test: | ||
name: GeoInterfaceMakie Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
version: | ||
- '1.6' | ||
- '1' # automatically expands to the latest stable 1.x release of Julia | ||
os: | ||
- ubuntu-latest | ||
arch: | ||
- x64 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- uses: julia-actions/setup-julia@v1 | ||
with: | ||
version: ${{ matrix.version }} | ||
arch: ${{ matrix.arch }} | ||
- uses: julia-actions/cache@v1 | ||
- name: Install Julia dependencies | ||
shell: julia --project=monorepo {0} | ||
run: | | ||
using Pkg; | ||
# dev mono repo versions | ||
pkg"dev . ./GeoInterfaceMakie" | ||
- name: Run the tests | ||
continue-on-error: true | ||
run: > | ||
julia --color=yes --project=monorepo -e 'using Pkg; Pkg.test("GeoInterfaceMakie", coverage=true)' | ||
&& echo "TESTS_SUCCESSFUL=true" >> $GITHUB_ENV | ||
- name: Exit if tests failed | ||
if: ${{ env.TESTS_SUCCESSFUL != 'true' }} | ||
run: exit 1 | ||
- uses: julia-actions/julia-processcoverage@v1 | ||
- uses: codecov/codecov-action@v1 | ||
with: | ||
file: lcov.info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/Manifest.toml | ||
/docs/build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Jan Weidner <[email protected]> and contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name = "GeoInterfaceMakie" | ||
uuid = "0edc0954-3250-4c18-859d-ec71c1660c08" | ||
authors = ["JuliaGeo and contributors"] | ||
version = "0.1.0" | ||
|
||
[deps] | ||
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f" | ||
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326" | ||
MakieCore = "20f20a25-4f0e-4fdf-b5d1-57303727442b" | ||
|
||
[compat] | ||
GeoInterface = "1" | ||
GeometryBasics = "0.4.4" | ||
MakieCore = "0.5.1" | ||
julia = "1.6" | ||
|
||
[extras] | ||
LibGEOS = "a90b1aa1-3769-5649-ba7e-abc5a9d163eb" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" | ||
|
||
[targets] | ||
test = ["Test", "LibGEOS", "Makie"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# GeoInterfaceMakie | ||
|
||
[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://jw3126.github.io/GeoInterfaceMakie.jl/stable/) | ||
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://jw3126.github.io/GeoInterfaceMakie.jl/dev/) | ||
[![Build Status](https:/jw3126/GeoInterfaceMakie.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https:/jw3126/GeoInterfaceMakie.jl/actions/workflows/CI.yml?query=branch%3Amain) | ||
|
||
Makie support for any geometry that implements [GeoInterface](https:/JuliaGeo/GeoInterface.jl). | ||
|
||
# Usage | ||
Add Makie support to a type that implements GeoInterface: | ||
```julia | ||
struct MyGeometry | ||
... | ||
end | ||
# overload GeoInterface methods | ||
... | ||
import GeoInterfaceMakie | ||
GeoInterfaceMakie.@enable MyGeometry | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
module GeoInterfaceMakie | ||
|
||
using GeoInterface | ||
import MakieCore as MC | ||
import GeometryBasics as GB | ||
import GeoInterface as GI | ||
|
||
|
||
function _plottype(geom) | ||
plottype_from_geomtrait(GI.geomtrait(geom)) | ||
end | ||
function plottype_from_geomtrait(::Union{GI.LineStringTrait, GI.MultiLineStringTrait}) | ||
MC.Lines | ||
end | ||
function plottype_from_geomtrait(::Union{GI.PointTrait, GI.MultiPointTrait}) | ||
MC.Scatter | ||
end | ||
function plottype_from_geomtrait(::Union{GI.PolygonTrait,GI.MultiPolygonTrait, GI.LinearRingTrait}) | ||
MC.Poly | ||
end | ||
function pttype(geom) | ||
if GI.is3d(geom) | ||
GB.Point3f | ||
else | ||
GB.Point2f | ||
end | ||
end | ||
function points(geom)::Union{Vector{GB.Point2f}, Vector{GB.Point3f}} | ||
Pt = pttype(geom) | ||
out = Pt[] | ||
points!(out, GI.geomtrait(geom), geom) | ||
end | ||
@noinline function points!(out, ::GI.AbstractTrait, geom) | ||
for pt in GI.getpoint(geom) | ||
push!(out, _convert(eltype(out), pt)) | ||
end | ||
out | ||
end | ||
@noinline function points!(out, ::GI.PointTrait, pt) | ||
push!(out, _convert(eltype(out), pt)) | ||
out | ||
end | ||
function _convert(::Type{GB.Point2f}, pt) | ||
x,y = GI.getcoord(pt) | ||
GB.Point2f(x,y) | ||
end | ||
function _convert(::Type{GB.Point3f}, pt) | ||
x,y,z = GI.getcoord(pt) | ||
GB.Point3f(x,y,z) | ||
end | ||
|
||
function basicsgeom(geom) | ||
t = GI.geomtrait(geom) | ||
T = basicsgeomtype(t) | ||
GI.convert(T, t, geom) | ||
end | ||
|
||
basicsgeomtype(::GI.PointTrait) = GB.Point | ||
basicsgeomtype(::GI.MultiPointTrait) = GB.MultiPoint | ||
basicsgeomtype(::GI.PolygonTrait) = GB.Polygon | ||
basicsgeomtype(::GI.MultiPolygonTrait) = GB.MultiPolygon | ||
basicsgeomtype(::GI.LineStringTrait) = GB.LineString | ||
basicsgeomtype(::GI.MultiLineStringTrait) = GB.MultiLineString | ||
|
||
function _convert_arguments(::Type{<:MC.Poly}, geom)::Tuple | ||
geob = basicsgeom(geom)::Union{GB.Polygon, GB.MultiPolygon} | ||
(geob,) | ||
end | ||
function _convert_arguments(::MC.PointBased, geom)::Tuple | ||
pts = points(geom) | ||
(pts,) | ||
end | ||
|
||
function expr_enable(Geom) | ||
quote | ||
function $MC.plottype(geom::$Geom) | ||
$_plottype(geom) | ||
end | ||
function $MC.convert_arguments(p::Type{<:$MC.Poly}, geom::$Geom) | ||
$_convert_arguments(p,geom) | ||
end | ||
function $MC.convert_arguments(p::$MC.PointBased, geom::$Geom) | ||
$_convert_arguments(p,geom) | ||
end | ||
end | ||
end | ||
|
||
""" | ||
@enable(Geom) | ||
Enable Makie based plotting for a type `Geom` that implements the geometry interface | ||
defined in `GeoInterface`. | ||
# Usage | ||
```julia | ||
struct MyGeometry | ||
... | ||
end | ||
# overload GeoInterface for MyGeometry | ||
... | ||
@enable MyGeometry | ||
``` | ||
""" | ||
macro enable(Geom) | ||
esc(expr_enable(Geom)) | ||
end | ||
|
||
# TODO | ||
# Features and Feature collections | ||
# https:/JuliaGeo/GeoInterface.jl/pull/72#issue-1406325596 | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import GeoInterfaceMakie | ||
using Test | ||
import LibGEOS | ||
using LibGEOS | ||
import GeoInterface as GI | ||
using Makie | ||
|
||
GeoInterfaceMakie.@enable(LibGEOS.AbstractGeometry) | ||
|
||
@testset "points" begin | ||
points = GeoInterfaceMakie.points | ||
pt = LibGEOS.Point(1,2,3) | ||
@test points(pt) == [Point3f(1,2,3)] | ||
|
||
unitsquare = readgeom("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))") | ||
@test points(unitsquare) == [ | ||
Point2f(0.0, 0.0), | ||
Point2f(0.0, 1.0), | ||
Point2f(1.0, 1.0), | ||
Point2f(1.0, 0.0), | ||
Point2f(0.0, 0.0), | ||
] | ||
end | ||
|
||
@testset "smoketest 2d" begin | ||
unitsquare = readgeom("POLYGON((0 0, 0 1, 1 1, 1 0, 0 0))") | ||
bigsquare = readgeom("POLYGON((0 0, 11 0, 11 11, 0 11, 0 0))") | ||
smallsquare = readgeom("POLYGON((5 5, 8 5, 8 8, 5 8, 5 5))") | ||
fig = Figure() | ||
geoms = [ | ||
unitsquare, | ||
GI.difference(bigsquare, smallsquare), | ||
boundary(unitsquare), | ||
GI.union(smallsquare, unitsquare), | ||
readgeom("POINT(1 0)"), | ||
readgeom("MULTIPOINT(1 2, 2 3, 3 4)"), | ||
] | ||
for (i,geom) in enumerate(geoms) | ||
Makie.plot!(Axis(fig[i,1], title="$(GI.geomtrait(geom))"), geom) | ||
end | ||
fig | ||
end |