# Simple use of Geodesy.jl to get euclidean distances?

**URL:** https://discourse.julialang.org/t/simple-use-of-geodesy-jl-to-get-euclidean-distances/118680
**Category:** General Usage
**Tags:** geo, coordinate-transform, geodesy
**Created:** [August 27, 2024, 5:25pm UTC](https://discourse.julialang.org/t/simple-use-of-geodesy-jl-to-get-euclidean-distances/118680 "2024-08-27T17:25:05Z")
**Posts on this page:** 4
**Page:** 2

<div class="post-metadata">

### Author: ![technocrat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/technocrat/32/220947_2.png) [@technocrat](https://discourse.julialang.org/u/technocrat)
#### Post date: [August 29, 2024, 6:45am UTC](https://discourse.julialang.org/t/simple-use-of-geodesy-jl-to-get-euclidean-distances/118680/21 "2024-08-29T06:45:33Z")

</div>

You have three options:

1. Cartesian Euclidian distance, which is an easy calculation but accuracy degrades with distance, but first you must convert lat/lon to meters, from the Prime Meridian (E +, W-) and the Equator (N +, S-). You don’t want to do that.
2. Haversine distance, using the `Haversine.jl` package, which traces the distance along a spherical representation of the Earth, so it will trace a longer path than Cartesian and its relative accuracy to Cartesian increases with distance. But it works directly with lat/lon.
3. Geodesic distance, using the `SimpleFeatutes.jl` package, which accounts for the Earth being an oblate spheroid, rather than a perfect sphere. It will allow you to specify the standard US NAD83 CRS (coordinate reference system) and has a function to calculate distances between two points.

The big advantage of `SimpleFeatures.jl` is that it is just a DataFrame object that accommodates a `Geometry` object to represent points, lines, polygons or multipolygons. That means you can have a single DataFrame with your GEOID, County Name, State Name if you want, lat/lon from the TIGER files, the Geometry object and whatever attributes you are collecting all in the same object.

Depending on what you’re planning to do, there are a couple of other considerations.

If for some reason you want pairwise data for all counties, even though many pairs will be zero valued, consider using a `SparseArray`. For choropleth mapping, I haven’t found a tool I really like. There’s an implementation of Plotly for roadmap type work and `GeoStats.jl` is expert-level. So, I usually resort to `GGPlot2` in `R` through `RCall` or natively. I have’t tried `TidierPlots.jl` yet but it doesn’t have the `sf_geom` to work with SimpleFeatures, nor does `Gadfly.jl` or `Makie.jl`. (even with `GeoMakie.jl`).

---

<div class="post-metadata">

### Author: ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)
#### Post date: [August 29, 2024, 2:52pm UTC](https://discourse.julialang.org/t/simple-use-of-geodesy-jl-to-get-euclidean-distances/118680/22 "2024-08-29T14:52:28Z")

</div>

So for right now I went with distances.jl and use the haversine distance. And I’m fitting my desirability polynomial directly on latitude and longitude. We will see how this goes.

---

<div class="post-metadata">

### Author: ![mihalybaci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mihalybaci/32/13528_2.png) [@mihalybaci](https://discourse.julialang.org/u/mihalybaci)
#### Post date: [August 29, 2024, 3:38pm UTC](https://discourse.julialang.org/t/simple-use-of-geodesy-jl-to-get-euclidean-distances/118680/23 "2024-08-29T15:38:49Z")

</div>

I don’t think this was mentioned yet, but the lat, lon coordinates are very likely in the [WGS 1984](https://en.wikipedia.org/wiki/World_Geodetic_System#WGS_84) coordinate reference system, which models the Earth as an ellipsoid. I know you’re not too concerned about absolute error, and counties that are relatively close may be fine using Haversine. But if you were to estimate the distance from, say, Seattle, Washington to Miami, Florida, the error may be higher than you wish. Do you happen to have altitude/elevation data as well? Some counties may be near 0 m above mean sea level (MSL) while others may be over 2000m MSL. I’m not sure what these factors do to the overall accuracy, but it may be worth testing the Haverine formula against something like `Geodesy.euclidian_distance` to see what the differences are.

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [August 29, 2024, 6:35pm UTC](https://discourse.julialang.org/t/simple-use-of-geodesy-jl-to-get-euclidean-distances/118680/24 "2024-08-29T18:35:22Z")

</div>

> [@mihalybaci](#):
>
> Geodesy.euclidian\_distance

As the name suggests, this computes the straight line distance, which is only accurate for small distances - [see doc reference here](https://github.com/JuliaGeo/Geodesy.jl?tab=readme-ov-file#distance).

[Previous page](https://discourse.julialang.org/t/simple-use-of-geodesy-jl-to-get-euclidean-distances/118680.md?page=1)
