+ Reply to Thread
Results 1 to 6 of 6

Locations finding

  1. #1
    Registered User
    Join Date
    02-14-2006
    Posts
    24

    Unhappy Locations finding

    I have 198 locations that given in a form or coordinates (Latitude and longitude). If I pick location 182 (Loc182) and I want to find out all other locations that are 10 miles or more from from Loc182 and each ohters (for example Loc182, Loc175, Loc153, Loc154, Loc149, Loc94,.....are 10 miles or more from Loc182 and each other). Can some someone help me with a script please?

    The distance between 2 coordinates can be calculated using "disthigh" built in formula or you can use the below formula:

    Latitude1
    Longitude1

    Latitude2
    Longitude2

    distance =3444*ACOS(COS(RADIANS(90-(Latitude1)))*COS(RADIANS(90-(Latitude2)))+SIN(RADIANS(90-(Latitude1)))*SIN(RADIANS(90-(Latitude2)))*COS(RADIANS((Longitude1-Longitude2))))

    Data file:

    Location Lat1 Lon1
    Loc1 39.6064 -75.6906
    Loc2 39.7814 -75.5053
    Loc3 39.5708 -75.7434
    Loc4 39.756 -75.7072
    Loc5 39.7037 -75.5722
    Loc6 39.675 -75.6994
    Loc7 39.7207 -76.0345
    Loc8 39.6469 -75.8464
    Loc9 39.6639 -75.8147
    Loc10 39.6117 -75.9
    Loc27 40.0101 -74.9313
    Loc28 40.0775 -74.7554
    Loc29 40.0197 -74.8289
    Loc30 39.9811 -74.8172
    Loc31 39.7097 -74.5317
    Loc32 39.9343 -74.8938
    Loc33 40.0172 -74.9506
    Loc34 40.0039 -74.8506
    Loc35 39.8068 -74.9386
    Loc36 39.7378 -74.8694
    Loc37 39.7804 -74.9585
    Loc38 39.7073 -74.8951
    Loc39 39.9297 -75.1171
    Loc40 39.8428 -74.9669
    Loc41 39.7945 -74.9195
    Loc42 39.9686 -75.0528
    Loc43 39.8247 -74.9989
    Loc44 39.8053 -75.0206
    Loc45 39.7621 -74.9401
    Loc46 39.6515 -75.0332
    Loc47 39.6428 -75.0994
    Loc48 39.7653 -75.3192
    Loc49 39.8278 -75.1636
    Loc50 39.6943 -75.0428
    Loc51 39.7639 -75.39
    Loc52 39.7994 -75.1992
    Loc53 39.7178 -75.1411
    Loc54 39.6948 -75.2983
    Loc55 39.7257 -75.3446
    Loc56 39.7336 -75.0253
    Loc57 40.414 -74.8101
    Loc58 40.5983 -74.8756
    Loc59 40.3731 -74.9121
    Loc60 40.4436 -75.0407
    Loc61 40.3851 -74.8824
    Loc62 40.2954 -74.7236
    Loc63 40.2901 -74.7936
    Loc64 40.5293 -74.3923
    Loc65 40.5712 -74.3465
    Loc66 40.3587 -74.4054
    Loc67 40.3933 -74.585
    Loc68 40.4551 -74.2957
    Loc69 40.2494 -74.3414
    Loc70 40.1872 -74.4756
    Loc71 40.1883 -74.4756
    Loc72 40.3122 -74.3622
    Loc73 40.2042 -74.2703
    Loc74 40.1397 -74.2225
    Loc75 39.7517 -74.2608
    Loc76 40.1065 -74.4804
    Loc77 39.6358 -75.1925
    Loc78 39.6358 -75.1925
    Loc79 39.5304 -75.381
    Loc80 39.6589 -75.3617
    Loc81 39.5962 -75.4943
    Loc82 39.7388 -75.4541
    Loc83 40.4864 -74.5058
    Loc84 40.4878 -74.6413
    Loc85 40.6048 -74.5593
    Loc86 40.4708 -74.7278
    Loc87 40.2441 -75.7983
    Loc88 40.4126 -75.8446
    Loc89 40.4653 -76.0086
    Loc90 40.4777 -75.8491
    Loc91 40.2293 -75.806
    Loc92 40.2707 -76.0313
    Loc93 40.5691 -75.9757
    Loc94 40.4447 -75.5811
    Loc95 40.3091 -75.7522
    Loc96 40.5801 -75.7932
    Loc97 40.5723 -75.8944
    Loc98 40.3747 -75.8844
    Loc99 40.3513 -75.6848
    Loc100 40.4229 -75.8786
    Loc161 39.9744 -75.4472
    Loc162 39.9179 -75.3561
    Loc163 39.8896 -75.4333
    Loc164 39.9614 -75.2863
    Loc165 40.1858 -75.9538
    Loc181 40.1225 -75.3656
    Loc182 40.2111 -75.289 <<<<<<Location 182>>>>>>>>>>
    Loc183 40.2789 -75.6464
    Loc184 40.1212 -75.1924
    Loc198 39.915 -75.2202

    Thank you guru!
    Last edited by VBA Noob; 04-02-2008 at 07:18 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388
    Quote Originally Posted by tbobo
    I have 198 locations that given in a form or coordinates (Latitude and longitude). If I pick location 182 (Loc182) and I want to find out all other locations that are 10 miles or more from from Loc182 and each ohters (for example Loc182, Loc175, Loc153, Loc154, Loc149, Loc94,.....are 10 miles or more from Loc182 and each other). Can some someone help me with a script please?
    To start, what you could do is have a lookup table that stores the distances between each location,
    like the distance charts in road atlases.

    This can be implemented in a 2D array (198 * 198).

    There will be a lot of wasted space in this data structure,
    (e.g. it stores the distance from Loc1 to Loc2, but doesn't need to store the distance from Loc2 to Loc1 or from Loc1 to Loc1 etc.).

    The advantage is that it will be easy to visualise and simple to work with.

    The lookup table is initialised by taking the latitude and longitude co-ordinates of two locations and calculating the distance between them.

    This is repeated for each permutation, with the exceptions mentioned above.

    Below is some code to initialise a lookup table for 8 locations (kept small for testing).

    Please Login or Register  to view this content.
    Here is some code to display the lookup table.

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    The attached file is a bit contrived in terms of fixing the output / input areas, but see if it is going in the right direction. I've had to get rid of the distances in the matrix to save space, so copy the formula from D2 down to D199, then across to GS199 to complete the matrix.

    Then run the macro. It will build a matrix starting at row 204 that gives the locations, and the matrix output is merely to show that the distances are really more than 10 apart from all the others.

    HTH

    rylo
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    02-14-2006
    Posts
    24
    Thank you very much for helping T-J and Rylo. Sorry for the delay!

    T-J ==> I tried your programs. They yield no results...What am I missing?

    Rylo ==> I tried your program it works.

    I have additional questions:

    A. Let's say that I have a list of data up to 1000 locations. How can we get around the matrix solution?? Knowing that there only 255 colums in excel.

    B. Rylo, your program provide the list of locations with in 10 miles of location 182. Can we remove these locations from the master list? because we choose another location, the master list will get smaller til no locations left to be chosen.

    Again thank you much!!!

  5. #5
    Valued Forum Contributor
    Join Date
    08-26-2006
    Location
    -
    MS-Off Ver
    2010
    Posts
    388
    Quote Originally Posted by tbobo
    T-J ==> I tried your programs. They yield no results...What am I missing?
    If you read what I wrote again you'll see that my code creates a lookup table of distances between each location and displays it on a sheet.
    That's all it does. More code is needed to do what you want.

    It was only meant to give you a start on tackling the problem.
    Using the lookup table it should be fairly easy to write code to find locations within a given distance.

    Quote Originally Posted by tbobo
    I have additional questions:

    A. Let's say that I have a list of data up to 1000 locations. How can we get around the matrix solution?? Knowing that there only 255 colums in excel.
    You could have a third dimension in the array.

    1st dimension = sheet
    2nd dimension = row
    3rd dimension = column

  6. #6
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    1) Try this. It works on the source data only, and doesn't need the matrix. Again, I've used the fixed sources while testing, and the output will be put into row 206.

    I've used T-J's function to calculate the distance, but converted the output from integer to single (cudos T-J).

    This should be easily expanded to cover the 10k rows, but you would have to change the output to be column based, rather than row based.

    2) You should be able to use the final array as the basis for deleting the entries, before moving onto the next query.

    Please Login or Register  to view this content.

    rylo

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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