cityofchicago/traffic-crashes-crashes-85ca-t3if
Icon for Socrata external plugin

Query the Data Delivery Network

Query the DDN

The easiest way to query any data on Splitgraph is via the "Data Delivery Network" (DDN). The DDN is a single endpoint that speaks the PostgreSQL wire protocol. Any Splitgraph user can connect to it at data.splitgraph.com:5432 and query any version of over 40,000 datasets that are hosted or proxied by Splitgraph.

For example, you can query the traffic_crashes_crashes table in this repository, by referencing it like:

"cityofchicago/traffic-crashes-crashes-85ca-t3if:latest"."traffic_crashes_crashes"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "injuries_fatal", -- Total persons sustaining fatal injuries in the crash
    "device_condition", -- Condition of traffic control device, as determined by reporting officer
    "weather_condition", -- Weather condition at time of crash, as determined by reporting officer
    "lighting_condition", -- Light condition at time of crash, as determined by reporting officer
    "first_crash_type", -- Type of first collision in crash
    "trafficway_type", -- Trafficway type, as determined by reporting officer
    "lane_cnt", -- Total number of through lanes in either direction, excluding turn lanes, as determined by reporting officer (0 = intersection)
    "alignment", -- Street alignment at crash location, as determined by reporting officer
    "roadway_surface_cond", -- Road surface condition, as determined by reporting officer
    "road_defect", -- Road defects, as determined by reporting officer
    "report_type", -- Administrative report type (at scene, at desk, amended)
    "crash_type", -- A general severity classification for the crash. Can be either Injury and/or Tow Due to Crash or No Injury / Drive Away 
    "intersection_related_i", -- A field observation by the police officer whether an intersection played a role in the crash. Does not represent whether or not the crash occurred within the intersection.
    "private_property_i", -- Whether the crash begun or first contact was made outside of the public right-of-way.
    "hit_and_run_i", -- Crash did/did not involve a driver who caused the crash and fled the scene without exchanging information and/or rendering aid
    "damage", -- A field observation of estimated damage.
    "date_police_notified", -- Calendar date on which police were notified of the crash
    "prim_contributory_cause", -- The factor which was most significant in causing the crash, as determined by officer judgment
    "sec_contributory_cause", -- The factor which was second most significant in causing the crash, as determined by officer judgment
    "street_no", -- Street address number of crash location, as determined by reporting officer
    "street_direction", -- Street address direction (N,E,S,W) of crash location, as determined by reporting officer
    "street_name", -- Street address name of crash location, as determined by reporting officer
    "beat_of_occurrence", -- Chicago Police Department Beat ID. Boundaries available at https://data.cityofchicago.org/d/aerh-rz74
    "photos_taken_i", -- Whether the Chicago Police Department took photos at the location of the crash
    "statements_taken_i", -- Whether statements were taken from unit(s) involved in crash
    "dooring_i", -- Whether crash involved a motor vehicle occupant opening a door into the travel path of a bicyclist, causing a crash
    "work_zone_i", -- Whether the crash occurred in an active work zone
    "work_zone_type", -- The type of work zone, if any
    "workers_present_i", -- Whether construction workers were present in an active work zone at crash location
    "num_units", -- Number of units involved in the crash. A unit can be a motor vehicle, a pedestrian, a bicyclist, or another non-passenger roadway user. Each unit represents a mode of traffic with an independent trajectory. 
    "most_severe_injury", -- Most severe injury sustained by any person involved in the crash
    "injuries_total", -- Total persons sustaining fatal, incapacitating, non-incapacitating, and possible injuries as determined by the reporting officer
    "injuries_incapacitating", -- Total persons sustaining incapacitating/serious injuries in the crash as determined by the reporting officer. Any injury other than fatal injury, which prevents the injured person from walking, driving, or normally continuing the activities they were capable of performing before the injury occurred. Includes severe lacerations, broken limbs, skull or chest injuries, and abdominal injuries.
    ":@computed_region_rpca_8um6", -- This column was automatically created in order to record in what polygon from the dataset 'Boundaries - ZIP Codes' (rpca-8um6) the point in column 'location' is located.  This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
    "injuries_non_incapacitating", -- Total persons sustaining non-incapacitating injuries in the crash as determined by the reporting officer. Any injury, other than fatal or incapacitating injury, which is evident to observers at the scene of the crash. Includes lump on head, abrasions, bruises, and minor lacerations.
    "injuries_reported_not_evident", -- Total persons sustaining possible injuries in the crash as determined by the reporting officer. Includes momentary unconsciousness, claims of injuries not evident, limping, complaint of pain, nausea, and hysteria.
    "injuries_no_indication", -- Total persons sustaining no injuries in the crash as determined by the reporting officer
    "injuries_unknown", -- Total persons for whom injuries sustained, if any, are unknown
    "crash_hour", -- The hour of the day component of CRASH_DATE.
    "crash_day_of_week", -- The day of the week component of CRASH_DATE. Sunday=1  
    "crash_month", -- The month component of CRASH_DATE.
    "latitude", -- The latitude of the crash location, as determined by reporting officer, as derived from the reported address of crash
    "longitude", -- The longitude of the crash location, as determined by reporting officer, as derived from the reported address of crash
    "location", -- The crash location, as determined by reporting officer, as derived from the reported address of crash, in a column type that allows for mapping and other geographic analysis in the data portal software
    "posted_speed_limit", -- Posted speed limit, as determined by reporting officer
    "crash_date", -- Date and time of crash as entered by the reporting officer
    "crash_date_est_i", -- Crash date estimated by desk officer or reporting party (only used in cases where crash is reported at police station days after the crash)
    "traffic_control_device", -- Traffic control device present at crash location, as determined by reporting officer
    "crash_record_id" -- This number can be used to link to the same crash in the Vehicles and People datasets. This number also serves as a unique ID in this dataset.
