MCPcopy Index your code
hub / github.com/buckhx/gofence

github.com/buckhx/gofence @v0.0.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.0.4 ↗ · + Follow
110 symbols 262 edges 19 files 29 documented · 26%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

gofence

Build Status

Tool for geofencing with different algorithms for profiling.

Installation

// omitting the dot installs to /usr/local/bin
curl -sSL https://raw.githubusercontent.com/buckhx/gofence/master/scripts/install.py | python - .

Usage

Invoking the fence cli will start an HTTP server and read geojson files from a directory into memory for searching. The features in the geojson will be searchable at different endpoints for each file. The endpoints will use a url-safe slug of the file name as their identifiers.

NAME:
   fence - Fence geojson point features

USAGE:
   cli [global options] command [command options] path/to/geojson/dir

VERSION:
   0.0.0

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --fence "rtree"  Type of fence to use rtree|brute|qtree|qrtree|city|city-bbox|bbox
   --zoom, -z "18"  Some fences require a zoom level
   --port, -p "8080"    Port to bind to
   --help, -h       show help
   --version, -v    print the version

The city algorithms are special cases and both require NYC_BOROS_PATH envvar to be set to a geojson file. Don't use either of them for anything besides benchmarking. The boros and tracts data can be found on NYC Open Data Maps

HTTP Methods

GET /fence

A list of the available fence names

POST /fence/:name/add

Adds a geojon feature from the post body to the fence at. This feature will not be saved to the server and will be gone if the server is restarted. Features in a fence have no notion of uniqueness, so if you add the same feature twice, the searchs will return both.

POST /fence/:name/search

Search a fence for the query in the post body. This query must be a geojson feature with a point geometry. The properties of the matched features in the fence will be returned as a list.

GET /fence/:name/search?lat=<LAT>&lon=<LON>

Convenience method for search with GET parameters. Both lat and lon and required and must be numbers. Any other parameters in the query string will be treated as properties of the query in the result.

Micro Benchmarks

Benchmark Operations Time (ns/op) Bytes (b/op) Mallocs (allocs/op)
BenchmarkBrute-4 5000 251641 19 1
BenchmarkCity-4 30000 39913 40 1
BenchmarkBbox-4 50000 37085 11 1
BenchmarkCityBbox-4 200000 9484 13 1
BenchmarkQfence-4 300000 3959 399 18
BenchmarkRfence-4 1000000 2290 174 9

chart link broken

Benchmarking requires NYC_TRACTS_PATH envvar to be set. Benchmarks are ran by checking which census tract a point is in code here

HTTP profiling is done via https://golang.org/pkg/net/http/pprof/

See https://github.com/buckhx/gofence-profiling for more in depth benmarking.

Extension points exported contracts — how you extend this code

GeoFence (Interface)
Interface for algortithms to implement. [10 implementers]
geofence/fence.go
FenceIndex (Interface)
FenceIndex is a dictionary of multiple fences. Useful if you have multiple data sets that need to be searched [2 implementers]
geofence/index.go

Core symbols most depended-on inside this repo

Set
called by 10
geofence/index.go
Get
called by 6
geofence/fence.go
Add
called by 5
geofence/fence.go
die
called by 4
cli.go
Search
called by 4
geofence/index.go
ContainsCell
called by 4
geofence/s2.go
IntersectsCell
called by 4
geofence/s2.go
Add
called by 3
geofence/index.go

Shape

Function 49
Method 41
Struct 17
Interface 2
TypeAlias 1

Languages

Go100%

Modules by API surface

geofence/index.go22 symbols
geofence/s2.go16 symbols
geofence/fence_test.go11 symbols
geofence/msg.go8 symbols
geofence/http.go8 symbols
geofence/qtree.go5 symbols
geofence/fence.go5 symbols
geofence/brute.go5 symbols
geofence/bbox.go5 symbols
geofence/rtree.go4 symbols
geofence/qrtree.go4 symbols
geofence/city_bbox.go4 symbols

For agents

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

⬇ download graph artifact