Skip to content

Add GetIdCommand for retrieving features by OSM ID#32

Open
JeremyBYU wants to merge 1 commit intoclarisma:mainfrom
JeremyBYU:jc/get-id
Open

Add GetIdCommand for retrieving features by OSM ID#32
JeremyBYU wants to merge 1 commit intoclarisma:mainfrom
JeremyBYU:jc/get-id

Conversation

@JeremyBYU
Copy link

Description of Work

Adds a new get-id CLI command for efficient OSM ID lookup using the index files generated by gol build -i. This is the CLI companion to libgeodesk PR #35, which provides the underlying getId() API.

Requires: clarisma/libgeodesk#35 (ID index support in libgeodesk)

What Changed

  • New get-id command (src/gol/GetIdCommand.cpp, src/gol/GetIdCommand.h)
    • Accepts typed IDs: n123 (node), w456 (way), r789 (relation)
    • Supports multiple IDs in a single invocation
    • All standard output formats: brief, count, list, geojson, geojsonl, wkt, csv
    • Uses IdIndex::findById() for fast lookups via pre-built indexes
  • Command registration in GolTool.cpp

Design Decision: Separate Command vs. Query Language Extension

The original libgeodesk PR mentioned future work to add w[id=12345] syntax to the GOQL query language. This implementation takes a different approach: a dedicated get-id command.

Why not extend the query language?

  1. Semantic mismatch - GOQL filters (a[highway=primary]) conceptually select from a set. ID lookup returns exactly 0 or 1 features—it's a key lookup, not a filter.

  2. Awkward composition - What does w[id=12345][highway=residential] mean? Apply both? It's redundant, the ID already uniquely identifies the feature.

  3. Different mental model - Users querying by ID typically want to retrieve a known feature, not filter an unknown set. A dedicated command makes this explicit.

  4. Cleaner UX - gol get-id world.gol w327189648 is direct and obvious. No need to remember filter syntax for a fundamentally different operation.

Usage Examples

# Get a single way
gol get-id world.gol w327189648

# Get multiple features
gol get-id world.gol n1 w2 r3

# Output as GeoJSON
gol get-id world.gol w123 -f geojson

# CSV with custom columns
gol get-id world.gol w123 -f csv -k id,name,highway

Open Questions

Currently if the index does not exist you will get an error like this:

❯ ./build/gol get-id $DATA_DIR/osm/planet-latest.gol w327189648 -v
 ──────  ID lookups require index files. Rebuild with: gol build -i ...

We could also fallback to brute force. But I felt that was overkill.

Finally, I would write some tests but am unsure how your testing infrastructure works.

Amount of Risk

Low risk, additive change.

  • No modifications to existing query paths or command behavior
  • Graceful failure if index files are missing (clear error message)
  • New command is isolated and self-contained

@JeremyBYU JeremyBYU mentioned this pull request Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant