From b95d3e5d8b0faa209fe6eaa7ec4ed12ffa9a003e Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Thu, 25 Jul 2024 13:01:25 +0530 Subject: [PATCH] Minor documentation improvements (#181) * Use NaturalEarth in benchmarks to get data Less of a pain * Add a geodesic-path tutorial * use NaturalEarth in simplify examples too * add backticks to `within` Literate docs --- benchmarks/benchmarks.jl | 6 +++--- docs/src/tutorials/geodesic_paths.md | 17 +++++++++++++++++ src/methods/geom_relations/within.jl | 14 +++++++------- src/transformations/simplify.jl | 3 ++- 4 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 docs/src/tutorials/geodesic_paths.md diff --git a/benchmarks/benchmarks.jl b/benchmarks/benchmarks.jl index bd28d63df..af5f15ed9 100644 --- a/benchmarks/benchmarks.jl +++ b/benchmarks/benchmarks.jl @@ -11,7 +11,7 @@ import GeometryOps as GO, GeoInterface as GI, GeometryBasics as GB, LibGEOS as LG -import GeoJSON +import GeoJSON, NaturalEarth # In order to benchmark, we'll actually use the new [Chairmarks.jl](https://github.com/lilithhafner/Chairmarks.jl), # since it's significantly faster than BenchmarkTools. To keep benchmarks organized, though, we'll still use BenchmarkTools' # `BenchmarkGroup` structure. @@ -184,7 +184,7 @@ usa_difference_suite = usa_poly_suite["difference"] = BenchmarkGroup(["title:USA usa_intersection_suite = usa_poly_suite["intersection"] = BenchmarkGroup(["title:USA intersection", "subtitle:Tested on CONUS"]) usa_union_suite = usa_poly_suite["union"] = BenchmarkGroup(["title:USA union", "subtitle:Tested on CONUS"]) -fc = GeoJSON.read(read(download("https://rawcdn.githack.com/nvkelso/natural-earth-vector/ca96624a56bd078437bca8184e78163e5039ad19/geojson/ne_10m_admin_0_countries.geojson"))) +fc = NaturalEarth.naturalearth("admin_0_countries", 10) usa_multipoly = fc.geometry[findfirst(==("United States of America"), fc.NAME)] |> x -> GI.convert(LG, x) |> LG.makeValid |> GO.tuples usa_poly = GI.getgeom(usa_multipoly, findmax(GO.area.(GI.getgeom(usa_multipoly)))[2]) # isolate the poly with the most area @@ -194,7 +194,7 @@ f, a, p = plot(usa_poly; label = "Original", axis = (; aspect = DataAspect())); axislegend(a) f -# Now, we get to benchmarking: +# Now, we get to benchmarking: usa_o_lg, usa_o_go = lg_and_go(usa_poly) diff --git a/docs/src/tutorials/geodesic_paths.md b/docs/src/tutorials/geodesic_paths.md new file mode 100644 index 000000000..f6f4bf653 --- /dev/null +++ b/docs/src/tutorials/geodesic_paths.md @@ -0,0 +1,17 @@ +# Geodesic paths + +Geodesic paths are paths computed on an ellipsoid, as opposed to a plane. + +```@example geodesic +import GeometryOps as GO, GeoInterface as GI +using CairoMakie, GeoMakie + + +IAH = (-95.358421, 29.749907) +AMS = (4.897070, 52.377956) + + +fig, ga, _cp = lines(GeoMakie.coastlines(); axis = (; type = GeoAxis)) +lines!(ga, GO.segmentize(GO.GeodesicSegments(; max_distance = 100_000), GI.LineString([IAH, AMS])); color = Makie.wong_colors()[2]) +fig +``` \ No newline at end of file diff --git a/src/methods/geom_relations/within.jl b/src/methods/geom_relations/within.jl index 5b240b819..8d2e34b16 100644 --- a/src/methods/geom_relations/within.jl +++ b/src/methods/geom_relations/within.jl @@ -40,14 +40,14 @@ implementation based on the geometry trait. Each of these calls a method in the geom_geom_processors file. The methods in this file determine if the given geometries meet a set of criteria. For the -`within` function and arguments g1 and g2, this criteria is as follows: - - points of g1 are allowed to be in the interior of g2 (either through +`within` function and arguments `g1` and `g2`, this criteria is as follows: + - points of `g1` are allowed to be in the interior of `g2` (either through overlap or crossing for lines) - - points of g1 are allowed to be on the boundary of g2 - - points of g1 are not allowed to be in the exterior of g2 - - at least one point of g1 is required to be in the interior of g2 - - no points of g1 are required to be on the boundary of g2 - - no points of g1 are required to be in the exterior of g2 + - points of `g1` are allowed to be on the boundary of `g2` + - points of `g1` are not allowed to be in the exterior of `g2` + - at least one point of `g1` is required to be in the interior of `g2` + - no points of `g1` are required to be on the boundary of `g2` + - no points of `g1` are required to be in the exterior of `g2` The code for the specific implementations is in the geom_geom_processors file. =# diff --git a/src/transformations/simplify.jl b/src/transformations/simplify.jl index d9d0e89de..8a36a48cc 100644 --- a/src/transformations/simplify.jl +++ b/src/transformations/simplify.jl @@ -37,10 +37,11 @@ We benchmark these methods against LibGEOS's `simplify` implementation, which us using BenchmarkTools, Chairmarks, GeoJSON, CairoMakie import GeometryOps as GO, LibGEOS as LG, GeoInterface as GI using CoordinateTransformations +using NaturalEarth import Main: plot_trials # hide lg_and_go(geometry) = (GI.convert(LG, geometry), GO.tuples(geometry)) # Load in the Natural Earth admin GeoJSON, then extract the USA's geometry -fc = GeoJSON.read(read(download("https://rawcdn.githack.com/nvkelso/natural-earth-vector/ca96624a56bd078437bca8184e78163e5039ad19/geojson/ne_10m_admin_0_countries.geojson"))) +fc = NaturalEarth.naturalearth("admin_0_countries", 10) usa_multipoly = fc.geometry[findfirst(==("United States of America"), fc.NAME)] |> x -> GI.convert(LG, x) |> LG.makeValid |> GO.tuples include(joinpath(dirname(dirname(pathof(GO))), "test", "data", "polygon_generation.jl"))