I want to cover a specific area using olc.

191 views
Skip to first unread message

HANUMAN ACHOLIA

unread,
Jan 26, 2018, 9:35:14 PM1/26/18
to open-location-code
Hi,

Suppose i want to cover 400 meter area using olc. I have lat,log and radius. I know i can get olc for 275 meter using 8 code length. How i can cover remaining area and get olc codes for remaining area.

HANUMAN ACHOLIA

unread,
Jan 26, 2018, 10:28:25 PM1/26/18
to open-location-code
For example : 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)

Andreas B

unread,
Jan 27, 2018, 6:21:39 AM1/27/18
to open-location-code
This depends on how exact you want that cover to be. Generally speaking, you could do the following:

1. Start with a "useful" code length (one where the entire feature is contained within a "few" OLC blocks of that size - in your example, this might be length 6).
2. Find and list all codes of that length that have at least a bit of your feature
3. Then, for each of the codes in that list still bigger than the minimum block size you want to use
  a. for all of the 20x20 sub-blocks, check whether they contain the feature, and store those that do on a separate list
  b. depending on the number of items now on that separate list, decide to
    I. remove the original block, and append the list of sub-blocks to the original list OR
    II. keep the original block, OR
    III. remove the original block without replacement.

Once you've reached the end of that list, it will contain all of the OLC blocks that make up your feature, with varying precision as necessary.

HANUMAN ACHOLIA

unread,
Jan 27, 2018, 7:33:26 AM1/27/18
to open-location-code
Can you please explain this in details. I am new this area.
If i choose 6 code length then i will cover 5500 meter and its give me only one olc string.
1. How i can find and list all olc codes which have at least a bit of your feature.?
2. How to divide them into 20*20 blocks and check that contains the feature or not ?

Any help appreciated :)

Andreas B

unread,
Jan 27, 2018, 8:13:35 AM1/27/18
to open-location-code
Of course! :)

Dividing is the easy part:

- If you have some plus code (for example of length 8, 66FF88XX+), you can replace pairs of characters with '0' to get another plus code for a larger area that contains the original area: 66FF8800+66FF0000+66000000+

- Likewise, if you have a plus code for a larger area (say, 66FF8800+), you can generate the codes for all 20x20 sub-blocks simply by iterating through all possible pairs of code characters ("23456789CFGHJMPQRVWX") and replacing the '0' characters with that:
66FF8822+
66FF8823+
66FF8824+
...
66FF882X+
66FF8832+
...
66FF88XX+

Now, finding out which of these code areas overlap with your feature can be a bit more tricky, depending on how you've defined your feature. For purely geometrical definitions of the feature (like origin/radius of a circle, or polygon), the best approach might be to look at various intersection algorithms. For other, more arbitrary definitions (like "surface area of $city"), other approaches might work better. In any case, the important thing to keep in mind here is the fact that the area of any plus code is simply a box aligned with the latitude/longitude grid, with just four important values (minimum/maximum latitude, minimum/maximum longitude).

HANUMAN ACHOLIA

unread,
Jan 27, 2018, 11:53:39 PM1/27/18
to open-location-code
Thanks for your kind help.

1. I have lat,log and radius so i can easily find out the lat,log of the corners which covered the given radius. Its a full
2. I already have all 8 digit olc code list.One by one i will pick the olc code from list and find out its lat,log of all four corners using openLocationcode decode function.
3. After this i will check all four corners that they are lies in our original area or not. I will use point in polygon method.

Andreas B

unread,
Jan 28, 2018, 6:51:08 AM1/28/18
to open-location-code
Sounds good! In your step #3, if at least one of the corners of a code area is inside your original area, then there's an overlap - but the opposite can be a bit tricky:

Even if all four corners of the code area are outside, there could still be some overlap along one of the sides. You will have to decide whether it is safe to ignore these cases in your use-case, or if you want to deal with them separately.

Nikhil VJ

unread,
Sep 9, 2018, 7:00:39 AM9/9/18
to Plus Codes Community Forum
Hi, this would make an interesting plugin in QGIS: Take a polygon shapefile and produce a "mosaic" of pluscodes.

There is a QGIS plugin that works with plus codes: https://github.com/NationalSecurityAgency/qgis-latlontools-plugin 

It seems to only do points for now.

-Nikhil VJ
Pune, India
Reply all
Reply to author
Forward
0 new messages