PostGIS distance calculation gives in-accurate results
46 Replies
⌛
This post has been reserved for your question.
Hey @Rag JN Eclipse IDE! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
The problem is I used Vincenty's algorithm
Which gave accurate result
Distance from repo is the PostGIS usage, and distanceFromAlgorithm by using the algo
The accurate one is Vincenty's algorithm
https://www.baeldung.com/java-find-distance-between-points#calculate-the-distance-using-vincentys-formula
Vincenty's algorithm
Baeldung
Calculate Distance Between Two Coordinates in Java | Baeldung
Learn three methods to calculate the distance between two geographical coordinates in Java.
That's not inaccurate, one of those is calculating something completely different
what postgis function did you use?
^
ST_Distance
I even used ST_DistanceSphere
I even used Points
Nothing gives me accurate results
This also has been usedyou should pass it geometries or it wouldn't work
ok makepoint does that
your points are stored in 4326?
yeah it should be
so I am not passing Geometrics?
st_makepoint is ok
I'd suggest read the docs very carefully, to see what it outputs, and what you expect it to output
You want haversine, or spherical distance between two points, and in a specific unit of measurement
So check those requirements for whichever function you call
https://postgis.net/docs/ST_Distance.html
This one right?
And also, don't go to the database for something like this, unless the data is already there, because a roundtrip to the database is not the way to do it
any, there's more
minimum 2D Cartesian (planar) distance between two geometries, in projected units (spatial ref units)Is that what you want? If not, look around for another function
I want how most online tools give almost havesine's result, and I want to get it using PostGIS
Returns minimum distance in meters between two lon/lat geometries using a spherical earth modelThat one seems more accurate
Returns minimum distance in meters between two lon/lat points. Uses a spherical earth and radius derived from the spheroid defined by the SRIDST_DistanceSphere what does that give you?
please wait.
Query I used is
that's better
paste those two locations plz
distanceFromRepo is the result for query.
25.7217, -80.1218
25.7617, -80.1918
yeah, check if you have lat/lon switched
but that result makes way more sense
You can see the lat and longs aren't switched
UserLocation, and hotelLocation are the Points.
7820.7057?
yeah
It should be this
bit brightness increased
and the spheroid function
what does that do?
yes, but result
I know what it does
ok let me try
oof, JTS, you're full on in the "use all the things" phase it seems
I hope it all the same syntax, the example syntax is harder to even read
Also, use
Point
, not Coordinate
I mean, the function arguments are the same...yep
how none of them doesn't come close to 8?
switch both lat and lon around
just curious
bet
wow
🙊
yeah I had a feeling
Which is why I fucking hate that stupid library you're using
It's so confusing
With their factories and their coordinates with X and Y instead of lat and lon
it's still my fault right?
I mean I just followed the standards
Thank you so much.
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
nah, that library is just confusing as hell, I made the same mistakes all the time when using it a long time ago
Now I just quickly add my own types and call it a day
Anyway, good luck!
ah ok.
what that means really?
I write my own Coordinate class, and some converters so jpa can be happy
ah ok
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.