datahub-austintexas-gov/watershed-reach-index-and-problem-scores-vk3r-6prc
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 watershed_reach_index_and_problem_scores table in this repository, by referencing it like:

"datahub-austintexas-gov/watershed-reach-index-and-problem-scores-vk3r-6prc:latest"."watershed_reach_index_and_problem_scores"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "index_aquatic_life", -- Aquatic Life Index score.  100 = best condition. (Bugs, diatoms abundance, diversity, pollution tolerance and other metrics)
    "index_water_quality", -- Water Quality Index score. 100 = best condition. (nutrients, temp, tss)
    "index_source_type", -- EII - Environmental Integrity Index or ALI - Austin Lakes Index 
    "problem_fertilizer", -- Fertilizer problem score (creeks only). 100 = worst condition. Nitrate.
    "index_vegetation", -- Vegetation Index score (for lakes only). 100 = best condition.
    "watershed_id", -- This is a foreign key to the system-assigned primary key to the  "Official Watershed List"  https://data.austintexas.gov/Government/Watersheds/ec78-i9z5  for the City of Austin.  1 to 1 relation with Watershed_Name. Even if Barton Creek is renamed, it will always have an ID of 1.
    "index_non_contact_recreation", -- Non Contact Recreation Index score (creeks only). 100 = best condition. Aesthetics, odor, safety.
    "problem_stability", -- Stability problem score (creeks only). 100 = worst condition. Stream bank failures.
    "index_habitat", -- Habitat Index score. 100 = best condition. Instream cover and substrate niches.
    "modified_by",
    "fiscal_year_of_observation", -- The City of Austin Fiscal year the data points are associated with. FY 2014 started on 01-OCT-2013 and ended 30-SEP-2014.
    "watershed_name", -- Official watershed name from this list: https://data.austintexas.gov/Government/Watersheds/ec78-i9z5
    "watershed_reach_id", -- Primary Varchar key for this dataset. 1 is most downstream reach and ascends for subsequent upstream reaches in the same watershed.
    "integrity_score_id", -- Primary Integer Key for this dataset.
    "problem_sewage", -- Sewage problem score (creeks only). 100 = worst condition. Water Quality problem caused by sewage.
    "problem_water_quality", -- Water Quality problem score (creeks only). 100 = worst condition. Water quality worst case.
    "problem_construction_runoff", -- Construction TSS Problem score (creeks only). 100 = worst condition.  Erosion and Sedimentation controls failure.
    "problem_riparian_vegetation", -- Riparian Vegetation problem score (creeks only). 100 = worst condition. Not enough riparian cover.
    "created_by",
    "problem_sediment", -- Sediment problem score (creeks only). 100 = worst condition. Worst of the problems set score.
    "index_reach_score", -- Overall Index Score. 100 = best condition.  Average of other index scores. Problem scores not included.
    "problem_animal_waste", -- Animal Problem score (creeks only). 100 = worst condition. Pet waste.
    "index_sediment", -- Sediment Index score. 100 = best condition. Metals, pcbs, pesticides average.
    "created_date",
    "index_eutrophication", -- Eutrophication Index score (for lakes only). 100 = best condition. In general, lower chlorophyll-a abundance and lower proportion of blue-green algae lead to a higher score to represent a superior trophic condition.
    "problem_litter", -- Litter problem score (creeks only). 100 = worst condition. Trash
    "index_phase", -- For streams only - one of two phases.  Lakes all collected in same phase.
    "modified_date",
    "index_contact_recreation" -- Contact Recreation Index score (for creeks only). 100 = best condition.  (bacteria)
FROM
    "datahub-austintexas-gov/watershed-reach-index-and-problem-scores-vk3r-6prc:latest"."watershed_reach_index_and_problem_scores"
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 datahub-austintexas-gov/watershed-reach-index-and-problem-scores-vk3r-6prc with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at datahub.austintexas.gov. When you querydatahub-austintexas-gov/watershed-reach-index-and-problem-scores-vk3r-6prc: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 datahub.austintexas.gov, 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 \
  "datahub-austintexas-gov/watershed-reach-index-and-problem-scores-vk3r-6prc" \
  --handler-options '{
    "domain": "datahub.austintexas.gov",
    "tables": {
        "watershed_reach_index_and_problem_scores": "vk3r-6prc"
    }
}'

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, datahub-austintexas-gov/watershed-reach-index-and-problem-scores-vk3r-6prc is just another Postgres schema.