shortest distance

Hi, I have a table of geometry of point, to select the intermediate points which gives the shortest between two predefined points (point 1 and point 2) using sdo_geom.sdo_distance.

ID X Y
point 1: 6143 - 87.910994 41.982889
point 2: 6048 - 87.907813 41.982816

intermediate points:

point 3: 5991 - 87.909845 41.9828835
point 4: 5994 - 87.908649 41.98287
point 5: 5993 - 87.908798 41.9826835
point 6: 6033 - 87.908493 41.9825935

any suggestions?
Thank you

If you want to find 3 points, you must use 3 loops FOR and concat 3 indexes for the ROAD:

SET SERVEROUTPUT ON SIZE 900000;

DECLARE
  TYPE points IS TABLE OF sdo_geometry;

  ipoints points :=  points();
  apoint sdo_geometry := sdo_geometry(2001, 8307, sdo_point_type(-87.910994, 41.982889 , 0), NULL , NULL);
  epoint sdo_geometry := sdo_geometry(2001, 8307, sdo_point_type(-87.907813, 41.982816 , 0), NULL, NULL);   

  dist   NUMBER := 0;
  sumd   NUMBER := 9999999;

  route  VARCHAR2(200) := '';

BEGIN

  --initialize
  ipoints.extend(3);
  ipoints(1) := sdo_geometry(2001, 8307,sdo_point_type( -87.905464, 41.967392, 0), NULL, NULL);
  ipoints(2) := sdo_geometry(2001, 8307,sdo_point_type( -87.904189, 41.967377, 0), NULL, NULL);
  ipoints(3) := sdo_geometry(2001, 8307,sdo_point_type( -87.901859, 41.9673795,0), NULL, NULL);

  --brute force
  FOR i IN 1..3 LOOP
    FOR j IN 1..3 LOOP
      FOR k IN 1..3 LOOP
          --dont use same point twice !
          IF (i=j OR i=k OR j=k) THEN CONTINUE;END IF;
          dist  := sdo_geom.sdo_distance(apoint    ,ipoints(i),1) +
                   sdo_geom.sdo_distance(ipoints(i),ipoints(j),1) +
                   sdo_geom.sdo_distance(ipoints(j),    epoint,1);
          --get the actual route
          IF sumd>dist THEN
            sumd  := dist;
            route := to_char(i)||to_char(j)||to_char(k);
          END IF;
      END LOOP;
    END LOOP;
  END LOOP;

  --length of shortest path
  dbms_output.put_line ('route='||route);
  dbms_output.put_line (sumd);
END;

route=123
3627,935355905372

The brute force method (in this very simple case) needs more iterations for each intermediate point (n * n), so it cannot be used for a large number of points.
In this thread there are links and advice for other methods in these cases.

POINTS ITERATIONS
----------------------------
1            1
2            4
3           27
4          265
5         3125
6        46656
...
10 10000000000

BTW. You should use markup bat, to format your code and the intention of the lines, you see the difference, not you?

Tags: Database

