Best way to determine adjacency and overlap?

245 views
Skip to first unread message

seklncknsekjn

unread,
Nov 8, 2017, 4:29:53 PM11/8/17
to open-location-code
Is there a built-in way to determine if two codes are exactly adjacent?

Similarly, is there an easy way to determine if two codes overlap?

Hopefully any solutions exist for dissimilar length codes... that'd be super cool!

Doug Rinckes

unread,
Nov 9, 2017, 2:29:29 AM11/9/17
to seklncknsekjn, open-location-code
Adjacency is a good question - I don't have an answer for you.

Codes don't overlap - but one code may be contained within another. The way to check is that the containing code will be a prefix of the contained code, because (for example) the area of 8FVC contains all codes that start with 8FVC.

For a long time I've been thinking about a geometry library that does:
  • For a polygon of lat/lngs, compute the codes that fill that polygon. The codes should be normalised (i.e. it might return some 6 digit codes with some 8 and 10 digit codes to fill the corners)
    • This will make "is this code inside the polygon" easy
  • For one code, return the 8 adjacent codes
    • This will make "are these two codes adjacent"
Are there any other functions that would be useful?



Doug Rinckes, Technical Program Manager, Google Switzerland GmbH; 9GHJ+P88 Zürich

--
Public site: http://www.openlocationcode.com/
Github project: https://github.com/google/open-location-code
Demo site: http://plus.codes/
---
You received this message because you are subscribed to the Google Groups "open-location-code" group.
To unsubscribe from this group and stop receiving emails from it, send an email to open-location-code+unsub...@googlegroups.com.
To post to this group, send email to open-location-code@googlegroups.com.
Visit this group at https://groups.google.com/group/open-location-code.
To view this discussion on the web, visit https://groups.google.com/d/msgid/open-location-code/8fc6cc55-fcb6-475c-b242-5ee241a7808b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dustin Suchter

unread,
Nov 10, 2017, 4:13:37 PM11/10/17
to Doug Rinckes, open-location-code
"contained" is a much more precise word, yeah, sorry about that. Of course individual *codes* don't "intersect" in the "partly overlapped, partly not" sense, so just for clarity I want to explain that I was envisioning rooftop traces, which in my case often a cluster of OLCs. This is meaningful to mention because it would be neat for a function to also take an array of OLCs and determine overlap (<- using my original sense of the word that translates to "at least one OLC is the same or fully contained within another").

Yes, what you propose is also quite useful! Even doing functions that simply check for one code contained within another, which is trivial once you understand OLC, is still useful in perpetuity because it makes code more readable (in my opinion).

On Wed, Nov 8, 2017 at 11:28 PM, Doug Rinckes <drin...@google.com> wrote:
Adjacency is a good question - I don't have an answer for you.

Codes don't overlap - but one code may be contained within another. The way to check is that the containing code will be a prefix of the contained code, because (for example) the area of 8FVC contains all codes that start with 8FVC.

For a long time I've been thinking about a geometry library that does:
  • For a polygon of lat/lngs, compute the codes that fill that polygon. The codes should be normalised (i.e. it might return some 6 digit codes with some 8 and 10 digit codes to fill the corners)
    • This will make "is this code inside the polygon" easy
  • For one code, return the 8 adjacent codes
    • This will make "are these two codes adjacent"
Are there any other functions that would be useful?



Doug Rinckes, Technical Program Manager, Google Switzerland GmbH; 9GHJ+P88 Zürich

On Wed, Nov 8, 2017 at 10:29 PM, seklncknsekjn <dus...@srax.com> wrote:
Is there a built-in way to determine if two codes are exactly adjacent?

Similarly, is there an easy way to determine if two codes overlap?

Hopefully any solutions exist for dissimilar length codes... that'd be super cool!

--
Public site: http://www.openlocationcode.com/
Github project: https://github.com/google/open-location-code
Demo site: http://plus.codes/
---
You received this message because you are subscribed to the Google Groups "open-location-code" group.
To unsubscribe from this group and stop receiving emails from it, send an email to open-location-code+unsubscribe@googlegroups.com.




--
srax_105x50px_nb.png
(Nasdaq: SRAX)
 
Dustin Suchter  CTO, SRAX 
srax.com  
+1 (415) 504-3556   
 


Andreas B

unread,
Nov 15, 2017, 7:53:03 AM11/15/17
to open-location-code
Doug,

those are exactly the functions I'm already using:

getNeighbors(olc) - returns 8 codes of the same length as the input for "tiles" that are adjacent to it
isNeighbor(olcA, olcB) - returns true iff the "tiles" of olcA and olcB share a "side", independent of their code length
contains(olcA, olcB) - returns true iff the "tile" of olcA is contained in olcB (= if olcB is a prefix of olcA)

I also played around with distance functions, like

getDistance(olcA, olcB) - which, for codes of the same length returns the number of same-sized "tiles" inbetween, either as Chebyshev or Manhatten distance. This can be useful as an approximation of travel distance from one location to another
getDirection(olcA, olcB) - which returns an approximate direction, for example in degrees, to get from olcA to olcB

and something like "areas", a structure to hold an arbitrary number of "tiles" identified by their OLC, with functionality like

Area.contains(olc)
Area.contains(otherArea)
Area.getSize()
Area.closestTileTo(olcNotInArea)

