MCPcopy Index your code
hub / github.com/Willyham/hashfill

github.com/Willyham/hashfill @v1.0.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.1 ↗ · + Follow
37 symbols 114 edges 4 files 14 documented · 38%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

GoDoc Go Report Card

Usage

Hashfill is a library for computing the set of geohashes which are contained by a geofence. It can either produce a set of hashes which are completely contained or one which also includes where the boundaries intersect. It currently operates on geom.Polygon objects from the https://github.com/twpayne/go-geom pacakge. Converting from geojson is simple and this package may offer a utility in the future.

func readFileAsGeometry(t *testing.T, file string) (*geom.Polygon, error) {
    data, err := ioutil.ReadFile(file)
    if err != nil {
        return nil, err
    }

    poly := new(geom.T)
    err = geojson.Unmarshal(data, poly)
    if err != nil {
        return nil, err
    }

    return nil, (*poly).(*geom.Polygon)
}

geofence := readFileAsGeometry("testdata/regents.geojson")
filler := hashfill.NewRecursiveFiller(
  hashfill.WithMaxPrecision(8),
)

hashes, err := filler.Fill(geofence, hashfill.FillIntersects)

Would result in something that could be visualized as:

Installation

This library depends on headers from the geos library. You can install with brew install geos or dnf install geos-devel on RPM based linux distros.

Options

  • WithMaxPrecision - Sets the max hash precision the algorithm will generate hashes for.
  • WithFixedPrecision - Causes the fully contained geohashes to still be divided into the hashes of the max precision.
  • WithPredicates - Can be used to supply your own functions for Intersect and Contains rather than the built in ones.

Improvements

TODO:

  • [] Fix bug in geofences with holes.
  • [] Corner based check optimisations (+ hybrid)
  • [] Cache poly to geom operation in predicates.
  • [] Add benchmarks

Extension points exported contracts — how you extend this code

Container (Interface)
Container tests if a hash is contained. [1 implementers]
predicates.go
Filler (Interface)
Filler is anything which can fill a polygon with geohashes. [1 implementers]
hashfill.go
Intersector (Interface)
Intersector tests if a hash intersects. [1 implementers]
predicates.go
Option (FuncType)
Option allows options to be passed to RecursiveFiller
hashfill.go

Core symbols most depended-on inside this repo

WithMaxPrecision
called by 6
hashfill.go
NewRecursiveFiller
called by 6
hashfill.go
Fill
called by 6
hashfill.go
Contains
called by 2
predicates.go
Intersects
called by 2
predicates.go
geomToGeosCoords
called by 2
predicates.go
hashToGeometry
called by 2
predicates.go
polygonToGeometry
called by 2
predicates.go

Shape

Function 17
Method 10
Interface 3
TypeAlias 3
FuncType 2
Struct 2

Languages

Go100%

Modules by API surface

predicates.go13 symbols
hashfill.go12 symbols
hashfill_test.go10 symbols
predicates_test.go2 symbols

For agents

$ claude mcp add hashfill \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact