+ Reply to Thread
Results 1 to 16 of 16

Determine in which geo area a geo point exists

  1. #1
    Registered User
    Join Date
    04-27-2020
    Location
    USA
    MS-Off Ver
    2003 Professional/Excel 2016
    Posts
    10

    Determine in which geo area a geo point exists

    This is a bit of a repost, but I'm hoping someone can help.

    Using Excel 2016.

    We have about 3500 geo points, each defined by its latitude/longitude. Each geo point resides in one and only one of about 60 geo areas. Each geo area is defined by the latitude/longitude of its "corners." A geo area may have up to 10 "corners." Corners are typically shared by adjacent geo areas. So, how to determine in which geo area each geo point resides?

    I appreciate your help.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,938

    Re: Determine in which geo area a geo point exists

    Without sample bit hard to give you help.

    But algorithm would be something like... if you draw polygon outline of geo area (i.e. straight line from one corner to next).
    Then if you draw straight line to the boundary from point.
    If it crosses odd times, it must be inside boundary. If it crosses even times then it must be out side boundary.
    This is likely one of faster calculation model.

    Alternately you can use angle summation technique, but this is one of the slowest method.

    Have a read of article in link.
    https://erich.realtimerendering.com/ptinpoly/
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,938

    Re: Determine in which geo area a geo point exists

    When I've encountered this problem on this forum in the past, it seems to have reduced down to solving a "point in polygon" problem for each point in each polygon. See this thread, for example: https://www.excelforum.com/excel-for...phic-area.html

    I note that the QGIS program that I mention in the other thread is still an active project. If you are not required to program your own solution in Excel, it might be easiest (even if you have to buy a software license) to use a GIS type of program that already knows how to solve this type of problem out of the box.

    If you must use Excel, I will suggest that you look over the information we gathered on the point-in-polygon problem and see how it will adapt to your spreadsheet.

    How would you like to proceed?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,938

    Re: Determine in which geo area a geo point exists

    I just looked close enough to realize you are the same user who posted this same question 4 years ago in the thread I linked to. Not sure if anything has changed in 4 years, but it looks like the same problem. Any changes we should know about from 4 years ago?

  5. #5
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,425

    Re: Determine in which geo area a geo point exists

    Here is a "point in polygon" function I posted quite a while ago. Since you have 60 geoareas, you will need to create 60 sets of coordinates for them and then run your test point against each geoarea in my function until you get a hit. The comment in message #9 might help you as well (it was for triangular areas, but can be adapted to generalized areas)...
    https://www.excelfox.com/forum/showt...Polygon-Or-Not

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2407 (Windows 11 23H2 64-bit)
    Posts
    83,106

    Re: Determine in which geo area a geo point exists

    Using Excel 2016.
    Please update your forum profile.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2407 (Windows 11 23H2 64-bit)
    Posts
    83,106

    Re: Determine in which geo area a geo point exists

    Administrative Note:

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not told us about this. You are required to do so. Cross-posts are allowed but you must provide a link to your posts on other sites.

    Please see Forum Rule #7 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important: https://excelguru.ca/a-message-to-forum-cross-posters/

    (Note: this requirement is not optional. As you are relatively inexperienced here, I shall do it for you this time: https://www.excelfox.com/forum/showt...o-area?p=24149)

  8. #8
    Registered User
    Join Date
    04-27-2020
    Location
    USA
    MS-Off Ver
    2003 Professional/Excel 2016
    Posts
    10

    Re: Determine in which geo area a geo point exists

    Yes, I'm the say user. I posed the problem on numerous website and haven't received any workable solutions. As I noted in my first post, this is a repost.

  9. #9
    Registered User
    Join Date
    04-27-2020
    Location
    USA
    MS-Off Ver
    2003 Professional/Excel 2016
    Posts
    10

    Re: Determine in which geo area a geo point exists

    Ali, as I noted in the initial "new" post, this a type of a repost.

  10. #10
    Registered User
    Join Date
    04-27-2020
    Location
    USA
    MS-Off Ver
    2003 Professional/Excel 2016
    Posts
    10

    Re: Determine in which geo area a geo point exists

    I have updated it.

  11. #11
    Registered User
    Join Date
    04-27-2020
    Location
    USA
    MS-Off Ver
    2003 Professional/Excel 2016
    Posts
    10

    Re: Determine in which geo area a geo point exists

    Please let me supply some addition info.

    I live in a densely populated county near Washington, DC. There are more than 3500 multi-unit buildings (aka "MUBs"; apartments and condominiums) in the county. The data we are using are from the county's tax database. It contains a plethora of data that are of no use my team. But the data do contain the latitude and longitude of each of the MUBs. Now, the county is divided up into 56 voter precincts. The object of the project is to determine in which precinct a MUB is located.

    Thanks!

  12. #12
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,938

    Re: Determine in which geo area a geo point exists

    After 4 years, you have made no progress on the problem, am I understanding correctly?

    When I look at the QGIS tutorial I linked to years ago, it seems to me like it should be easy enough to replicate those steps with your own set of polygon points and data points. I'm still inclined to think that gis programs already know how to solve this problem, so it will be easiest to turn to a gis app rather than programming your own solution from scratch in Excel. Have you decided you are not allowed to use a gis program for this analysis?

    Every Excel based solution I see being proposed in rooted in solving the point in polygon problem, and a few solutions for that problem have been proposed. Have you been able to solve the point in polygon problem for one point in one polygon? Rick's code seems to show up a few times in these conversations, have you had any luck getting his code to work for one point in one polygon?

  13. #13
    Registered User
    Join Date
    04-27-2020
    Location
    USA
    MS-Off Ver
    2003 Professional/Excel 2016
    Posts
    10

    Re: Determine in which geo area a geo point exists

    MrS, I will give Rick's solution a shot and get back to you.

    Thanks for your help!

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2407 (Windows 11 23H2 64-bit)
    Posts
    83,106

    Re: Determine in which geo area a geo point exists

    Ali, as I noted in the initial "new" post, this a type of a repost.
    But you did NOT provide links to the other forums where you have asked the question - you are required to do this as per our cross-posting rules.

    I have asked you to update your forum profile - you have now got two versions of Excel there. Please amend this to just Excel 2016. Thanks.

  15. #15
    Registered User
    Join Date
    04-27-2020
    Location
    USA
    MS-Off Ver
    2003 Professional/Excel 2016
    Posts
    10

    SOLVED!! Determine in which geo area a geo point exists

    SOLVED!!
    I first delineated each Geo area by the latitude and longitude of its "corners." Most areas ended up with ~15 corners. For each area I created a spreadsheet. The top row in each spreadsheet lists the latitudes and longitudes of the respective area. Note that I grouped each area's latitude and then the area's longitudes. See the attached .jpg. The rows below the aforementioned latitudes and longitudes of the area contain the formulae that subtract the the geo point's latitude from the ~15 corners' latitudes. This is repeated to subtract the geo point's longitude from the ~15 corners' longitudes.

    Next for each geo point's latitude I enter two "countif" formulae. The first is "countif(B$4:"$O$4:">0")". The second is "countif(B$4:"$O$4:"<0")". These two formulae are repeated for the geo point's longitude. The rationale is if a geo point is within a geo area, the four "countif" formulae will result in a value greater then "0." Finally, the results of the four "countif" formulae are multiplied. Any cell that contains the product and is greater then "0" is filled with green.
    Attached Images Attached Images

  16. #16
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,938

    Re: Determine in which geo area a geo point exists

    Glad you have something.

    How robust does this need to be? Since I didn't recognize your algorithm as any of the usual "point in polygon" algorithms, I tested it against some random polygons, and got several false positives. I suspect that your algorithm works just fine for a subset of polygons, but is not applicable to all polygons. As long as you know that your polygons will always be like your test polygon here, then it's probably okay. If you can't be certain that all of the polygons you need to test will have the same features as your test polygons, you might want to consider a more robust "point in polygon" algorithm.

    Again, if you are satisfied, I'm satisfied. To avoid coming back to this again in a few months or years, I recommend testing your point in polygon algorithm sufficiently to make sure it will work for all of the polygons you will need to test.

+ 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. determine if data exists on 2 sheets
    By tpaquette in forum Excel General
    Replies: 3
    Last Post: 06-22-2015, 09:00 AM
  2. [SOLVED] How to determine if a range exists
    By plans in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-16-2014, 07:56 PM
  3. [SOLVED] determine if a formula exists within a cell
    By crowegreg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-11-2013, 02:37 AM
  4. Determine if UDF Exists
    By stonesfan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-09-2011, 03:42 PM
  5. Formula to determine if an entry exists
    By GuruWannaB in forum Excel General
    Replies: 2
    Last Post: 07-21-2009, 11:55 AM
  6. Determine if folder exists
    By Terry K in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-09-2006, 01:30 PM
  7. Replies: 1
    Last Post: 10-06-2005, 08:05 AM

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