This document defines the canonical public interface that all DIGIPIN language libraries must implement. The goal is consistency, predictability, and cross-language parity.
- DIGIPIN is a pure, deterministic encoding
- No I/O, no networking, no external dependencies
- Same input → same output in every language
- No hidden state
Purpose Convert geographic coordinates to a 10-character DIGIPIN code.
Signature (conceptual)
encode(latitude, longitude) → digipin
Parameters
-
latitude- Type: floating point number
- Unit: decimal degrees
- Range: 2.5 ≤ latitude ≤ 38.5
-
longitude- Type: floating point number
- Unit: decimal degrees
- Range: 63.5 ≤ longitude ≤ 99.5
Return value
-
digipin- Type: string
- Format: 10 alphanumeric characters (optionally formatted with separators)
- Example:
39J-49L-L8T4or39J49LL8T4
Behavior
- Uses EPSG:4326 (WGS84)
- Implements DIGIPIN hierarchical 4×4 grid exactly as per spec
- Handles boundary conditions exactly as defined in the technical document
Errors
- Invalid latitude or longitude → error/exception
- Inputs outside bounding box → error/exception
Purpose Convert a DIGIPIN code to the geographic location it represents.
Signature (conceptual)
decode(digipin) → location
Parameters
-
digipin- Type: string
- Length: 10 characters (separators may be ignored)
- Case-insensitive (must be normalized internally)
Return value
-
locationlatitude(float, decimal degrees)longitude(float, decimal degrees)
The returned coordinates represent the center (centroid) of the DIGIPIN grid cell.
Errors
- Invalid length
- Invalid characters
- Invalid grid sequence
These improve usability but must not change core behavior.
normalize(digipin) → digipin
- Removes separators
- Converts to uppercase
- Validates character set
is_valid(digipin) → boolean
- Returns
trueif syntactically and semantically valid - Must not throw (pure validation)
-
Internal representation: no separators
-
Optional formatting for display:
- After 3rd and 6th character (e.g.
XXX-XXX-XXXX)
- After 3rd and 6th character (e.g.
-
Formatting must be cosmetic only
-
Libraries must use idiomatic error handling:
- Exceptions (Python, Swift, C#)
Result/Option(Rust)(value, error)(Go)
-
Error messages should be:
- Deterministic
- Human-readable
- Not localized (English only)
- Address resolution
- Reverse geocoding
- Maps, tiles, or visualization
- Persistence or databases
- Network services or APIs
- This API contract is stable starting v1.0.0
- Any breaking change requires a major version bump
- All language SDKs must adhere to this contract
A DIGIPIN library is considered compliant if and only if:
- It implements
encodeanddecode - It passes all shared test vectors
- It follows the boundary and labeling rules of the official specification