Page MenuHomePhabricator

Wikidata Query Service function geof:distance is not working outside Earth
Closed, DeclinedPublic

Description

Hi,

In the Wikidata Query Service, « The function geof:distance returns distance between two points, in kilometers. » according to the User Manual.

But apparently it works only on Earth :( Is it on purpose ? Could it be extended to other planets ?

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

It looks like BlazeGraph’s CoordinateDD type doesn’t like the longitudes of those coordinates… is it conventional to give them in range [0°, 360°) instead of [-180°, +180°) on bodies other than Earth? @thiemowmde I think you’re more familiar with that…

(But of course, just fixing that issue isn’t enough to properly calculate the distance, because the radius of the globe needs to be taken into account, right?)

is it conventional to give them in range [0°, 360°) instead of [-180°, +180°) on bodies other than Earth?

tldr; it's not unusual.

Longer explanation: outside Earth, their is several conventions and coordinates can be planetocentric or planetographic. The two systems co-exists not so peacefully :/ (and the habits differs for each and every celestial bodies... for some the planetocentric is more usual, for some the planetographic is more usual… I'm not even sure to fully understand the situation)

This query doesn’t crash:

SELECT (2 * ?distance AS ?circumference) WHERE {
  BIND("<http://www.wikidata.org/entity/Q111> Point(0 0)"^^geo:wktLiteral AS ?point1)
  BIND("<http://www.wikidata.org/entity/Q111> Point(180 0)"^^geo:wktLiteral AS ?point2)
  BIND(geof:distance(?point1, ?point2) AS ?distance)
}

But it reports the equatorial circumference of Mars as 40k km, which is incorrect (that’s Earth’s circumference (roughly)).

Aklapper renamed this task from Wikidata Query Service fuction geof:distance is not working outside Earth to Wikidata Query Service function geof:distance is not working outside Earth.Sep 11 2017, 5:46 PM
Smalyshev triaged this task as Medium priority.Sep 16 2017, 12:30 AM
Smalyshev subscribed.

geof:distance is definitely assuming Earth for now. Doing it for other globes is tricky since even if we assume they all spherical (which may be good approximation for larger planets but less so for dwarf planets and completely wrong for things like asteroids) we'd need to account for radius, etc. which is hardcoded now for Earth data. I'm not even sure how to efficiently implement it for random globe. It may be possible to do it for predefined set of globes.

So... The other way round now:

  • if it's only for Earth, should it *not* give results on other places ?

Meanwhile, I've updated the User Manuel : https://www.mediawiki.org/w/index.php?diff=2566505

If we assume spherical globes (which is already slightly inaccurate for Earth, but probably okay), the actual calculation is just “Earth distance × (globe radius / Earth radius)”, right? And I think a predefined set of globes is acceptable.

the actual calculation is just “Earth distance × (globe radius / Earth radius)”, right?

Yes, that appears to be the case, but we'd have to store the radius data for all globes. OTOH, we already have them in the database, so we could probably just look them up via properties... With some caching it might work.

Thanks for raising this issue and updating the user manual.
As pointed out, we are currently Earth-centric, which is currently a reasonable expectation for the majority of use cases. For astronomy, I recognize this will often be insufficient for various reasons -- as was also pointed out, we're also making assumptions about perfect spheres. As of now we are not prioritizing second order calculations like this in WDQS by design due to the complexity and hyper-specificity involved. I think there is sufficient information on the astronomical objects to calculate non-Earth distances based on coordinates outside of WDQS for specific use cases -- or perhaps if distance is required for a query, to calculate these distances externally enough to restrict queries to a range of coordinates on the astronomical object in question.