Spark SQL Geospatial · Realtime telemetry

Live Fleet Spatial Command

Track 24 simulated vehicles, score three geofences, and calculate spherical distance to HQ with real Spark geospatial functions—entirely in-browser.
loading spatial engine…
Active assets
Average speed
Restricted zone
Farthest from HQ
Spark query
Telemetry batch

Realtime operations map

vehiclealertHQ

Fleet priority queue

AssetClassSpeed km/hSpatial stateDistance to HQ

Equivalent PySpark geospatial query

# positions: streaming micro-batch with lon, lat, wkt, speed
positions.createOrReplaceTempView("positions")
scored = spark.sql("""
SELECT vehicle_id, speed,
  ST_Contains(
    ST_GeomFromText(:downtown_wkt, 4326),
    ST_GeomFromText(wkt, 4326)
  ) AS in_downtown,
  round(ST_DistanceSphere(
    ST_GeogFromText(wkt),
    ST_GeogFromText('POINT (-122.4194 37.7749)')
  )) AS meters_to_hq,
  ST_AsText(ST_GeomFromText(wkt, 4326)) AS position_wkt
FROM positions
""")
scored.writeStream.format("memory").start()
Spark spatial system tour

How does realtime fleet tracking work?

This dashboard generates moving telemetry, runs a real Spark SQL geospatial query in a Web Worker every second, and renders only Spark-scored positions.

01

Telemetry → Spark micro-batch

The simulator creates 24 vehicles with longitude, latitude, speed, heading, event time, and a WKT point such as POINT (-122.4194 37.7749). The Worker replaces the in-memory positions table with that batch, then runs the spatial query. Nothing is sent to a server.

02

What Spark computes

  • ST_GeomFromText(wkt, 4326) creates each WGS84 geometry.
  • ST_Contains(polygon, position) evaluates Downtown, Waterfront, and Restricted Yard membership.
  • ST_DistanceSphere(position, HQ) calculates real spherical meters to the operations center.
  • ST_AsText(position) returns normalized WKT used by the validation layer.

The “Spark query” KPI measures the complete register → plan → execute → JSON result cycle.

03

How to read the map

Vehicles

Cyan dots are normal assets. Their arrow shows heading and their trail holds the last 22 scored positions.

Alerts

Red pulsing assets are inside the restricted polygon or moving faster than 60 km/h.

Geofences

Cyan, purple, and red polygons are the same WKT boundaries passed into Spark SQL.

HQ

The green pulse is the fixed point used by ST_DistanceSphere.

Occupancy bars

Counts come from the three boolean ST_Contains result columns.

Priority queue

Restricted assets sort first, followed by the fastest vehicles.

04

Incidents and controls

The incident feed records a vehicle’s first transition into the Restricted Yard and first transition above the speed threshold. Pause tracking stops source generation and Spark triggers without clearing trails; Resume tracking continues from the next deterministic position.

Try pausing on a red vehicle, inspect its zone and distance in the queue, then resume to watch the next Spark-scored point arrive.

05

Browser execution boundary

Real in this tab: Spark SQL parsing/planning, in-memory table replacement, spatial UDF execution, one-second micro-batches, and all displayed geofence/distance results.

Not included: external map tiles, GPS hardware, Kafka/Event Hubs, remote executors, or cloud credentials. A production source would feed the same Worker batch contract through a credential-safe gateway.

Watch the next spatial batch

Close the guide and ensure tracking is running.