15 KiB
Geographical resolution and map positioning
Implementation and qualification record, 13 November 2026. This feature extends existing Locations and Maps. Word Companion, manuscript persistence, Context and Intent are untouched.
Author workflow and triggers
Creating an unparented location does not submit lookup. Saving an explicit parent assignment, including creating a child beneath a recognised root, establishes/changes a hierarchy and automatically requests eligible work for that branch. Name/type edits to an existing location also re-evaluate identifying context. Reparenting follows the same path. The Resolve button is recovery, not mandatory setup. Maps can explicitly request its unsubmitted linked locations. There is no database-wide enrichment or periodic provider refresh.
Admission charges newly required uncached location work: up to 20 new eligible locations per submission, 20 per author in a rolling hour and 120 application-wide in that hour. This preserves the original maximum capacity of one 20-location author batch and six application batches while removing their per-click lockouts. Cached responses, confirmed/resolved locations, already-requested jobs and duplicates are not billed. Failed admissions roll back without charging. Multiple small parent-assignment actions can use the remaining allowance. Real HTTP requests have a separate persistent application counter and remain serialized, at least 15 seconds apart, and capped at 200/day. Bounded error retries and one optional context fallback consume that HTTP budget, not separate author hierarchy actions.
Location Details shows status, candidate name/administrative context/country/coordinates and source attribution. Selecting a candidate sends its index and the observed generation, never client-supplied coordinates. Confirmed matches persist until identifying context changes or the author explicitly chooses replacement/exclusion. Authors can exclude lookup and later re-enable it; re-enabling waits for a deliberate hierarchy request.
Eligibility and root reference
Existing database types are Country, Region, Town, Village, Street, Building, Floor, Room, Outdoor Area, Vehicle Interior, Landmark and Other. Only Country, Region, Town and Village currently qualify. The generic rule also supports State, County and City if those types already exist in another installation; it does not insert or rename types. Premises, streets and arbitrary non-geographical intermediate parents are excluded.
Country and administrative-root recognition uses the bundled Debian iso-codes ISO 3166-1/3166-2 datasets, not a UK-only coordinate gazetteer. Attribution/licensing accompany the files in PlotLine/Data/Reference/Geography/COPYRIGHT.txt. Update these reference snapshots from the upstream iso-codes project, review their differences and run the focused geography tests. Country names, official/common names and alpha-3 identifiers are accepted. Explicit subdivision codes and country-qualified subdivision names (for example US-CA or California, US) avoid unsafe bare-region assumptions. UK/United Kingdom and US/USA/United States aliases are supported, as are England, Scotland, Wales and Northern Ireland. Bare Georgia is deliberately excluded; use GEO for the country or US-GA for the state. Fictional roots fail closed. Incomplete/archived ancestor chains also fail closed.
Depth is flexible: there is no requirement to insert missing administrative levels. All available geographical ancestors are sent, with a country restriction and explicit subdivision checking when available. Production rules contain no manuscript-specific place names.
Provider decision and policy
The initial configurable provider is public Nominatim, following the developer's explicit decision for a small user base and finite author-triggered hierarchy requests. No local UK gazetteer, OS Names API, map tiles or additional coordinate infrastructure is shipped.
The OSMF usage policy was checked on 13 November 2026. It permits modest user-triggered searches, limits the application as a whole to at most one request per second, requires an identifying User-Agent and attribution, discourages recurring/bulk work, and restricts permissible small bulk jobs to one thread on one machine. Regular or day-long scripts have a stricter four-request-per-minute ceiling. Repeated queries must be cached. Service availability and permission can change. These limits are not a blanket approval for scaling the workload; review the provider before increasing caps or user numbers.
This implementation always uses the stricter 15-second interval, one designated host, one database-fenced external request at a time and a 200-request daily application cap. Retries also consume this budget. Public usage requires no API key or subscription; service capacity is donated and carries no application SLA. Data attribution is © OpenStreetMap contributors, with the ODbL/copyright link, retained with candidates and displayed in Location Details and geographical preview. The ODbL terms apply to reuse of the geographical cache; do not publish a substantial extracted database without reviewing its obligations.
The Search API returns ranked matches, not a proof of uniqueness. The Nominatim adapter automatically resolves only one non-truncated candidate with an exact place-name match, matching country/subdivision, all available additional administrative ancestors represented in the response, and identifying context beyond a country-only root (an explicit subdivision root or additional matching ancestor). Multiple candidates, missing context, aliases without exact provider-name evidence and country-only queries require confirmation. A single ranking alone is insufficient. This deliberately means that the broad United Kingdom → town case may require confirmation; England → town or matching county context can resolve automatically. Other adapters must establish equivalent reliable matching rules before setting UniqueWithinContext. The deterministic tests cover automatic resolution and conservative ambiguity. OSM identities use osm_type:osm_id; Nominatim's transient numeric place_id is not treated as a stable identity (output documentation).
Earlier OS Open Names investigation found Great Britain coverage only, OGL commercial reuse, quarterly full replacements and an API alternative with the same underlying geographical coverage. Northern Ireland must not be inferred from Great Britain coverage. This direction was superseded by the explicit Nominatim decision; no OS data/importer/provider is part of this feature.
Configuration and safe disable/switch
Defaults keep external processing disabled. Put the following section in the deployment's watched appsettings.Production.json (or the applicable watched environment JSON), preserving its other settings:
"Geography": {
"Enabled": false,
"Provider": "Nominatim",
"Endpoint": "https://nominatim.openstreetmap.org/search",
"UserAgent": "PlotDirector/1.0 (+https://dev.plotdirector.com/)",
"WorkerHost": "atlas",
"MinimumIntervalSeconds": 15
}
Use the actual designated machine name and an identifying application/contact URL. Enabled=true requires a valid PlotDirector User-Agent and matching host. Enabled=false or a provider value other than Nominatim disables external lookup. An alternative Nominatim-compatible endpoint can be selected through the same configuration. IOptionsMonitor reloads watched JSON without redeployment. Environment-variable changes require a process restart, so use watched JSON when immediate disable/switch is required. HTTP redirects are disabled, and the server never exposes this configuration to browser clients. HttpClient request logging is removed for this client to prevent query URLs leaking into routine logs.
No external requests run during the automated tests. Public service testing must be an explicitly approved, small manual author-triggered acceptance check, not a dependency of the regression gate.
Queue, cache, concurrency and privacy
The Locations trigger invalidates changed locations and descendants on name/type/parent/archive changes. Ordinary descriptions do not invalidate confirmed geography. Invalidation increments a generation and revokes leases; it does not submit new work. The application admits author hierarchy events after its existing project-access checks. SQL rechecks project access and generation and admits the finite subtree under a transaction and central quota lock.
Jobs persist across restarts. A single per-location row deduplicates work. A two-minute processing lease supports crash recovery; a 25-second HTTP timeout keeps normal calls within that lease. Provider reservations serialize all external requests across application processes, with a persistent next-request timestamp, daily budget and cross-author request-key lease. The designated-host check prevents external processing on a second machine. Persistent request-key caching prevents repeats, including empty results; no TTL refresh is scheduled. Provider/endpoint plus country/subdivision and the complete available ancestor context form the request hash. Different Newtown contexts cannot reuse coordinates based on name alone.
If a full hierarchy query returns no geographical match, the worker queues at most one country-scoped fallback. It uses a separate persistent cache key and passes through the same external reservation gate. Its generation-bound stage survives restart and resets automatically when identifying context changes. A relaxed-context result always requires author confirmation; geographical parentage need not match the provider's administrative boundaries.
Shared cache entries contain provider-returned public geographical candidates: provider/OSM identity, canonical display name, coordinates, country, administrative context, attribution and resolution time. They contain no project, account, private description, manuscript text or original hierarchy. Per-author confirmation remains on that author's Location record; an ambiguous choice by one author is not silently promoted into another author's confirmed match. Identical candidate sets may be reused, with confirmation still required.
Provider failures have four bounded attempts and 60/120/240/480-second backoff. Rate reservation failures defer work without consuming a provider failure. HTTP 403/429 also apply an application-wide cooldown, respecting Retry-After subject to safe bounds. No provider error body/query/credential is logged. Only bounded error-type operational events are logged. Stale completion checks both generation and lease; a confirmed coordinate cannot be overwritten by a worker.
Maps
Position geographically projects resolved, unlocked location markers onto the currently visible canvas area. It uses a spherical azimuthal equidistant local projection, north up at its centre; circular longitude centring handles the antimeridian. One scale preserves aspect ratio with padding. Single/coincident points remain finite and centred; coincident places deliberately overlap. Shapes, paths, unlinked markers and locked pieces retain their serialized contents. Connected routes retain their existing behaviour of following their linked markers.
This is a local projection, not a claim that every pairwise spherical distance is exactly preserved. Extents beyond 15 degrees from the centre (roughly 1,650 km) are refused to avoid a misleading global arrangement. Labels and markers may overlap in dense clusters; authors can adjust them afterwards.
At least two distinct resolved, unlocked locations are required; a single marker is never centred and presented as a successful geographical arrangement. The actual proposed canvas is rendered inside a larger confirmation dialog, including unchanged surroundings, with north-up orientation, statuses and recovery links. The working document remains unchanged during preview. The dialog identifies moves, skipped statuses/locks and attribution. Cancel/Escape preserve the complete document. Apply adds one existing Undo/Redo checkpoint; Save uses the established map revision/permission/persistence path. No objects are deleted/recreated. Manual canvas dragging cannot alter geographical coordinates. Repositioning is always explicit.
Database rollout
Original tables/procedures are in 253, 254, 255 and 256. Corrections 257 and 258 implement work-based accounting, detailed queue state and the bounded context fallback; apply them after 256. Apply 253, 255, 254, 256, not a blind numeric replay. During Development qualification, 254 exposed that a new job-state label exceeded the original 24-character column; 255 is the forward-only width repair, preserving the applied scripts. 254 then completed successfully. 256 indexes the durable queue and batch-time lookup.
Development was verified as PlotDirector_Development before applying changes. A copy-only compressed CHECKSUM backup was successfully created and its nonempty container file verified at /var/opt/mssql/backup/PlotDirector_Development_geography_20261113_142234.bak. An additional RESTORE VERIFYONLY attempt was unavailable to the application principal (CREATE DATABASE permission); no restore was attempted. The backup is not a tested restore. Existing unrelated manuscript/Word work is preserved.
New per-location geography rows cascade on physical Location deletion. Shared public cache and provider-budget rows contain no private project hierarchy. The feature does not modify the existing map X/Y schema. Project backups currently do not export/import geocoding decisions; restored locations will need an explicit hierarchy request and confirmation again. Existing map canvas coordinates continue through the established map backup path.
Verification commands
Run build and regression serially:
dotnet build PlotLine.slnx
dotnet run --project PlotLine.Tests/PlotLine.Tests.csproj
dotnet run --project PlotLine.Tests/PlotLine.Tests.csproj -- --geography
The normal harness includes the deterministic geography group. Development-only SQL regressions 253_LocationGeographyRegression.sql and 254_GeographyHierarchyBatchesRegression.sql use rollback fixtures. --geography-database separately verifies 16 concurrent database provider reservations, persistent cooldown and fresh-connection recovery using random synthetic provider/request identifiers, then removes only its own rows. It makes no external requests.
Browser tests: maps-geography-engine.cjs, maps-geography.cjs, location-geography.cjs, existing maps-engine.cjs, maps-workspace.cjs, location-reparent.cjs, and application-pwa.cjs. The workspace tests use the isolated Razor host (--toolbar-browser-host) and deterministic mocked resolutions/saves, including browser/PWA and light/dark themes. The existing Maps test screenshots were redirected to the task evidence directory because the shared /tmp write quota rejected screenshot output; assertions were unchanged.
Final execution results, deployed commit and any remaining Development acceptance work are recorded in the delivery report accompanying this document.