FROM
    "cityofchicago/traffic-crashes-crashes-85ca-t3if:latest"."traffic_crashes_crashes"
LIMIT 100;

Connecting to the DDN is easy. All you need is an existing SQL client that can connect to Postgres. As long as you have a SQL client ready, you'll be able to query cityofchicago/traffic-crashes-crashes-85ca-t3if with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at data.cityofchicago.org. When you querycityofchicago/traffic-crashes-crashes-85ca-t3if:latest on the DDN, we "mount" the repository using the socrata mount handler. The mount handler proxies your SQL query to the upstream data source, translating it from SQL to the relevant language (in this case SoQL).

We also cache query responses on the DDN, but we run the DDN on multiple nodes so a CACHE_HIT is only guaranteed for subsequent queries that land on the same node.

Query Your Local Engine

Install Splitgraph Locally
bash -c "$(curl -sL https://github.com/splitgraph/splitgraph/releases/latest/download/install.sh)"
 

Read the installation docs.

Splitgraph Cloud is built around Splitgraph Core (GitHub), which includes a local Splitgraph Engine packaged as a Docker image. Splitgraph Cloud is basically a scaled-up version of that local Engine. When you query the Data Delivery Network or the REST API, we mount the relevant datasets in an Engine on our servers and execute your query on it.

It's possible to run this engine locally. You'll need a Mac, Windows or Linux system to install sgr, and a Docker installation to run the engine. You don't need to know how to actually use Docker; sgrcan manage the image, container and volume for you.

There are a few ways to ingest data into the local engine.

For external repositories (like this repository), the Splitgraph Engine can "mount" upstream data sources by using sgr mount. This feature is built around Postgres Foreign Data Wrappers (FDW). You can write custom "mount handlers" for any upstream data source. For an example, we blogged about making a custom mount handler for HackerNews stories.

For hosted datasets, where the author has pushed Splitgraph Images to the repository, you can "clone" and/or "checkout" the data using sgr cloneand sgr checkout.

Mounting Data

This repository is an external repository. It's not hosted by Splitgraph. It is hosted by data.cityofchicago.org, and Splitgraph indexes it. This means it is not an actual Splitgraph image, so you cannot use sgr clone to get the data. Instead, you can use the socrata adapter with the sgr mount command. Then, if you want, you can import the data and turn it into a Splitgraph image that others can clone.

First, install Splitgraph if you haven't already.

Mount the table with sgr mount

sgr mount socrata \
  "cityofchicago/traffic-crashes-crashes-85ca-t3if" \
  --handler-options '{
    "domain": "data.cityofchicago.org",
    "tables": {
        "traffic_crashes_crashes": "85ca-t3if"
    }
}'

That's it! Now you can query the data in the mounted table like any other Postgres table.

Query the data with your existing tools

Once you've loaded the data into your local Splitgraph engine, you can query it with any of your existing tools. As far as they're concerned, cityofchicago/traffic-crashes-crashes-85ca-t3if is just another Postgres schema.