Skip to content

Locations API (Pending)

Migration Pending

This API is pending migration to Cloudflare Workers.

The Locations API manages physical locations, intersections, and geographical zones for traffic monitoring.

Planned Procedures

ProcedureTypeDescription
locations.getAllQueryGet all locations
locations.getByIdQueryGet location by ID
locations.createMutationCreate new location
locations.updateMutationUpdate location
locations.deleteMutationDelete location
locations.getSensorsQueryGet sensors at location
locations.getZonesQueryGet geographical zones

Data Model

Location

typescript
interface Location {
  id: string;
  name: string;
  description?: string;
  address?: string;
  type: LocationType;
  coordinates: {
    latitude: number;
    longitude: number;
  };
  zone?: string;
  region?: string;
  city?: string;
  sensors: Sensor[];
  metadata?: Record<string, any>;
  createdAt: Date;
  updatedAt: Date;
}

Location Type

typescript
enum LocationType {
  INTERSECTION = "INTERSECTION",
  HIGHWAY = "HIGHWAY",
  CHECKPOINT = "CHECKPOINT",
  PARKING = "PARKING",
  ZONE = "ZONE",
  CUSTOM = "CUSTOM"
}

Planned Input Schemas

Create Location

typescript
{
  name: string;                    // Required, 3-100 chars
  description?: string;
  address?: string;
  type: LocationType;
  coordinates: {
    latitude: number;              // -90 to 90
    longitude: number;             // -180 to 180
  };
  zone?: string;
  region?: string;
  city?: string;
}

Update Location

typescript
{
  id: string;                      // Required
  name?: string;
  description?: string;
  address?: string;
  type?: LocationType;
  coordinates?: {
    latitude: number;
    longitude: number;
  };
  zone?: string;
  region?: string;
  city?: string;
}

Query Locations

typescript
{
  skip?: number;
  take?: number;
  search?: string;
  type?: LocationType;
  zone?: string;
  city?: string;
  bounds?: {
    north: number;
    south: number;
    east: number;
    west: number;
  };
}

Expected Responses

Get All Locations

json
{
  "locations": [
    {
      "id": "loc-001",
      "name": "Main Street Intersection",
      "type": "INTERSECTION",
      "address": "Main St & First Ave, Almaty",
      "coordinates": {
        "latitude": 43.238949,
        "longitude": 76.945465
      },
      "city": "Almaty",
      "sensorCount": 4,
      "createdAt": "2024-01-15T10:00:00.000Z"
    }
  ],
  "total": 150,
  "pageCount": 15
}

Use Cases

Traffic Monitoring

  • Group sensors by intersection
  • Define monitoring zones
  • Track traffic flow between locations

Analytics

  • Location-based violation statistics
  • Heat maps of traffic density
  • Regional comparisons

Geofencing

  • Define alert zones
  • Monitor vehicle entry/exit
  • Speed zone management

Migration Notes

Database Changes

  • Convert MongoDB ObjectId to UUID
  • Migrate GeoJSON to SQLite-compatible format
  • Index optimization for spatial queries

D1 Schema

sql
CREATE TABLE locations (
  id TEXT PRIMARY KEY,
  name TEXT NOT NULL,
  description TEXT,
  address TEXT,
  type TEXT NOT NULL,
  latitude REAL NOT NULL,
  longitude REAL NOT NULL,
  zone TEXT,
  region TEXT,
  city TEXT,
  metadata TEXT,
  createdAt TEXT NOT NULL,
  updatedAt TEXT NOT NULL
);

CREATE INDEX idx_locations_type ON locations(type);
CREATE INDEX idx_locations_city ON locations(city);
CREATE INDEX idx_locations_coords ON locations(latitude, longitude);

SCS Smart City - Traffic, Gateway, Camera, and NVR Platform