Skip to content

api: Territory geometry + spatial lookup endpoints #59

Description

@victorquinn

Summary

Implement territory-specific API endpoints for geometry retrieval and spatial point-in-polygon lookups.

Files to Create

  • app/api/v1/territories/[id]/geometry/route.ts — GeoJSON geometry with simplification
  • app/api/v1/territories/lookup/route.ts — Point-in-polygon lookup

Geometry Endpoint

  • Returns GeoJSON for a territory
  • ?simplify=0.001 for detail view (~100m precision)
  • ?simplify=0.01 for overview (~1km precision)
  • Aggressive caching (boundaries rarely change)

Lookup Endpoint

  • ?lat=35.78&lng=-78.64 returns all territories containing the point
  • Uses bbox pre-filter + ST_Covers for accuracy
  • Returns region metadata with territory info

Acceptance Criteria

  • Geometry endpoint returns valid GeoJSON
  • Simplification reduces vertex count appropriately
  • Lookup correctly identifies territories for a point
  • Proper caching headers
  • npm run build passes

Spec ref: Sections 4.5–4.6
Blocked by: #5, #7
Blocks: Explorer territory migration

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions