Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spherical geometry #17

Open
tiemvanderdeure opened this issue Sep 4, 2023 · 8 comments
Open

Spherical geometry #17

tiemvanderdeure opened this issue Sep 4, 2023 · 8 comments
Labels
enhancement New feature or request

Comments

@tiemvanderdeure
Copy link
Contributor

It could be useful to have some spherical geometry (read: geometry on the Earth surface).

In this pull request I implemented a formula to calculate the area of any spherical polygon, which of course sits awkwardly in Rasters.jl.

Some things we might want to implement are (please suggest more):

  • Shortest distance between two points on a sphere
  • Bearing
  • Polygon area

This page has some relevant math

@rafaqz
Copy link
Member

rafaqz commented Sep 4, 2023

Turf.jl also has a bunch of code for this we could use.

@rafaqz
Copy link
Member

rafaqz commented Sep 9, 2023

Distance between points and lines on a sphere would also be useful
https://stackoverflow.com/questions/1299567/how-to-calculate-distance-from-a-point-to-a-line-segment-on-a-sphere

@rafaqz
Copy link
Member

rafaqz commented Sep 11, 2023

Could be good to standardise with Distances.jl
https://github.com/JuliaStats/Distances.jl

This also integrates with
https://github.com/KristofferC/NearestNeighbors.jl

for fast calculations of e.g. distances between vectors of points,

Like finding minimum spherical distances between raster pixels and points in an arbitrary collection of features/geometries is only this much code already:

points = GeometryOps.flatten(GI.PointTrait, rivers) do point
    SVector(deg2rad(GI.x(point)), deg2rad(GI.y(point)))
end |> collect

bt = BallTree(points, SphericalAngle())
targets = map(DimPoints(mask_raster)) do p
    SVector(deg2rad.(p))
end |> vec
nearest = nn(bt, targets)
dist = Raster(nearest[2], dims(mask_raster))
Rasters.rplot(dist)

But it could be nice to make this a bit easier for people, and have a spherical_distances function that does the conversion to spherical coordinates automatically, as well as handling the conversions between packages for people.

Distances to lines and polygons on a sphere will of course be harder than this, but it would be good to have those too.

@asinghvi17
Copy link
Member

Just to chime in, there seem to be two other packages which look at spherical (specifically Earth spherical :D) coordinates: GeographicLib.jl (unregistered but pure Julia) or Proj.jl's geodesic API. I would guess that we could offer one or all of those as references as well, at least in the docs!

@asinghvi17 asinghvi17 added the enhancement New feature or request label Apr 1, 2024
@JeffreySarnoff
Copy link

Hello. While doing this -- how about Hyperbolic Geometry [has applications in AI/ML].

@asinghvi17
Copy link
Member

asinghvi17 commented Jan 20, 2025

It's definitely possible, some of the the same considerations as spherical geometry apply, so some of the polygon processing code could work out of the box.

But it would probably be useful to see some concrete usecases first to understand what the problems that have to be solved are!

@asinghvi17
Copy link
Member

http://www.boeing-727.com/Data/fly%20odds/distance.html is useful for the intersection_point implementation for spherical lines

@asinghvi17
Copy link
Member

https://github.com/ryanketzner/sphericalpolygon and its associated paper are pretty interesting for fast point in polygon on the sphere...but they require a known point inside the polygon. Maybe we can automatically generate that, somehow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants