Coder Social home page Coder Social logo

Comments (5)

dfellis avatar dfellis commented on May 22, 2024 1

So the following snippet ought to work:

function isChildOf(possibleParent, possibleChild) {
  return possibleParent === h3.h3ToParent(possibleChild, h3.h3GetResolution(possibleParent));
}

Since the parent-child relationship is a simple tree structure in H3, there can be only one parent for any H3 index at any given resolution coarser (smaller) than its own resolution.

from h3-js.

dfellis avatar dfellis commented on May 22, 2024 1

Oh, and the second piece "find a range of indexes that are all children of a specified id" is just h3.h3ToChildren(index, childResolution)

from h3-js.

dfellis avatar dfellis commented on May 22, 2024 1

So, yes, the underlying C implementation of h3ToParent and h3ToChildren is relatively straitghtforward (parent is much easier than children, though).

h3ToParent is some sanity checking up front, and then some bit masking to replace the resolution with the new parent resolution and write 1s to all of the bits for the resolutions that are larger than that.

h3ToChildren has to allocate memory for the maximum number of children possible at that child level, then it loops through the possible children with special logic to detect and handle "missing children" if one of the indexes is actually a pentagon, and writes them into the allocated memory. This one would be hard to replicate in a database, but not impossible.

from h3-js.

am2222 avatar am2222 commented on May 22, 2024

@dfellis thanks for the reply. But since we don't have access to the h3 library in the database is there any equations or logic to calculate the output of h3.h3ToChildren(index, childResolution) in database?

from h3-js.

am2222 avatar am2222 commented on May 22, 2024

@dfellis Thanks, I am looking into the functions. it seems they are the exact functions I am looking for

from h3-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.