Finding Distance between two zipcodes with longtitude and latitude

Want to find distance between two zipcodes that have their latitude and longitude stored in a table.
The table is as follows
CREATE TABLE distance (zipcode VARCHAR2, LNG NUMBER, LAT NUMBER)
I couldn't come up with a calculation or understand the mathematical calculation on line.. Can you help me with some stored procedure that will do..?
Thanks

There is no logical complexity in your query besides knowing the basics of
http://en.wikipedia.org/wiki/Spherical_coordinates
Also, the table name "Distance" cannot be more confusing; what you have is essentially "PointsOnSphere".
select R*sqrt(
(sin(pi-p1.lng)*cos(p1.lat)-sin(pi-p2.lng)*cos(p2.lat))* (sin(pi-p1.lng)*cos(p1.lat)-sin(pi-p2.lng)*cos(p2.lat))
+
(sin(pi-p1.lng)*sin(p1.lat)-sin(pi-p2.lng)*sin(p2.lat))*
(sin(pi-p1.lng)*sin(p1.lat)-sin(pi-p2.lng)*sin(p2.lat))
+
(cos(pi-p1.lng)-cos(pi-p2.lng))*(cos(pi-p1.lng)-cos(pi-p2.lng))
from distance p1, distance p2
where R is the radius of Earth, and pi=3. Don't forget to convert angular degrees into radiants before you plug in them into the query above
Correction: This was euclidean distance sqrt((x1-x2)^2+(y1-y2)^2+(z1-z2)^2) between the points (x1,y1,z1) and (x2,y2,z2). Spherical distance is
sqrt(
(R*(colatitude1-colatitude2))^2+
(R*sin(colatitude1-colatitude2)*(longtitude1-longtitude2))^2
Message was edited by:
Vadim Tropashko

Similar Messages

  • Distance between two points with degrees and minutes

    I would like to store several points in the database given degrees and minutes as position. In this example I have point 1 that is E 150, 0/S 30, 0 and points 2 that is E 150, 0/S 30.1. For example if I enter 2 km as distance from position of point 1 I would like the search to return all points witin 2 km.(should return points 2 that is very near)
    If I run the query
    SELECT c.name
    FROM cola_markets_cs c
    WHERE
    SDO_WITHIN_DISTANCE(c.shape,
    SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE(150.0, 30.1, NULL), NULL, NULL),
    'distance=10000 unit=KM')
    = 'TRUE';
    I get result both position 1 and 2, but if I decrease to distance=1000 no rows is returned.
    Can you see what I am doing wrong here?
    Can I also combine SDO_WITHIN_DISTANCE with SDO_NN_DISTANCE so I can ask for all points 10 km in distance from the reference point and I can also see the actual distance for each point?
    Thank you
    I have tested with the following code. Do I save the position wrong..?
    CREATE TABLE cola_markets_cs (
    mkt_id NUMBER PRIMARY KEY,
    name VARCHAR2(32),
    shape MDSYS.SDO_GEOMETRY);
    INSERT INTO cola_markets_cs VALUES (
    1,
    'Point 1',
    MDSYS.SDO_GEOMETRY(
    2001,
    8307,
    MDSYS.SDO_POINT_TYPE(150.0, 30.0, NULL),
    NULL,
    NULL
    INSERT INTO cola_markets_cs VALUES (
    2,
    'Point 2',
    MDSYS.SDO_GEOMETRY(
    2001,
    8307,
    MDSYS.SDO_POINT_TYPE(150.0, 30.1, NULL),
    NULL,
    NULL
    -- UPDATE METADATA VIEW --
    -- Update the USER_SDO_GEOM_METADATA view. This is required
    -- before the Spatial index can be created. Do this only once for each
    -- layer (i.e., table-column combination; here: cola_markets_cs and shape).
    INSERT INTO USER_SDO_GEOM_METADATA
    VALUES (
    'cola_markets_cs',
    'shape',
    MDSYS.SDO_DIM_ARRAY(
    MDSYS.SDO_DIM_ELEMENT('Longitude', -180, 180, 10), -- 10 meters tolerance
    MDSYS.SDO_DIM_ELEMENT('Latitude', -90, 90, 10) -- 10 meters tolerance
    8307 -- SRID for 'Longitude / Latitude (WGS 84)' coordinate system
    -- CREATE THE SPATIAL INDEX --
    -- Must be R-tree; quadtree not supported for geodetic data.
    CREATE INDEX cola_spatial_idx_cs
    ON cola_markets_cs(shape)
    INDEXTYPE IS MDSYS.SPATIAL_INDEX;
    --This search only return if distance is 10 000 km...
    SELECT c.name
    FROM cola_markets_cs c
    WHERE
    SDO_WITHIN_DISTANCE(c.shape,
    SDO_GEOMETRY(2001, 8307, SDO_POINT_TYPE(150.0, 30.1, NULL), NULL, NULL),
    'distance=10000 unit=KM')
    = 'TRUE';
    --According to this search the distance to point 1 is 3331198,72256398,
    --this  should be zero..
    SELECT
    c.mkt_id, c.name, SDO_NN_DISTANCE(1) dist
    FROM cola_markets_cs c
    WHERE SDO_NN(c.shape,
    sdo_geometry(2001, 8307,sdo_point_type(150.0, 30.1, NULL), NULL, NULL),
    'sdo_num_res=2', 1) = 'TRUE' ORDER BY dist

    Hi,
    What version of Oracle are you using? I got this using your example:
    SELECT
    c.mkt_id, c.name, SDO_NN_DISTANCE(1) dist
    FROM cola_markets_cs c
    WHERE SDO_NN(c.shape,
    sdo_geometry(2001, 8307,sdo_point_type(150.0, 30.1, NULL), NULL, NULL), 'sdo_num_res=2', 1) = 'TRUE'
    ORDER BY dist ;
    MKT_ID NAME DIST
    2 Point 2 0
    1 Point 1 11085.3285
    This is 10.1.0.4
    Also:
    Can I also combine SDO_WITHIN_DISTANCE with SDO_NN_DISTANCE so I can ask for all points 10 km in distance from the reference point and I can also see the actual distance for each point?
    No, but you can add a distance calculation:
    SELECT
    c.mkt_id, c.name, SDO_GEOM.SDO_DISTANCE(c.shape,sdo_geometry(2001, 8307,sdo_point_type(150.0, 30.1, NULL), NULL, NULL),1) dist
    FROM cola_markets_cs c
    WHERE SDO_WITHIN_DISTANCE(c.shape,
    sdo_geometry(2001, 8307,sdo_point_type(150.0, 30.1, NULL), NULL, NULL), 'distance=10 unit=km') = 'TRUE'
    ORDER BY dist ;

  • Bestway to find difference between two roles in quality and production

    We have a process of collecting su53 dump and then analyze for missing authorization . However some time although everything works fine in quality , it fails in production . Hence I want to know a simple methodology to compare roles in quality and production to know difference ... Can anyone share best methodolgy being used in your setup ?
    NPB

    (1)How to find the difference between two dates at Universe level and at report Level in IDT?
    DaysBetween ([Sale Date];[Invoice Date]) returns 2 if [Sale Date] is 15 December 2001 and [Invoice Date] is 17 December 2001.
    (2) How to change format of dates from YYYY/MM/DD to DD/MM/YYYY in IDT at prompt level ?
    =FormatDate(ToDate(YOUR DARE OBJECT);"YYYY/MM/DD");"dd'/'MM'/'yyyy")
    =To_Char (object name, required format)
    Find the below link for more info.
    http://scn.sap.com/community/semantic-layer/blog/2014/04/18/bi41-business-layer-enhancements--create-display-format
    (3)What is VIEWS in IDT of data foundation layer when we right click? could u plz give one example where exactly we use VIEWS?
    A custom data foundation view is a subset of the data foundation Master view. You can use views when editing a large data foundation, and interested in working with a subset of tables. You can define multiple custom views for the data foundation due to the complexity of the data warehouse.
    Essentially, need created views for each individual star scheme (like Sales, Production, Finance, Accounting, etc.) plus a view for eachcomplex dimension structure (like Business Partner, Material, Customer, Plant etc.),
    Find the below link for more info.
    http://scn.sap.com/docs/DOC-54422
    (4) How to represent & report my IDT data in dashboards? could u plz explain the steps?
    Please find the below link: http://scn.sap.com/docs/DOC-27559

  • Shortest distance between two line segments

    Hi.
    I am looking for the code of the "Shortest distance between two line segments". I would appreciate if anyone has and willing to share.
    I can find some in the net but its in VB and i am not familiar with it.
    THanks a lot.
    regards,

    There are a couple of things that are not clear:
    What determines the rotation speed and lenght of each stick at any given time?
    What is the program allowed to do to prevent collision (change speed/direction, change radius, stop everything)
    Since you want to prevent collision, you need a predictive algorithm. Once they overlap, the collision has already happened. Too late!
    What information does your algorithm get (e.g. r1, r2, theta1, theta2, delta-thetat1, delta-theta2, etc.), i.e. does the program only get static information and need  to construct the trajectory from sequential history data or does it get dynamic information about speed and direction?
    The trivial answer would be to just keep r1+r2 < distance(P1,P2). This will prevent all "potential" collisions.
    LabVIEW Champion . Do more with less code and in less time .

  • Find gap between two dates from table

    Hello All,
    I want to find gap between two dates ,if there is no gap between two dates then it should return min(eff_dt) and max(end_dt) value
    suppose below data in my item table
    item_id    eff_dt           end_dt
    10         20-jun-2012     25-jun-2012
    10         26-jun-2012     28-jun-2012 There is no gap between two rows for item 10 then it should return rows like
    item_id eff_dt end_dt
    10 20-jun-2012 28-jun-2012
    item_id    eff_dt           end_dt
    12         20-jun-2012     25-jun-2012
    12         27-jun-2012     28-jun-2012 There is gap between two rows for item 12 then it should return like
    item_id eff_dt end_dt
    12 20-jun-2012 25-jun-2012
    12 27-jun-2012 28-jun-2012
    I hv tried using below query but it giv null value for last row
    SELECT   item_id, eff_dt, end_dt, end_dt + 1 AS newd,
             LEAD (eff_dt) OVER (PARTITION BY ctry_code, co_code, item_id ORDER BY ctry_code,
              co_code, item_id) AS LEAD,
             (CASE
                 WHEN (end_dt + 1) =
                        LEAD (eff_dt) OVER (PARTITION BY ctry_code, co_code, item_id ORDER BY ctry_code,
                         co_code, item_id, eff_dt)
                    THEN '1'
                 ELSE '2'
              END
             ) AS new_num
      FROM item
       WHERE TRIM (item_id) = '802'
    ORDER BY ctry_code, co_code, item_id, eff_dtI m using oracle 10g.
    please any help is appreciate.
    Thanks.

    Use start of group method:
    with sample_table as (
                          select 10 item_id,date '2012-6-20' start_dt,date '2012-6-25' end_dt from dual union all
                          select 10,date '2012-6-26',date '2012-6-26' from dual
    select  item_id,
            min(start_dt) start_dt,
            max(end_dt) end_dt
      from  (
             select  item_id,
                     start_dt,
                     end_dt,
                     sum(start_of_group) over(partition by item_id order by start_dt) grp
               from  (
                      select  item_id,
                              start_dt,
                              end_dt,
                              case lag(end_dt) over(partition by item_id order by start_dt)
                                when start_dt - 1 then 0
                                else 1
                              end start_of_group
                        from  sample_table
      group by item_id,
               grp
      order by item_id,
               grp
       ITEM_ID START_DT  END_DT
            10 20-JUN-12 26-JUN-12
    SQL> SY.

  • Distance between two PCIe x 16 slot of P55 GD85

    Hello,
    Does anyone have an idea what is the clear distance between two PCIe x 16 slot of P55 GD85? planning to get one if my 2 x GTX 285 with modified cooling fan will fit in. each VGA with modified fan is around 55mm in height.
    thank you,   

    Exactly, there was no "rude" intention or the will to provoke you behind my previous answer.  In fact, I spent 15 minutes to find a ruler in order to measure the port distance on three different ATX Board to make sure I am not telling you anything wrong.  I would not have bothered to do that if I had been planning to write a rude reply. 
    [On the flip side: Personally, I find it kind of rude that you are accusing me of 'rudeness'.  However, I suggest we better drop the whole 'who is really being rude here' discussion.]
    Quote
    The distance between the center lines of two neighbouring slots is always ~ 2.05cm.  There are two slots between the PCI-E-x16 slots of the P55-DG85.  Simply do the math!
    Quote
    I am not a mathematician
    The distance between the center lines of the two PCI-E-x16-slots of the P55-GD85 is ~6.15cm (there are two more slots in between --> 2.05cm x 3).
    This means that this ...
    Quote
    each VGA with modified fan is around 55mm in height.
    ... should actually fit.

  • Distance between two pixel in screen

    Hi all ,
    How can I get the distance between two pixel of the screen .
    Thanks and Regards
    Anshuman Srivastava

    You're welcome. Do spend more time with the API, there are a wealth of methods available in classes like Toolkit, SwingUtilities, Utilities and Robot that help solve many rather obscure problems.
    db

  • How to find differene between two time fields??

    Hi Experts,
    I am trying to find difference between two time fields,  I have created two formula variables by using replacement path for the two time fields, I have taken dimension key NUMBER, because of this time format is converting to numbers for example if the time is 13:20:10 then it is converting to 1,32,010 then it is calculating, I am getting wrong values.
    Is there any options to find out the difference between two time fields.
    Thanks in advance,
    Venkat.

    use COPF_DETERMINE_DURATION. Its better you do it in data model itself.
    If you have date and time seperately use command
    use CONVERT TIMESTAMP command and
    then use this function module to get the difference in
    timestamp
    CCU_TIMESTAMP_DIFFERENCE
    us this in conjunction with the below function module
    DAYS_BETWEEN_TWO_DATES
    Edited by: Ananda Theerthan on Jan 21, 2010 7:18 AM

  • Distance between two objects

    Hi folks,
    Who knows how I can discover the distance between two selected objects without using neither guides nor grids?
    Thanks.

    How do imagine this would working without using guides or grids? The way I normally do it is:
    1. Drag out a guide to point A
    2. Drag out a guide to point B
    3. Hold shift and put the mouse cursoe between the two -- it shows you the distance
    You could also use the measuring tool (click and hold the rectangle tool in the tool pallette.)
    Or even just draw a rectangle and look at the width in the property panel. That's a fast and easy method I use sometimes.
    Aaron Beall
    http://fireworks.abeall.com

  • Distance between two GPS points

    Is there an inbuilt function in PL/SQL for calulating the distance between two GPS (lat/long) points?
    I'm using Oracle 9i. There's a thing called SDO_GEOM available, but I'm not sure if this is what its used for or if it's the best option.

    If the earth is a complete globe and its circumference is 40000km,
    I make the function as follows.
    create ore replace
    function distance
    (a_lat number,a_lon number,b_lat number, b_lon number)
    return number is
    circum number := 40000; -- kilometers
    pai number := acos(-1);
    a_nx number;
    a_ny number;
    a_nz number;
    b_nx number;
    b_ny number;
    b_nz number;
    inner_product number;
    begin
    if (a_lat=b_lat) and (a_lon=b_lon) then
    return 0;
    else
    a_nx := cos(a_lat*pai/180) * cos(a_lon*pai/180);
    a_ny := cos(a_lat*pai/180) * sin(a_lon*pai/180);
    a_nz := sin(a_lat*pai/180);
    b_nx := cos(b_lat*pai/180) * co s(b_lon*pai/180);
    b_ny := cos(b_lat*pai/180) * sin(b_lon*pai/180);
    b_nz := sin(b_lat*pai/180);
    inner_product := a_nx*b_nx + a_ny*b_ny + a_nz*b_nz;
    if inner_product > 1 then
    return 0;
    else
    return (circum*acos(inner_product))/(2*pai);
    end if;
    end if;
    end;
    I rewrite it by using the factorization and the triangle function's sum and difference formulas:
    cos(x-y) = cos(x)cos(y)+sin(x)sin(y)
    As result, this function is same to the 1st method of Billy Verreynne.
    create or replace
    function distance
    (a_lat number,a_lon number,b_lat number, b_lon number)
    return number is
    circum number := 40000; -- kilometers
    pai number := acos(-1);
    dz number;
    dx2y2 number;
    inner_product number;
    begin
    if (a_lat=b_lat) and (a_lon=b_lon) then
    return 0;
    else
    dz := sin(a_lat*pai/180)*sin(b_lat*pai/180);
    dx2y2 := cos(a_lat*pai/180)*cos(b_lat*pai/180)*cos((a_lon-b_lon)*pai/180);
    inner_product := dz*dz + dx2y2;
    if inner_product > 1 then
    return 0;
    else
    return (circum*acos(inner_product))/(2*pai);
    end if;
    end if;
    end;
    Message was edited by:
    ushitaki

  • Can music be shared between two devices with different apple IDs?

    Can music be shared between two devices with different apple IDs?

    The Apple Support Communities are an international user to user technical support forum. As a man from Mexico, Spanish is my native tongue. I do not speak English very well, however, I do write in English with the aid of the Mac OS X spelling and grammar checks. I also live in a culture perhaps very very different from your own. When offering advice in the ASC, my comments are not meant to be anything more than helpful and certainly not to be taken as insults.
    iTunes content can be commingled in the iTunes library on a computer and synced to iOS devices. The computer must be authorized to use the content from the respective Apple IDs in the iTunes Store menu.

  • How to count days between two dates excluding saterady and sunday

    Hi all
    iam working on oracle sql/plsql.
    In my application , i need to caliculate leave days between two dates excluding saterady and sunday
    Please tell me the solution if any one knows
    thanks in advance ,
    balu

    More modern version:
    WITH date_tab AS
    (SELECT TO_DATE ('&from_date', 'dd-MON-yyyy')
    + LEVEL
    - 1 business_date
    FROM DUAL
    CONNECT BY LEVEL <=
    TO_DATE ('&to_date', 'dd-MON-yyyy')
    - TO_DATE ('&from_date', 'dd-MON-yyyy')
    + 1)
    SELECT business_date
    FROM date_tab
    WHERE TO_CHAR (business_date, 'DY') NOT IN ('SAT', 'SUN');Thank you,
    Tony Miller
    Webster, TX
    Never Surrender Dreams!
    JMS
    If this question is answered, please mark the thread as closed and assign points where earned..

  • How to measure distance between two points uisng uiaccelerometer

    Hello all,
    I am trying to measure distance between two points.So for that i am used uiaccelerometer but its give only rotation changes. I am moving my whole device from one point to another point so for that all x,y & z changes remain same. So how can get the device movement for that?
    Thank you..

    UIAccelerometer does not give rotation changes, it senses acceleration in each of the 3 axis in g-force units. Moving in a plane from one point to another and stopping will result in a net g-force in that axis of zero. To get distance one has to measure the initial acceleration and then the time before a deceleration is detected. It gets really complicated in real life since the start and stop are not instantaneous.

  • How do i link itunes between two computers with different Apple ID's

    how do I link itunes between two computers with different Apple ID

    You need to set up two user accounts on the mac.  System Preferences>Users & Groups.  Then each user can set up apple IDs for itunes and icloud any way they want.

  • Is there any css to vary the distance between two items in apex

    Hi,
    Is there any css to vary the distance between two items ie two columns  horizontally / vertically in apex application at page line level
    Regards,
    Pavan

    Hi ,
    I done what u suggested above  but  i ll tel u clearly
    i have name,plot no,street,city,distict,state,country,phone no,pincode items.. i need to align this items like
    --------------------------------------------------------------------------main region----------------------------------------------------------------------------
    --left region-------------------------------------------middle region------------------------------------------------------right region-------------------
    name,___________
    plot no,_________
    street,________
    city,___________                                    distict,_________                                              
    state,__________                                   country,_________                                                  nothing in it
    phone no,__________                              pincode_________
    to achieve this wat i have to do
    Thanks,
    pavan

Maybe you are looking for

  • How do I back up Wireless Hard Drive using Time Machine

    I have a MacBook Pro and I'm running OSX Lion. I'm having trouble setting up time machine to back up two USB external hard drives (named Portable iTunes and Portable iPhoto) connected to my Airport Extreme Base Station. I have a time capsule with a 3

  • Custom attributes in Service Registry

    Hi! Is it possible to use custom attributes in Service Registry? And if Yes, where can these attributes be displayed in Business Service Control or Registry Control? Thanks

  • How to send a link in maverick

    Since I upgraded to Maverick I don't see an easy way to send the link of a safari page I am viewing.  When I use "send the page" it usually doesn't incude the web address or any body??? Ideas??

  • OIM Custom reports - Un-Identified Accounts Report

    HI, I am working on *OIM custom reports . I was trying to get custom Un-Identified Accounts Report. Is there an example for the query Unidentified Account Report? I make query from oim10g is not working, especially table RCD, RCM. What is table name

  • Incompleteness Procedure - Navigation to required fields.....

    Hello, I noticed that on the portal side as well as the GUI, if you don't fill standard required fields the error message will have a link that will navigate you directly to the field in question to enter values in the given field.  I want to impleme