> ## Documentation Index
> Fetch the complete documentation index at: https://docs-attestly.code4source.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Return reference areas within a distance range of a geometry

> Accepts a GeoJSON Polygon, MultiPolygon, or Point and returns reference areas whose great-circle distance to the input lies in ``[min_distance_m, max_distance_m]`` across all registered datasets. Content is negotiated via the ``Accept`` header:

- ``application/json`` (default) — `StandardResponse[DistanceResponse]`.
- ``application/geo+json`` — a GeoJSON `FeatureCollection`.
- ``application/x-ndjson`` — server-side fan-out streamed as NDJSON. Within each per-source frame hits are sorted ASC by ``distance_m``; cross-source ordering is completion order, so clients re-sort once the stream ends if they want a global view.



## OpenAPI

````yaml /openapi.json post /v1/distance
openapi: 3.0.3
info:
  description: >-
    Geographic compliance API — evaluates polygons against authoritative
    environmental and regulatory datasets and returns deterministic, audit-ready
    verdicts.
  title: Attestly API
  version: 1.0.0
servers: []
security: []
paths:
  /v1/distance:
    post:
      tags:
        - Distance
      summary: Return reference areas within a distance range of a geometry
      description: >-
        Accepts a GeoJSON Polygon, MultiPolygon, or Point and returns reference
        areas whose great-circle distance to the input lies in
        ``[min_distance_m, max_distance_m]`` across all registered datasets.
        Content is negotiated via the ``Accept`` header:


        - ``application/json`` (default) — `StandardResponse[DistanceResponse]`.

        - ``application/geo+json`` — a GeoJSON `FeatureCollection`.

        - ``application/x-ndjson`` — server-side fan-out streamed as NDJSON.
        Within each per-source frame hits are sorted ASC by ``distance_m``;
        cross-source ordering is completion order, so clients re-sort once the
        stream ends if they want a global view.
      operationId: find_distance_v1_distance_post
      parameters:
        - in: header
          name: accept
          required: false
          schema:
            nullable: true
            title: Accept
            type: string
        - in: header
          name: Idempotency-Key
          required: false
          schema:
            nullable: true
            title: Idempotency-Key
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DistanceRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema: {}
          description: Distance matches returned.
        '400':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: Malformed request body.
        '401':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: Missing or invalid JWT.
        '402':
          description: Subscription is inactive.
        '403':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: Authorization failed.
        '404':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: Resource not found.
        '409':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: Resource conflict.
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: Input failed validation.
        '429':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: Rate limit exceeded
        '500':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/ProblemDetail'
          description: Unexpected server error.
      security:
        - HTTPBearer: []
components:
  schemas:
    DistanceRequest:
      properties:
        input:
          $ref: '#/components/schemas/DistanceInput'
          description: >-
            User-supplied data for the request — geometry, optional CRS, and the
            ``[min_distance_m, max_distance_m]`` bounds. Required.
        reference_areas_country_iso3:
          description: ISO3 filter (e.g. 'BRA').
          maxLength: 3
          minLength: 3
          nullable: true
          title: Reference Areas Country Iso3
          type: string
        reference_areas_source:
          description: Source filter (e.g. 'wfs').
          maxLength: 64
          nullable: true
          title: Reference Areas Source
          type: string
        reference_id:
          description: Optional caller-provided reference identifier for audit/trace.
          maxLength: 128
          nullable: true
          title: Reference Id
          type: string
      required:
        - input
      title: DistanceRequest
      type: object
    ProblemDetail:
      properties:
        detail:
          type: string
        instance:
          type: string
        status:
          type: integer
        title:
          type: string
        type:
          format: uri
          type: string
      required:
        - type
        - title
        - status
      type: object
    DistanceInput:
      additionalProperties: false
      properties:
        crs:
          description: >-
            Optional source CRS of the input geometry (e.g. ``EPSG:31983``).
            When present, the engine projects the geometry to WGS84 before
            evaluation. When absent, geometry is assumed to be WGS84. Accepts
            EPSG codes, PROJ strings, or WKT — anything ``pyproj`` can parse.
            Unknown CRSes return HTTP 400.
          maxLength: 256
          nullable: true
          title: Crs
          type: string
        geometry:
          description: >-
            GeoJSON Polygon, MultiPolygon, or Point used as the input shape for
            the request.
          discriminator:
            mapping:
              MultiPolygon:
                $ref: '#/components/schemas/MultiPolygon'
              Point:
                $ref: '#/components/schemas/Point'
              Polygon:
                $ref: '#/components/schemas/Polygon'
            propertyName: type
          oneOf:
            - $ref: '#/components/schemas/Polygon'
            - $ref: '#/components/schemas/MultiPolygon'
            - $ref: '#/components/schemas/Point'
          title: Geometry
        max_distance_m:
          description: Inclusive upper bound in meters. Must be > 0 and >= min.
          exclusiveMinimum: true
          minimum: 0
          title: Max Distance M
          type: number
        min_distance_m:
          default: 0
          description: Inclusive lower bound in meters. Defaults to 0.
          minimum: 0
          title: Min Distance M
          type: number
      required:
        - geometry
        - max_distance_m
      title: DistanceInput
      type: object
    MultiPolygon:
      description: MultiPolygon Model
      properties:
        bbox:
          anyOf:
            - items:
                type: number
              maxItems: 4
              minItems: 4
              type: array
            - items:
                type: number
              maxItems: 6
              minItems: 6
              type: array
          nullable: true
          title: Bbox
        coordinates:
          items:
            items:
              items:
                anyOf:
                  - $ref: '#/components/schemas/Position2D'
                  - $ref: '#/components/schemas/Position3D'
              minItems: 4
              type: array
            type: array
          title: Coordinates
          type: array
        type:
          enum:
            - MultiPolygon
          title: Type
          type: string
      required:
        - type
        - coordinates
      title: MultiPolygon
      type: object
    Point:
      description: Point Model
      properties:
        bbox:
          anyOf:
            - items:
                type: number
              maxItems: 4
              minItems: 4
              type: array
            - items:
                type: number
              maxItems: 6
              minItems: 6
              type: array
          nullable: true
          title: Bbox
        coordinates:
          anyOf:
            - $ref: '#/components/schemas/Position2D'
            - $ref: '#/components/schemas/Position3D'
          title: Coordinates
        type:
          enum:
            - Point
          title: Type
          type: string
      required:
        - type
        - coordinates
      title: Point
      type: object
    Polygon:
      description: Polygon Model
      properties:
        bbox:
          anyOf:
            - items:
                type: number
              maxItems: 4
              minItems: 4
              type: array
            - items:
                type: number
              maxItems: 6
              minItems: 6
              type: array
          nullable: true
          title: Bbox
        coordinates:
          items:
            items:
              anyOf:
                - $ref: '#/components/schemas/Position2D'
                - $ref: '#/components/schemas/Position3D'
            minItems: 4
            type: array
          title: Coordinates
          type: array
        type:
          enum:
            - Polygon
          title: Type
          type: string
      required:
        - type
        - coordinates
      title: Polygon
      type: object
    Position2D:
      items:
        title: Longitude
        type: number
      maxItems: 2
      minItems: 2
      type: array
    Position3D:
      items:
        title: Longitude
        type: number
      maxItems: 3
      minItems: 3
      type: array
  securitySchemes:
    HTTPBearer:
      scheme: bearer
      type: http

````