Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation about searches and calculations #4

Open
synw opened this issue Aug 13, 2019 · 4 comments
Open

Documentation about searches and calculations #4

synw opened this issue Aug 13, 2019 · 4 comments

Comments

@synw
Copy link

synw commented Aug 13, 2019

The original library mentions that you can search "within flexible levels of zone size" and that you can do easy distance calculations but I did not find any documentation on how to do it.

Do you have more information about these features?

@NiKoTron
Copy link
Owner

Sorry for the late answer. I've had a very busy week.

Yep.

From the original doc:

Easy Distance Calculation

Each zone is the same distance from any of its neighbors within the same level.

Therefore, it is easy to calculate steps between zones.

So. for example:

take a two 'level 2' zones

PM84 and his neighbor PM85

and accordingly, the distance between their centers will be equal to the size of one of the zone.

Next.

Zones have an [X,Y] coordinates. so using these parameters we can take the distance (in steps) between two zones with the simple equation:

steps=\sqrt{(B{x}^{2}-A{x}^{2})+(B{y}^{2}-A{y}^{2})}

One thing that we will do to calculate the distance it's multiply size of the zone to count of steps.

Programmatically, it will look something like this:

import 'dart:math' as math;

import 'package:geohex/geohex.dart';

void main() {
  final a = GeoHex.decode('XM488507762');
  final b = GeoHex.decode('XM488531402');

  final len = math.sqrt(math.pow(b.x - a.x, 2) + math.pow(b.y - a.y, 2));

  print('${len * a.hexSize} 鯨尺');  
}

So! it's an important thing. first time I've confused by result value, but after little investigating, I've able to this is could be old Japanese unit of measure named 鯨尺 (kujirajaku) And it looks like the right thing.

@synw
Copy link
Author

synw commented Aug 20, 2019

Thanks for this information, very interesting.

It could be useful but distance calculation with just coordinates is fast. I was wondering more about doing some fast geofencing: actually geofencing a point in a polygon is slow and expensive. Do you think that we could build a faster geofencing system out of these geohex objects?

This might be related to the original doc: "You can search easily within flexible levels of zone size". How? I'm also interested by the another mysterious feature: "Single-query Searching": does this apply to more than just searching for one point's code?

Sorry I'm curious: you made me discover that geo hex system with your lib and now I want to use it!

@NiKoTron
Copy link
Owner

actually geofencing a point in a polygon is slow and expensive. Do you think that we could build a faster geofencing system out of these geohex objects?

it depends on how do you solve this.
brute-force solution will be expensive, right. So.. geohex designed to solve this problem. actually geohex on each level it is an "even-r" hexagonal grid layout. Actually X,Y of zones it is row and columns at this grid. Well.. you can easily find a necessary zone just by address row+column.

: "Single-query Searching": does this apply to more than just searching for one point's code?

From the original doc:

Single-query Searching
GeoHex is very compatible with cloud-based key-value stores.

It means that geohex allows you to store some geo-related data as a simple key-value pair where the key is geohex code and value is some data.

and search for some geo-related object data into the some area should be simple query by key.

for example:
someKVDatabase.get('AB123') -> SomeObject(s)

I think just that, not anything else.

Sorry I'm curious: you made me discover that geo hex system with your lib and now I want to use it!

I'm very glad to hear it!

@synw
Copy link
Author

synw commented Aug 25, 2019

Hi. I've made some experiments for geofencing. The test use case is to find in which country is a point. The idea: get level 0 grid of hexes, then prepare a dataset using geopandas in python to list the countries contained in each hex (from a geojson dataset for countries) and store this in a kvstore.

Then when a user taps on the map it gets the hex and check what countries (and the stored polygons numbers as countries are multipolygons) to search for: if only one country is found the answer is instant, if more than one it will check the polygons with brute force to geofence.

The thing is that I can not manage to get correct data. I am not sure of my hexes grid data: I made a script to get a grid but I am not sure of the method. So I would like to ask you how to get a clean grid of hexes for a level?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants