ilyabo / geohex.js

Hexagonal geo-coding system
7 stars 2 forks source link

Redundant values in getPolygon() #1

Open EMRJ opened 8 years ago

EMRJ commented 8 years ago

When I call getPolygon() method, it returns latitude and longitude when I convert back them into encoded value I get 4 values remaining 3 values are redundant

How to find all the polygons associated with the geohex?

e.g Geohex = "PX0072320" getpolygon

Encoded values = ["PX0072320", "PX0072324", "PX0072323", "PX0072323", "PX0072312", "PX0072320", "PX0072320"]

ilyabo commented 8 years ago

not sure I understand what you are trying to do

getPolygon() returns the geometry of one hexagon on a particular zoom level

if you want to get all hexagons contained in a specific hexagon on the next zoom level, take its code and append 0,1,2,3,4,5,6 to it

PX0072320 should contain these: PX00723200 PX00723201 PX00723202 PX00723203 ...

EMRJ commented 8 years ago

I want to find adjacent hexagons (7 hexagon),There are only 4 geohex were present (refer incomplete_hex)

Output: incomplete_hex

Expected Output: expected_output

I want to fill the remaining hexagon (refer expected_output) Is there any way to achieve using x, y coordinates?

Ref: http://geohex.net/v3.html?code=PX0072320

ilyabo commented 8 years ago

Ah, ok, this is less obvious, no API function for that.

I would try to calculate the coords of their center points based on the center of the starting hexagon and its radius. Then, call getZoneByLocation for each of them.

something like this:

 for i in 0 to 5 
    getZoneByLocation(x0 + r*cos(i * PI/3), y0 + r*sin(i * PI/3))
EMRJ commented 8 years ago

@ilyabo Can you elaborate the above sample, what are all the values needs to replaced for x0, y0 and r

ilyabo commented 8 years ago

x0 and y0 are the lon and lat of the starting hexagon, respectively R is two times its inner radius (=the diameter) which can be calculated from the coords of the hexagon vertices:

     R = 2 * midpoint(coords[0], coords[1]), midpoint(coords[3], coords[4])

where midpoint is:

     function midpoint(p1, p2) {
        return [ (p1[0] + p2[0])/2, (p1[1] + p2[1])/2 ];
     }
EMRJ commented 8 years ago

@ilyabo From the above midpoint(coords[0], coords[1]), midpoint(coords[3], coords[4]) returns [80.2697759487883, 13.086934044236282] [80.27892089620485, 13.081791282653175]

It returns array, Is that the radius? Is the above is correct?

ilyabo commented 8 years ago

sorry it should be the distance between these two points of course