oracle - SDO Geometry. Calculate shortest distance -
i have coordinates of place stored struct object , coordinates of buildings stored doubles.
select geo.id, geo.object_id, geo.object_type, geo.date_created, t.x longitude, t.y latitude geolocation geo, table(sdo_util.getvertices(geo.location)) t; --i can fetch places coordinates.
select longitude, latitude building -- fetch buildings locations.
i have find in building place located (the shortest distance near building). i.e.
place: longitude = 41.1111111, langitude = 42.2222222 building 1: longitude = 41.1111112, langitude = 42.42.2222223 building 2: longitude = 50.1111111, langitude = 50.2222222 building 3: longitude = 60.1111111, langitude = 60.2222222
(i exaggerated values deliberately)
the result should be: building 1 (this near building).
how can use sdo_geom.sdo_distance ?
sorry. know nothing sdo_geom. can show few maths, if helps:
define vector centre-of-earth point1. define vector centre-of-earth , point. dot product of both vectors gives cosine of angle between these 2 vectors.
the point maximum dot-product closest point point1.
for dot product spherical coordinates see this post.
you can take aproximation vectors have same r
. because interested in maximum values (not real distances) can use r1 = r2 = 1
also, in post φ = 90 - latitude
. remember sin(a) = cos(90-a).
doing both corrections final formula need is
d = cosφ1 cosφ2 cos(θ1−θ2) + sinφ1 sinφ2
with φ
= latitude , θ
= longitude
Comments
Post a Comment