michigan-gov/mdot-bureau-of-bridges-and-structures-common-nfup-38ux
Loading...

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 mdot_bureau_of_bridges_and_structures_common table in this repository, by referencing it like:

"michigan-gov/mdot-bureau-of-bridges-and-structures-common-nfup-38ux:latest"."mdot_bureau_of_bridges_and_structures_common"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "geo_reference",
    "facility_carried_item_7_b", -- The name or names of the facilities carried by the structure.
    "report_date", -- The date the report was generated. Every row will have the same date.
    "latitude_item_16", -- The latitude of the bridge.
    "bridge_width_out_to_out_item", -- The out-to-out width of the deck to the nearest tenth of a foot. If the structure is a through structure, the number to be recorded will represent the lateral clearance between superstructure members. The measurement should be exclusive of flared areas for ramps. Where traffic runs directly on the top slab (or wearing surface) of the culvert, record the actual width (out-to-out). This will also apply where the fill is minimal, and the culvert headwalls affect the flow of traffic. However, for sidehill viaduct structures record the actual out-to-out structure width. Where the roadway is on a fill carried across a pipe or box culvert and the culvert headwalls do not affect the flow of traffic, record as blank. This is considered proper, as a filled section over a culvert simply maintains the roadway cross-section.
    "design_load_item_31_b_lr", -- The live load for which the structure was designed.
    "total_spans_item_45_item", -- The total number of spans on the structure.
    "owner_item_21_22_b_cl_01", -- The actual name(s) of the agency(s) responsible for the maintenance of the structure.
    "lanes_under_structure_item", -- The lanes under the structure. 
    "approach_span_design_type", -- The approach spans to the major bridge design type.
    "length_item_49_b_g_02", -- The length of the structure measured along the centerline of the roadway from back-to-back of backwalls of abutments or from paving notch to paving notch to the nearest tenth of a foot.
    "year_overlaid_b_w_02", -- The year the overlay was applied to the bridge deck.
    "year_reconstructed_item_106", -- The year of most recent reconstruction of the structure.
    "service_type_on_item_42a", -- The type of service the structure carries.
    "feature_intersected_item", -- The name or names of the features intersected by the structure.
    "structure_name", -- The name of the structure. 
    "region_item_2_b_l_04", -- The MDOT region of the structure. 
    "longitude_item_17", -- The longitude of the bridge.
    "lanes_on_structure_item_28a", -- The lanes carried on the structure.
    "approach_span_count_item", -- The type of structure for the approach spans to a major bridge or for the spans where the structural material is different.
    "year_painted_b_w_02", -- The year the structure was last painted.
    "service_type_under_item_42b", -- The type of service the structure crosses.
    "approach_span_material_type", -- The approach spans to the major bridge material type.
    "main_span_design_type_item", -- The main spans design type.
    "wearing_surface_item_108a", -- The wearing surface and protective system of the bridge deck.
    "main_span_count_item_45_b", -- The number of spans in the main or major unit. 
    "structure_number_item_8_b", -- The unique structure number identifying the structure.
    "main_span_material_type_item", -- The main spans material type.
    "year_built_item_27_b_w_01", -- The year of construction for when the structure was built.
    "location_item_9_b_l_06", -- A narrative description of the bridge location.
    ":@computed_region_v2et_sdmx", -- This column was automatically created in order to record in what polygon from the dataset 'County Boundaries' (v2et-sdmx) the point in column 'geo_reference' is located.  This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
    ":@computed_region_w7pm_j3n4" -- This column was automatically created in order to record in what polygon from the dataset 'ISD' (w7pm-j3n4) the point in column 'geo_reference' is located.  This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
FROM
    "michigan-gov/mdot-bureau-of-bridges-and-structures-common-nfup-38ux:latest"."mdot_bureau_of_bridges_and_structures_common"
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 michigan-gov/mdot-bureau-of-bridges-and-structures-common-nfup-38ux with SQL in under 60 seconds.

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, 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 (like this repository), where the author has pushed Splitgraph Images to the repository, you can "clone" and/or "checkout" the data using sgr cloneand sgr checkout.

Cloning Data

Because michigan-gov/mdot-bureau-of-bridges-and-structures-common-nfup-38ux:latest is a Splitgraph Image, you can clone the data from Spltgraph Cloud to your local engine, where you can query it like any other Postgres database, using any of your existing tools.

First, install Splitgraph if you haven't already.

Clone the metadata with sgr clone

This will be quick, and does not download the actual data.

sgr clone michigan-gov/mdot-bureau-of-bridges-and-structures-common-nfup-38ux

Checkout the data

Once you've cloned the data, you need to "checkout" the tag that you want. For example, to checkout the latest tag:

sgr checkout michigan-gov/mdot-bureau-of-bridges-and-structures-common-nfup-38ux:latest

This will download all the objects for the latest tag of michigan-gov/mdot-bureau-of-bridges-and-structures-common-nfup-38ux and load them into the Splitgraph Engine. Depending on your connection speed and the size of the data, you will need to wait for the checkout to complete. Once it's complete, you will be able to query the data like you would any other Postgres database.

Alternatively, use "layered checkout" to avoid downloading all the data

The data in michigan-gov/mdot-bureau-of-bridges-and-structures-common-nfup-38ux:latest is 0 bytes. If this is too big to download all at once, or perhaps you only need to query a subset of it, you can use a layered checkout.:

sgr checkout --layered michigan-gov/mdot-bureau-of-bridges-and-structures-common-nfup-38ux:latest

This will not download all the data, but it will create a schema comprised of foreign tables, that you can query as you would any other data. Splitgraph will lazily download the required objects as you query the data. In some cases, this might be faster or more efficient than a regular checkout.

Read the layered querying documentation to learn about when and why you might want to use layered queries.

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, michigan-gov/mdot-bureau-of-bridges-and-structures-common-nfup-38ux is just another Postgres schema.

Related Documentation:

Loading...