惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
B
Blog
P
Proofpoint News Feed
美团技术团队
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
A
About on SuperTechFans
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Vercel News
Vercel News
有赞技术团队
有赞技术团队
小众软件
小众软件
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
aimingoo的专栏
aimingoo的专栏
H
Help Net Security
罗磊的独立博客
L
LangChain Blog
GbyAI
GbyAI
腾讯CDC
T
The Blog of Author Tim Ferriss
Microsoft Security Blog
Microsoft Security Blog

Hacker News: Show HN

PurrrrrFocus: Pomodoro Timer App - App Store Workflow Engine — Multi-Step Orchestration for Bun RapidPhoto: Pro Photo Editor App - App Store GitHub - DheerG/swarms: Achieve extraordinary results with claude code across a variety of tasks SPICE simulation → oscilloscope → verification with Claude Code — Lucas Gerads Show HN: VCoding – A 5 MB native Windows IDE with no dynamic dependencies Show HN: LLMs don't hallucinate because they're bad at math, it's the format GitHub - Agent-FM/agentfm-core: AgentFM is a peer-to-peer network that turns everyday computers into a decentralized AI supercomputer. AgentFM lets you run massive AI workloads directly across a global mesh of idle CPUs and GPUs. Show HN: Tracking Top US Science Olympiad Alumni over Last 25 Years GitHub - Potarix/agent-hub: One place to talk to all your agents Show HN: Runtime security for AI agents(injection,tool abuse, data exfiltration) GitHub - dubeyKartikay/lazyspotify: Terminal Spotify client for macOS and Linux GitHub - the-banana-tool/king-louie: Easy to use GUI Personal AI Assistant. Win/Linux/Mac. Show HN I made my vacation rental bookable by AI agents–no Airbnb, 0% commission GitHub - basteez/jsf-autoreload: maven plugin to enable hot reload on jsf projects uvm32/hosts/host-gdbstub at main · ringtailsoftware/uvm32 GitHub - labsai/EDDI: Config-driven engine that turns JSON into production-grade AI agents. Multi-agent orchestration, 12+ LLM providers, MCP/A2A protocols, RAG, persistent memory, and enterprise compliance (EU AI Act, GDPR, HIPAA). Built on Quarkus. GitHub - glitchnsec/fortyone-oss: AI Executive Assistant Platform Quickstart | Alien GitHub - muxshed/shed: One stream in, or many. Every destination, simultaneously. No cloud middleman, no per-channel fees, no limits. GitHub - ocrbase-hq/ocrbase: 📄 PDF/IMG ->.MD/JSON Document OCR API for PaddleOCR and GLMOCR. Self-hostable. GitHub - impactjo/home-memory: MCP server that lets your AI assistant remember everything about your home. GitHub - Sets88/dbcls: DbCls is a powerful terminal database client that supports various databases GitHub - neptun2000/heor-agent-mcp GitHub - SeanFDZ/macmind: Single-layer transformer in HyperTalk for the classic Macintosh RollQuation: Math Puzzles - Apps on Google Play GitHub - dropbox/witchcraft Show HN: Agent-cache – Multi-tier LLM/tool/session caching for Valkey and Redis GitHub - opentalon/opentalon: OpenTalon is an open-source platform built from the ground up in Go as a robust alternative to OpenClaw LinkedIn™ 职位抓取工具 - Chrome 应用商店
offline country lookup (a Trifold library)
jaakl · 2026-06-16 · via Hacker News: Show HN

countrycheck: which country is this point in?

An offline lookup library built on the Trifold grid. The level-10 grid (~7 km cells) classified against country polygons with accurate OSM-derived borders — extended with coastal waters and including X-coded territories like Kosovo and the Caspian Sea — collapses into a 323 KB dataset that names the country anywhere on Earth in microseconds, with a confidence value for every answer. Python and JavaScript give identical results. This page runs the real JS library in your browser; the dataset is embedded right in this HTML file.

Try it on the map

Interactive demo

Load sample points or your own file (CSV lon,lat or GeoJSON points), and every point is resolved to a country in your browser by the bundled library, with no server and no network call per lookup. Each dot is coloured by the country it lands in; open ocean stays grey. The lookups-per-second figure is measured tightly around the classification loop on your machine (map rendering and file parsing excluded), so it is the real library throughput. Use the 100k-random button for a stable number.

Controls

Your own points

Open CSV / GeoJSON…

CSV: lon,lat[,name] per line (or a header naming lat/lon columns in either order). GeoJSON: any FeatureCollection of Points. Files stay on your machine.

Exact border refinement exact polygon test wherever a border crosses a cell (downloads ~19 MB once)

Off: border cells use the bundled best-call with its area share as confidence. On: exact country/country and coastline borders. Watch how the counts, confidence and lookup rate change.

Debug layers source border polygons (needs the refinement layer)

Click anywhere on the map to see the level-10 triangle and its country answer.

one hue per country (256 total)
no country: open ocean (confidence 1.0)
border cell (mixed)
answer changed by refinement

Loading dataset…

Click any classified point for its full answer: country code (GADM gid_0), ISO 2, name, kind, confidence, area share and cell address (computed on the fly for open-ocean points, whose cells are not stored). Switching on exact border refinement makes the source polygons authoritative in every cell a border crosses. Caveats inherited from the source data: coastal waters are an approximate distance-based assignment, not legal EEZ; disputed territories follow GADM (Crimea, Western Sahara…); lakes belong to their surrounding country, except the Caspian Sea, which is its own XCA entry.

