+ Reply to Thread
Results 1 to 8 of 8

Nearest neighbour limited by point type

Hybrid View

  1. #1
    Registered User
    Join Date
    05-26-2013
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    79

    Question Nearest neighbour limited by point type

    Hi all,

    I have a list of x and y xoordinates all with a respective ID and point type (either "RO" or "RP"). I wish to define the nearest other point by ID for every point but I wish to limit this calculation to only points of the opposite type. That is, if I have point ID 315 which is of RO type, I wish to find the nearest point that is of RP type, and visa-versa.

    So far through reading many forums and posts and spending quite some time editing I have managed to create a solution for finding the nearest other point but not limit this to the opposite point type. My scenario is as follows...

    M N O P Q
    1 RO 311 478113 6771180 312
    2 RO 312 478105 6771179 ?
    3 RO 313 478096 6771178 ?
    4 RP 314 478088 6771177 ?
    5 RP 315 478080 6771176 ?
    6 RP 316 478071 6771175 ?

    Where... M=Type, N=ID, O=X-coordinate, P=Y-coordinate, Q=Nearest Point

    The table shown consists of cells M1:Q7 but the entire table I wish to select from will pontentially be M1:Q1000. Obviously I cannot have 312 as the nearest ID to 311 as it must be of RP type. Please note that the table shown shows rounded coordinates, the spreadsheet I use has the exact coordinate to 6 decimal places. The formula I have used to establish the Nearest ID as used in Q2 is as follows.

    Formula: copy to clipboard
    {=INDEX($N$2:$N$1000,MATCH(MIN(IF(O2&","&P2<>O$2:O$1000&","&P$2:P$1000,ABS(O2-O$2:O$1000)+ABS(P2-P$2:P$1000))),IF(O2&","&P2<>O$2:O$1000&","&P$2:P$1000,ABS(O2-O$2:O$1000)+ABS(P2-P$2:P$1000)),0))}


    Although it may be considered quite a complex formula I am still only learning the ropes of excel. I must acknowledge all sources that have helped me get this far but would just like the finishing touch to have it do what I need. I have considered a macro however the spreadsheet I am producing, for reasons beyond my control is required to be without a macro. Im sure that it is probably just a simple IF statement that needs to be inserted but I am not sure where and how.

    Thanks in advance!

    Kind Regards,
    Ben
    Last edited by Spicey_888; 05-08-2014 at 08:39 AM. Reason: Solved

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,862

    Re: Nearest neighbour limited by point type

    Try:
    {=INDEX($N$2:$N$1000,MATCH(MIN(IF((O2&","&P2<>O$2:O$1000&","&P$2:P$1000)*(Q2<>Q$2:Q$1000),ABS(O2-O$2:O$1000)+ABS(P2-P$2:P$1000))),IF((O2&","&P2<>O$2:O$1000&","&P$2:P$1000)*(Q2<>Q$2:Q$1000),ABS(O2-O$2:O$1000)+ABS(P2-P$2:P$1000)),0))}
    Best Regards,

    Kaper

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,862

    Re: Nearest neighbour limited by point type

    By the way - you check that O and P are different. Does it mean you can have two points with exactly the same pair of coordinates? if not, shorter version will be quicker:
    {=INDEX($N$2:$N$1000,MATCH(MIN(IF(Q2<>Q$2:Q$1000,ABS(O2-O$2:O$1000)+ABS(P2-P$2:P$1000))),IF(Q2<>Q$2:Q$1000,ABS(O2-O$2:O$1000)+ABS(P2-P$2:P$1000)),0))}
    And I am not sure about application, but in most of them, cartesian distance would be more appropriate than using
    ABS(O2-O$2:O$1000)+ABS(P2-P$2:P$1000)
    so:
    (O2-O$2:O$1000)^2+(P2-P$2:P$1000)^2
    (as you do not calculate distance, but only locate smallest one, no need for SQRT here).

  4. #4
    Registered User
    Join Date
    05-26-2013
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    79

    Re: Nearest neighbour limited by point type

    Kaper,

    Thanks for your quick reply. I changed your reference of the Q column in your formula to M and its perfect. Well I think, having read further on in your post I am now not sure what is best for my case. I wish to compare distance. I will explain the use as follows...

    Essentially I have a set of drill holes, these are drilled using two different methods. I have a value for each hole which I establish on another spreadsheet which I am going to then compare between the different drill holes as per method of drilling (RP or RO). For accuracy purposes i wish to compare each drill hole to the closest nearby hole drilled using the alternative method by distance.

    As I am a bit of an amateaur, and by that I mean only two days ago I had no idea how to use VLOOKUP or create a pivot table, I am not 100% certain that the formula represents what I need.

    Also, the reason i check that O and P are different is that in data entry due to Re-drills the same hole can mistakedly be entered twice.

    Your thoughts?

    Kind Regards,
    Ben

  5. #5
    Valued Forum Contributor Hawkeye16's Avatar
    Join Date
    02-27-2013
    Location
    Holland
    MS-Off Ver
    ├•┤ Pew Pew
    Posts
    441

    Re: Nearest neighbour limited by point type

    Got ninja'd. Looks like you may have gotten a better answer already.

  6. #6
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,862

    Re: Nearest neighbour limited by point type

    Sure, not Q but M. Good you spotted this
    So if O and P are some mesurements (this is how I understand coordinates) in 2 perpendicular directions, I'd for sure recommend

    (O2-O$2:O$1000)^2+(P2-P$2:P$1000)^2
    (twice)

    have a look on
    0 0
    and
    0 5
    5 0
    3 3
    The closest one to 0,0 will be 3,3 (some 4.25 units away)

  7. #7
    Registered User
    Join Date
    05-26-2013
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    79

    Re: Nearest neighbour limited by point type

    You are absolutely right, I just worked that out as you replied

    Will definately use cartesian and have ammended this already. And as you previously mentioned SQRT is not required, which makes sense. This formula is working perfectly now and will save me hours.

    Thanks for your help, I will now mark this as solved

  8. #8
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,862

    Re: Nearest neighbour limited by point type

    Glad to hear that. And thanks for reputation point

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Return the difference between a value and it's nearest upper and lower neighbour?
    By Prince Dakkar in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 12-10-2013, 07:21 PM
  2. [SOLVED] Scatter Plot X Axis to the nearest point
    By vcodec in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 08-07-2012, 09:57 AM
  3. Using Large Point Type Over Two Rows
    By scotfitz in forum Excel General
    Replies: 3
    Last Post: 11-06-2010, 02:30 PM
  4. Replies: 4
    Last Post: 10-31-2010, 09:37 PM
  5. [SOLVED] Rounding to the nearest quarter point?
    By George in forum Excel General
    Replies: 3
    Last Post: 06-10-2006, 05:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1