In the context of making locations without street addresses addressable, the latter could be useful to answer questions like "Which of the (potentially many) subsidiary/branches of a store is closest to my current location, how far away is it, and how do I get there?" Obviously, distance and direction can also be calculated by using the center lat/lng of a tile, so might not be that useful an addition.

Doug Rinckes

unread,
Nov 15, 2017, 12:02:34 PM11/15/17
to Andreas B, open-location-code
Wow - that's really cool Andreas, I can imagine those functions would be useful to other people too.

Can you / have you open sourced them? I'm happy to provide a link from the OLC github project.


Doug Rinckes, Technical Program Manager, Google Switzerland GmbH; 9GHJ+P88 Zürich

--
Public site: http://www.openlocationcode.com/
Github project: https://github.com/google/open-location-code
Demo site: http://plus.codes/
---
You received this message because you are subscribed to the Google Groups "open-location-code" group.
To unsubscribe from this group and stop receiving emails from it, send an email to open-location-code+unsub...@googlegroups.com.
To post to this group, send email to open-location-code@googlegroups.com.
Visit this group at https://groups.google.com/group/open-location-code.

Andreas B

unread,
Nov 15, 2017, 4:35:46 PM11/15/17
to open-location-code
Hi Doug,

I just did - although currently just for the mentioned functions, not yet the "Area" implementation (which is still somewhat messy and all over the place). I would add that to the same repository when done. I wasn't completely sure how to best integrate this additional functionality with OLC, so my current approach is to have a separate class wrapping an OpenLocationCode object.

Doug Rinckes

unread,
Nov 17, 2017, 3:59:45 AM11/17/17
to Andreas B, open-location-code
That's fine - I think a separate library makes sense, and I really like the functions you've implemented.

I'll add a wiki page and add a pointer to your project if that's ok?


Doug Rinckes, Technical Program Manager, Google Switzerland GmbH; 9GHJ+P88 Zürich

--
Public site: http://www.openlocationcode.com/
Github project: https://github.com/google/open-location-code
Demo site: http://plus.codes/
---
You received this message because you are subscribed to the Google Groups "open-location-code" group.
To unsubscribe from this group and stop receiving emails from it, send an email to open-location-code+unsub...@googlegroups.com.
To post to this group, send email to open-location-code@googlegroups.com.
Visit this group at https://groups.google.com/group/open-location-code.

Andreas B

unread,
Nov 17, 2017, 5:41:13 AM11/17/17
to open-location-code
A link from the wiki would be great, thanks for that!

Наташа Савенкова

unread,
Jan 9, 2018, 7:05:56 PM1/9/18
to open-location-code
среда, 15 ноября 2017 г., 15:53:03 UTC+3 пользователь Andreas B написал:
среда, 15 ноября 2017 г., 15:53:03 UTC+3 пользователь Andreas B написал:

Tony B

unread,
Jan 23, 2018, 6:30:56 AM1/23/18
to open-location-code
Hi all

Additional functionality that would be very useful in my view is the creation of a buffer zone around a code or a collection of codes, according to an inputted distance. This could be used for geofencing, for example.

Tony

Andreas B

unread,
Jan 23, 2018, 7:32:19 AM1/23/18
to open-location-code
Hi Tony,

a simple way to achieve something like this would be to use prefixes and neighbors. For example, if the "exact" plus code of a location is 8FW4V75V+8Q, then
8FW4V75V+
8FW4V700+
8FW40000+
8F000000+
are near-rectangular surface area "tiles" that contain this location.

This simple approach comes with a number of problems, for example the fixed size and shape, and also the fact that a location almost never is centered within its "tile". Adding neighbors at one tile size instead of changing to a bigger tile size can solve some of these problems, at the expense of some simplicity of the data structure. 

Doug Rinckes

unread,
Jan 24, 2018, 5:58:56 AM1/24/18
to Andreas B, open-location-code
The height and width in degrees of a code depends only on the number of digits, and it's constant.

A 10 digit code (like 8FW4V75V+8Q) is exactly 1/8000th of a degree high and 1/8000th of a degree wide. If you want to get say the neighbour to the east, then you get the center latitude and longitude, add 1/8000 to the longitude, and then encode that.

You could use this to get all 9 codes around the starting one. I put together an example on jsfiddle that you can play with.

It shouldn't be that hard ("an exercise for the reader") to change the getNeighbours() function to also take the number of steps to the side that you want to expand by.






Doug Rinckes, Technical Program Manager, Google Switzerland GmbH; 9GHJ+P88 Zürich

--
Public site: http://www.openlocationcode.com/
Github project: https://github.com/google/open-location-code
Demo site: http://plus.codes/
---
You received this message because you are subscribed to the Google Groups "open-location-code" group.
To unsubscribe from this group and stop receiving emails from it, send an email to open-location-code+unsub...@googlegroups.com.
To post to this group, send email to open-location-code@googlegroups.com.
Visit this group at https://groups.google.com/group/open-location-code.

Rich Murnane

unread,
May 1, 2018, 4:53:28 PM5/1/18
to open-location-code
Anyone out there feel ambitious enough to write getNeighbors() in python? I'm a java dummy, and having this in python would be really useful for me.  

Thanks...Rich Murnane
Reply all
Reply to author
Forward
0 new messages