How to fix intersection points to calculate the distance between points?

Asked

Viewed 143 times

3

I need to calculate the distance between points within the place where I work, so I calculated the coordinates of each location in X and Y and I launched the coordinates into the system.

I’m making a query to calculate this distance, however as it is not always in a straight line that will be made to calculate them I had to put points of intersection to calculate when it leaves a street and goes to another,

For example: From 1AF-001-10 to 1AD-013-10 it comes off "AF" street and goes to street "AD".

For that he needs to calculate so :

De            Para
1AF-001-10  || interseçãoAF = valor1

    De            Para
interseçãoAF || interseçãoAD = valor2

    De            Para
interseçãoAD || 1AD-013-10 = valor3

Ou seja :
    De           Para
1AF-001-10 || 1AD-013-10 = soma(valor1,valor2,valor3)

I managed to reach the calculation in a straight line, I used the case with substr saying that if the acronyms of the initial street is equal to the final he makes the calculation and I do not know how to put in Else as he has to proceed with the other calculations.

Below follows the query :

[Select 

local_inicial,
local_final,
case when substr(local_inicial,2,2) = substr(local_final,2,2) then Round (SQRT (POWER (eixoxf - eixoxi,2) + POWER (eixoyf - eixoyi,2)))*1.2 else 0 end  as "dist",
carton,
usuario,
tempoi,
tempof

From
(Select
linhas,
loci as local_inicial,
LEAD(loci, 1,loci) OVER (PARTITION BY usu,hh,dia1 ORDER BY linhas) as local_final,
ctn as carton,
usu as usuario,
hhmmssi as tempoi,
LEAD(hhmmssi, 1,hhmmssi) OVER (PARTITION BY usu,hh,dia1 ORDER BY linhas) as tempof,
exi as eixoxi,
LEAD(exi, 1,exi) OVER (PARTITION BY usu,hh,dia1 ORDER BY linhas) as eixoxf,
eyi as eixoyi,
LEAD(eyi, 1,eyi) OVER (PARTITION BY usu,hh,dia1 ORDER BY linhas) as eixoyf

From
(Select 
rownum as linhas, 
D.frstol as loci,
D.To_subnum as ctn,
D.usr_id as usu,
To_Char (D.trndte, 'HH24') as hh,
To_Char (D.trndte, 'DD') as dia1,
To_Char (D.ins_dt, 'HH24:MI:SS') as hh24,
To_Char (D.ins_dt, 'HH24') *3600 + To_Char (D.ins_dt, 'MI') *3600/60 + To_Char (D.ins_dt, 'SS') as hhmmssi,
Substr(L.top_left_x,1,2) as exi,
Substr(L.top_left_y,1,2) as eyi

From DLYTRN D, LOCMST L
Where D.WH_ID = L.WH_ID
And D.frstol = L.stoloc
And D.trndte >= trunc (sysdate) -5
And D.oprcod = 'UPK'
And D.actcod in ('CASPCK','PLAPCK','OTRPCK')
And D.usr_id <> all ('EDREIS','ARSILVA','EGONCALVES','AAKOJO')
And D.usr_id = 'ADFLORENCIO'
And L.top_left_x > '0'
And L.top_left_y > '0'
Order By D.usr_id, To_Char (D.trndte, 'DD'), To_Char (D.ins_dt, 'HH24:MI:SS')))

I thought I’d do another query inside the case saying that if the initial place acronym is "X" it needs to go through the intersection points "A", "B" etc. and at the end add the two. but I don’t know how to.

Query that brings only intersection points :

[Select  
Substr(stoloc,2,2) as inter,
Substr(L.top_left_x,1,2) as exi, 
Substr(L.top_left_y,1,2) as eyi 

From LOCMST L 
Where L.top_left_x > '0' 
And L.top_left_y > '0' 
And L.stoloc like '1%PD-%'

Below follows a layout image to make it easier to understand the intersection points.

inserir a descrição da imagem aqui

  • You are using 3 databases?

  • Not just a friend.

  • mysql sql-server oracle ?

  • These are just the tags I put in, the database I use accepts a bit of each language

  • Yes, the tags have relationship with what you use, if I had a reply with mysql and your database for oracle will have a lot in the query will not be accepted in the last database, ie use the tags that has direct relation to your problem.

  • Got it, sorry there, I’m still learning, actually until today I learned only reading I have no technical knowledge, know that our database is oracle, sql I know that runs on it normal pq do all query with sql language know that it accepts some other languages

  • the SQL is generic, see tag your rules for use. I changed your tag to oracle which in case is the most correct.

  • Thanks for the help

  • From what I understand you want to walk a route of pre-defined streets and pick up the total spent on distance, correct? Would you have the de-stop coordinates of each street intersection on a table? In this case, if your oracle is !! g up, could be used a block with with SEARCH BREADTH FIRST

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.