Similar Questions

  • How to format a cell to calculate the distance based on names of cities in the other two cells

    I am using 3.6.1 numbers to display distances in Miles or Km in column 3 based on the names of the cities in columns 1 and 2

    For example:

    "Boston' appears in the cell"A1"and"New York"in cell"B1. "  I would like that the cell "C1" then automatically read "215 Miles.

    I could not find a way to do it. Any help would be appreciated. Thank you in advance.

    Hi Nicolas,.

    Which you will store the information needed for the numbers compute these results?

    If she wants to be a direct calculation of the shortest distance, you will need the geographical location of each of the two cities, as well as an algorithm/formula for the calculation of the circle distance between these two places. Boston-New York, is about 190 miles.

    On distance (215 miles) of driving, the calculations are a bit more complicated. They require access to a wide range of data including a "route map" for the area that you want to include, then an algorithm that can look up cities, determine a route between them, find the distance of conduct for each section of this road and add them to the top.

    If you place a strict limit on the number of cities and have access to networks "driving distance" which were (and maybe still) included with the paper maps printed of gas stations or AAA (to the United States), CAA (Canada), the AA (in Britain) and other organizations to motorist elsewhere in the world, you might be able to manage it with one or more lookup tables and a search feature appropriate in column C.

    Otherwise, you may incur development of Google (or one of several others) team to reinvent the wheel, so to speak, and provide you a stand-alone application to do this.

    Or you can choose to use a more suitable and existing tool. Some choices are MapQuest, OpenStreetMap, Bing Maps, Google Maps, or maps (Apple) (included in recent versions of Mac OS X).

    Kind regards

    Barry

  • change the position of right click Refresh

    Hello, for some time I had firefox.

    So, when you right click on a page in its new version, you get a menu with icons in the top row. I'm used to cool off even being a low item on the list, but now he is on the side, a sort of boring post to navigate to and can hit front/rear/favorite. Up and down queries are much easier to do on a mouse that side by side or diagonal lines.

    I would like to as for the button refresh to be the first item of the left, where is back, which is the shortest distance. I'm a compulsive refresher to right click. (otherwise, I have to use my left hand to do a refresh, or go SLSA the path up to the tiny button in the address bar)

    You can set one of these four points as the whole first giving him a - moz-box-ordinal-group: 0! important CSS rule.

    #context-back
    #context-forward
    #context-reload
    #context-stop

    Add code to the file userChrome.css below default @namespace.

    @namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); /* only needed once */
    
    #context-reload { -moz-box-ordinal-group:0 !important; }
    

    The file userChrome.css (UI) customization and userContent.css (Web sites) are located in the folder of chrome in the Firefox profile folder.

    You can use this button to go to the Firefox profile folder currently in use:

    If you prefer the text labels on the shortcut menu rather than the icons for the back, forward and Reload and the star to bookmark the page and then you can install the extension "Classic theme restaurant"
    You can find the option for labels of text instead of icons in the context menu in Options/preferences of the extension of the TRC in the section general UI.

    • Replace page with label context menu icons (back, forward, stop, reload, page bookmark)

    Note that you can navigate through the icons in the context menu from the top and to the bottom of the press and the cursor keys ENTER to invoke the action as you can with other items in the context menu.

  • B570 wifi headache with Atheros AR9285 Win7

    Hi, please help!

    Has obtained a - beautiful machine - B570 running 64-bit Win7. The wifi seems to be terrible with this wireless adapter. It reads the signal from my router pretty well, even says that it is excellent, but it has real problems, try to connect to the internet. Must be the shortest distance possible from the router so that it can maintain an internet connection. All other devices that we have (2 laptops to work, 2 ipods, 2 smartphones) have absolutely no problem connecting to the internet all over the House but this laptop really struggles.

    I tried several versions of drivers and it seems that the old drivers of the '8' series work best, but are unstable. Have now reverted back to the original from the Lenovo Web site drivers. Looks like others have had problems with this network adapter but I've not seen a lot of resolutions. I spent many an hour to try to address this issue and it is now starting to drive me crazy.

    Any help appreciated gratefully.

    djboyo


  • Follower of the mouse of rotation with easing

    I'm terrible at math and having a problem to reach my goal.

    http://www.newgrounds.com/dump/item/6e5cde6c6b94de74119aac82c43312d2 - example

    It works just fine, but what I want to do is have each object to follow the rotation at different speeds. I want that every MC having "Acceleration".

    I can't understand how to run a little slower than the mouse itself. As a result, just dead on, same speed as the mouse moves, it moves.

    Related to mcMouseFollower.as MovieClip class.

    I have my main class the following:

    package {}

    import flash.display. *;

    import flash.events.Event;

    SerializableAttribute public class MAIN extends MovieClip {}

    public var follower: mcMouseFollower;

    public void MAIN () {}

    the constructor code

    Tracker = new mcMouseFollower();

    Follower.x = stage.stageWidth / 2;

    Follower.y = stage.stageHeight / 2;

    stage.addChild (follower);

    stage.addEventListener (Event.ENTER_FRAME, frameLoop);

    }

    public function frameLoop (event: Event): void {}

    Check out the coordinates of the mouse to discover the angle

    var cy:Number = stage.mouseY - follower.y;

    var cx:Number = stage.mouseX - follower.x;

    var Radians: Number = Math.atan2 (cx, cy); / / Find the angle

    var degrees: Number = Radians * 180 / Math.PI;// convert to degrees of rotation

    Rotate

    Follower.rotation = degrees;

    }

    }

    }

    To do this manually, you need to find the change in rotation between the follower.rotation and the degrees of calculated. Then, you apply some of this difference. So if you want to have the rotation of the rod move 1/10 of the path to the destination of your choice each image, calculate the change in the rotation needed to point to the mouse, then multiply by 0.1 and apply this rotation changed to follower.rotation. This does not exactly work as tweens that you configure in Flash because it will not have an exact end time. Instead, each image rotation reduces the difference in new rotation of half. It will resemble an ease of exit. You can check when it is thin enough (for example, the difference is less than 1 degree) and just snap to your final rotation rather than continue to settle for halfway.

    You'll want to know how to work the degrees of rotation. Pointing to the right is 0 degrees, rotation to the right there is positive, go to 180 that points to the left. From 0 degrees and rotating timer causes the downward rotation value, entering negative numbers, from 0 to-180 (pointing to the left). So when you try to interpolate a value through the left direction you have a problem, since the numbers of jump from-180 to 180 at that time here.

    To solve this * West * problem, you detect if the rotation must be changed by more than 180 and you adjust accordingly for the direction of rotation moves the shortest distance to the rotation of the target rather than the long way around. The calculation in the SmartRotationPlugin of the packaging of GTween is a good way to handle this:

    https://code.Google.com/p/Pipoca/source/browse/trunk/classes/com/gskinner/motion/plugins/S martRotationPlugin.as? r = 9

    Here's the corrected code (starting after your calculation of degrees):

    var deltaDegrees:Number = degrees - follower.rotation;

    deltaDegrees % = 360;

    If (deltaDegrees > 180)

    {

    deltaDegrees-= 360;

    }

    ElseIf (deltaDegrees<>

    {

    deltaDegrees += 360;

    }

    Rotate

    Follower.rotation = degrees;

    Follower.rotation += deltaDegrees * 0.1;

    You can also consider using a tween as GTween for your tween engine: http://www.gskinner.com/libraries/gtween/

  • Shortest path

    I have this table:
    with t as (
      select 'A' source, 'B' destination, 7 meter from dual
      union all
      select 'A' source, 'C' destination, 9 meter from dual
      union all
      select 'A' source, 'F' destination, 14 meter from dual
      union all
      select 'B' source, 'C' destination, 10 meter from dual
      union all
      select 'B' source, 'D' destination, 15 meter from dual
      union all
      select 'C' source, 'D' destination, 11 meter from dual
      union all
      select 'C' source, 'F' destination, 2 meter from dual
      union all
      select 'D' source, 'E' destination, 6 meter from dual
      union all
      select 'E' source, 'F' destination, 9 meter from dual
    )
    select * from t;
    How to know the shortest path from a source to a destination? Suppose that, from A to F. can show us the shortest path using SQL? TX in advance.

    Something that I almost never use - hierarchical queries. So therefore the hack of the dynamic assessment. I guess that there is a better and more elegant way to calculate the sum of the distances?

    // the hack - evaluate a dynamic math expression and return the result
    SQL> create or replace function EvalMath( math varchar2 ) return number is
      2          n       number;
      3  begin
      4          execute immediate
      5                  'begin :0 := '||math||'; end;'
      6          using out n;
      7
      8          return( n );
      9  end;
     10  /
    
    Function created.
    
    SQL>
    SQL> with paths(from_point,to_point,distance) as (
      2          select 'A', 'B', 07 from dual
      3          union all
      4          select 'A', 'C', 09 from dual
      5          union all
      6          select 'A', 'F', 14 from dual
      7          union all
      8          select 'B', 'C', 10 from dual
      9          union all
     10          select 'B', 'D', 15 from dual
     11          union all
     12          select 'C', 'D', 11 from dual
     13          union all
     14          select 'C', 'F', 02 from dual
     15          union all
     16          select 'D', 'E', 06 from dual
     17          union all
     18          select 'E', 'F', 09 from dual
     19          union all
     20          select 'B', 'E', 15 from dual
     21  ),
     22  grid as(
     23          select
     24                  level+1                                                 as POINTS,
     25                  to_point,
     26                  sys_connect_by_path(from_point,'/')||'/'||to_point      as PATH,
     27                  '0'||sys_connect_by_path(distance,'+')                  as DISTANCE
     28          from    paths
     29          start with from_point = 'A'
     30          connect by prior to_point = from_point
     31  )
     32  select
     33          points,
     34          path,
     35          distance,
     36          EvalMath(distance)      as METRES
     37  from       grid
     38  where      to_point = 'F'
     39  order by 4
     40  /
    
        POINTS PATH            DISTANCE                 METRES
    ---------- --------------- -------------------- ----------
             3 /A/C/F          0+9+2                        11
             2 /A/F            0+14                         14
             4 /A/B/C/F        0+7+10+2                     19
             4 /A/B/E/F        0+7+15+9                     31
             5 /A/C/D/E/F      0+9+11+6+9                   35
             5 /A/B/D/E/F      0+7+15+6+9                   37
             6 /A/B/C/D/E/F    0+7+10+11+6+9                43
    
    7 rows selected.
    
    SQL> 
    

    So the way the shorter has 3 points, is A through C to F over a distance of 11 meters. But there must be a better way to get the distances summed up...

  • Distance and rounds of training swimming errors

    Hello...

    I have the new Apple Watch series 2. I make the swim in our pool inner community twice a week, and I used the new watch swimming twice now. Both times the watch Gets the distance of towers and evil. Here are some details:

    Our community pool is 25 yards - long we checked this by measuring it ourselves. I use the session pool swim.

    The first time I used the watch, I swam 44 laps, which is 1 100 yards. Training app reported that I had made 62 laps and 1 550 yards.

    The second time (today), I swam 50 laps, which is 1250 yards. Training app reported that I had made, 80 laps and 2000 yards.

    I always swim in the same way,-1 lap breaststroke of 2 rounds side stroke, rear race 1 lap. Then, again. I don't have flip turn.

    Any ideas or help greatly appreciated.

    Hello

    I suggest that raise you this issue with Apple supports, taking advantage of your initial 90 days of free technical support by phone of the coverage:

  • Manual lap (or segment) the pace and distance

    Is there a way (or will there be a way) to see tour distance and pace on the lookout for series 2? I want to set manual towers (or "segments") on trips and see my stats in real time, and not only in the application phone later. I've used this feature on my garmin all the time and it is very useful when the PACE work or attend training sessions. I also use strava, but I don't see either this function in their application.

    Hello

    To mark a segment (for example a tower) year running, double-tap the screen, then wait the segment summary appears in the display.

    More information:

    Work with your Apple Watch - Apple Support

  • is your Apple Watch unplug your phone at a certain distance?

    I recently bought a series of Apple Watch 1 and I was wondering if at a distance, only he disconnects your iPhone?

    In addition, who is the home button, and what are the objectives of the buttons?

    Hello

    Once they have been paired, your iPhone and Apple Watch will remain paired until they are non-matched manually. However, they can become disconnected or connected (several times), while that always paired.

    Disconnections can be normal, for example when the watch loses the Bluetooth connection with the matched iPhone and no known Wi - Fi network is available.

    Normal Bluetooth range is about 10 meters/33 feet. Actual range varies in practice due to interference with wireless (including, for example, because of the walls), but you don't need necessarily to have your iPhone on or just around you (scope of arms, for example) for devices to keep their Bluetooth connection.

    Once they have are disconnected, they should reconnect automatically after close moments being brought back.

    More information:

    On Bluetooth and Wi - Fi on Apple Watch - Apple Support

    valem1234 wrote:

    .. In addition, who is the home button, and what are the objectives of the buttons?

    You can find these resources useful:

  • How to assign to the logic of distance in a separate in Logic Pro environment physical port entrance

    Is it possible to assign the logical KEYBOARD with a separate entrance in the port of entry of environmental Logic Pro physics?

    Thank you for your advice.

    I don't think so.  Logic of distance is considered to be a controller. Controller input data stream are made (by logic) before stopping the logic entry in physics. I "think" (I'm not an expert on remote logic) that the flow of midi is available on the port of the sum.

    I'm still not aware that you can change the channel of the South on the logic of distance. So it must be channel a (connected) and your other controllers must be able to have their midi outputs assign other channels if you demux their output.

    (please, correct me if this is not correct about the logic of distance - more conjecture on my part because I use remote logical not)

  • iPhone 6s: stages of collection arrested health, distance etc. How to fix?

    Today my iPhone 6s suddenly stopped to collect steps, distance, or flights is mounted. Nothing I tried was able to fix this, including how to use the health post (even though it is very useful).

    Can anyone suggest some next steps?

    Try these standard troubleshooting steps.

    Reset: hold the Home and Power buttons until you see the Apple logo (10 to 20 seconds).

    If this does not help, you may need to restore your iPhone.

    https://support.Apple.com/en-us/HT204184

    If your backup in iTunes, make sure that it is an encrypted backup.

  • Steps and distance of duplication of the iphone and Apple Watch

    Hi, I would like to know how to disable back into shape and the movement for enforcement of health on my iphone affects the calculations of distance and stage of Apple Watch. IM turning off this option because I found his duplication my distance and steps. My Apple Watch will cease to use my iPhone's gps location?

    I know health app must analyze the data a prioritize my Apple Watch. Instead, his duplication in the info on my iphone and Apple Watch. Im not using third party applications. I do not fear the deactivation of the fitness and followed by my iphone only if my Apple Watch will receive my iphone gps information when I workout.

    Hello

    Health and fitness of the Apple Watch data, iPhone and all the other sources are grouped within the app to health on the iPhone, which allows to adjust the results to avoid any double counting of data from different sources.

    When several sources are available, the application of health uses a single data source for updating your consolidated data. This source is selected according to the order of priority that you set (or that was created automatically - for example, by default, rank devices Apple above sources third party).

  • Why, suddenly, my desktop icons are difficult to align because they can be moved very small distances?

    For years, my desktop icons have acted as if they have so many 'slots' to enter in on the office. But this has never been a problem. They were easier to align because they were right next to each other, or a 'slot' above/below/apart.

    Now, for some reason, I can travel distances of small icons on the desktop, as if they were scalar elements which can be minimally pushed open. Suddenly there are not more "slots", and sort of paradoxically icons are more difficult to assemble and align because I have to keep their repositioning so that they are straight. Before, they were either straight, or a whole notch offline.

    It is NOT correct. Right-click and select Show , and then turn on Align

  • I can't find how to change the distance between two lines of text

    ureself
    ureself

    I mean the vertical distance between the two lines with mmmmm

    http://codeverge.com/Mozilla.support.Thunderbird/line-spacing-how-to-double-space/1402587

    http://forums.mozillazine.org/viewtopic.php?f=39 & t = 403487

  • iPhone health app 6s underestimate distance

    My wife and I have two iPhone 6s, both with chip TSMC, mine is 64 GB and his is 16 GB.

    the question I've seen, is that my application health systematically underestimates the distance we have travelled.

    I realized I'm 1, 5-2 km behind each 10km we walk, that is I lose 15-20%

    I changed 4 iPhones

    I've implemented all the news

    I've done all kinds of resets in settings, data, etc.

    so far, no solution

    someone has an idea what is wrong? Any help please on how to overcome this problem?

    Health app considers the distance my take at specific time interval gps location data - this is a general problem with the gps on the iPhone 6 s?

    Health app systematically underestimates the distance we have travelled.

    I realized I'm 1, 5-2 km behind each 10km we walk, that is I lose 15-20%

    Health in accuracy should improve over time. The steps of each person are of different size.

    Health app considers the distance I took specific interval gps location data

    The primary data comes from count measures. Data GPS are also used, but above all to calibrate the size of your individual step and in the case of step cash does not for some reason any.

    Any help please on how to overcome this problem?

    Experiment with where you hold the iPhone while walking and correspond to this topic. Some places, such as a bag, may not work at all for counting steps. I find that simply keep it's sweatpants Pocket works very well.

Maybe you are looking for