User guide

JavaScript (browser or Node)

import { CountryCheck } from "./countrycheck.mjs";

// Node: bundled file · browser: fetch the 323 KB dataset
const cc = await CountryCheck.fromFile();                  // Node
const cc = await CountryCheck.fromUrl("countries_L10.tfcs"); // browser

cc.country(24.7536, 59.437);   // 'EST'  (lon, lat)
cc.check(-0.1276, 51.5072);
// { country: 'GBR', iso2: 'GB', name: 'United Kingdom',
//   kind: 'country', confidence: 1, share: 1,
//   cell: 'TFA95BM', refined: false }

Python (stdlib only)

from countrycheck import CountryCheck

cc = CountryCheck()                    # bundled data
cc.country(24.7536, 59.4370)           # 'EST'
cc.check(-0.1276, 51.5072)
# CountryResult(country='GBR', iso2='GB',
#   name='United Kingdom', kind='country',
#   confidence=1.0, share=1.0, cell='TFA95BM',
#   refined=False)

What the answer means

kindmeaningcountryconfidence
countrycell wholly inside one countrythat country1.0
nonecell absent from the dataset (international waters) null1.0
bordermixed cell; bundled best call decides (may be none) best callarea share
border + refineddecided by the exact source polygon exact0.99

Measured accuracy: 99.82% agreement with exact polygon containment on 30,000 uniform random points. The country and none answers were 100% correct; all residual error lives in border answers, which self-report lower confidence. With the border refinement loaded, agreement reaches 100.0% on the same sample.

Command line

$ python countrycheck/python/countrycheck.py 24.7536 59.4370
EST  iso2=EE  name='Estonia'  kind=country  confidence=1.000  share=1.0  cell=TFAVKGR  refined=False

The CLI loads the border refinement automatically when borders_L10.tfcr is present. Install with pip install countrycheck or npm install countrycheck, or run straight from a repo checkout.

Technical info

Canonical index

Any Trifold cell at level ≤ 10 maps to a contiguous range in the level-10 index space (face·410 + path): a level-l cell covers exactly 410−l consecutive indices. The whole country classification becomes run-length intervals.

TFCS format · 323 KB

222,403 runs as varint(gap), varint(len·2|border) — interior runs carry a country id, border runs a best call plus a 4-bit area share — over a country table of 256 code/iso2/name strings, all zlib-compressed. Level-agnostic.

Lookup path

Pure-float point location (no dependencies, bit-identical to the SDK) descends 10 subdivision levels, then one binary search over the run starts. ~0.6 µs in Node, ~13 µs in pure Python, ~3 µs batched with numpy.

Border refinement · TFCR

Source country polygons clipped to every border cell, quantized to a cell-local 16-bit grid (~0.1 m), one zone per country present with zigzag-varint rings and the even-odd rule. A point-in-polygon test then decides the exact country (or none) in those cells.

The borders come from the timezone-boundary-builder “with oceans” polygons (OSM-derived, already reaching into territorial water); GADM level-0 supplies only the country identity and ISO codes, joined by max land overlap. 256 countries and territories, 6.90M level-10 cells belonging to some country, of which 195,473 are border cells. Full documentation, the one-pass build.py, the PostGIS source build (sql/build_countries_coastal.sql) and the cross-language test suite live in countrycheck/ on GitHub. Roadmap: an L12 (~1.8 km) variant and timezone detection from the same source data.

Accuracy: tested on 57,501 real airports

Ground truth is the OurAirports dump — 57,501 points, each tagged with an ISO country code from an unrelated source. countrycheck places 99.50% of them in the correct country from the bundled 323 KB data, and 99.68% with the border refinement loaded. Interior-country answers are 99.91% correct; the refinement works only on the 729 airports that fall in a border cell, and there it lifts agreement from 80.66% to 95.20% — the payoff of the accurate OSM-derived borders.

99.50% → 99.68%

overall agreement with airport country codes, bundled vs. border-refined. The residual is mostly disputed/border territory the sources map differently, dependencies coded to a parent state, and offshore or placeholder coordinates.

99.995% refined

against exact SQL point-in-polygon containment over the same source polygons (100,000 random points): the refinement resolved all but 5 of the 168 base-mode border disagreements (those 5 are coastal-overlap tie-breaks). Base mode: 99.83%.

Reproduce with scripts/accuracy_countrycheck_airports.py (airports) and scripts/benchmark_countrycheck.py (vs. SQL containment).

Benchmark: 7–97× faster than SQL spatial engines

One workload, four engines: assign a country (gid_0) to 100,000 sphere-uniform random points against the same country polygons. Median of seven warm runs, Apple M5 Pro, June 2026. The refined Trifold answers reproduce exact polygon containment to 99.995% (see above) while running an order of magnitude faster — ~7× PostGIS, ~97× DuckDB Spatial. Called one point at a time, the gap holds.

Batch · 100,000 points per call

Trifold base

452,594 pts/s

Singular · one point per call

DuckDB 1.5.3 and PostGIS 3.6.3 compute exact containment and returned byte-identical answers; BigQuery is documented but was not run in this pass. PostGIS singular includes localhost TCP + Docker transport; DuckDB runs embedded in-process. The live figure in the demo panel is the same throughput measured on your own device. Full methodology, dataset manifest, the airport test and the BigQuery procedure: countrycheck_benchmark.md.