mydata-iowa-gov/national-incorporated-places-and-counties-djvt-gf3t
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 national_incorporated_places_and_counties table in this repository, by referencing it like:

"mydata-iowa-gov/national-incorporated-places-and-counties-djvt-gf3t:latest"."national_incorporated_places_and_counties"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "class_code", -- A code used by U.S. Census Bureau to identify the type of entity.  This resource contains information for the following:  C1 - An active incorporated place that does not serve as a county subdivision equivalent; C2 - An active incorporated place legally coextensive with a county subdivision but treated as independent of any county subdivision; C3 - A consolidated city; C4 - An active incorporated place with an alternate official common name; C5 - An active incorporated place that is independent of any county subdivision and serves as a county subdivision equivalent; C6 - An active incorporated place that partially is independent of any county subdivision and serves as a county subdivision equivalent or partially coextensive with a county subdivision but treated as independent of any county subdivision; C7 - An incorporated place that is independent of any county; C8 - The balance of a consolidated city excluding the separately incorporated place(s) within that consolidated government; C9 - An inactive or nonfunctioning incorporated place; H1 - An active county or statistically equivalent entity; H4 - A legally defined inactive or nonfunctioning county or statistically equivalent entity; H5 - A census areas in Alaska, a statistical county equivalent entity; and H6 - A county or statistically equivalent entity that is areally coextensive or governmentally consolidated with an incorporated place, part of an incorporated place, or a consolidated city.  See full list: https://www2.census.gov/geo/pdfs/reference/ClassCodes.pdf
    "primary_long_dec", -- Primary longitude in decimal degrees used to create the primary point for the local entity as provided by U.S. Geological Survey, 19810501, U.S. Geographic Names Information System (GNIS): U.S. Geological Survey, Reston, VA.  The primary point is generally at or near the geographic center of the incorporated place or county.
    "primary_lat_dec", -- Primary latitude in decimal degrees used to create the primary point for the local entity as provided by U.S. Geological Survey, 19810501, U.S. Geographic Names Information System (GNIS): U.S. Geological Survey, Reston, VA.  The primary point is generally at or near the geographic center of the incorporated place or county.
    "name", -- Name of local entity.
    "geocoded_column", -- Point based on primary lat and long.
    "state_name", -- Name of state entity is located.
    "fips", -- The FIPS code is a concatenation of two state number and either the five digit place code or three digit county code.  State Code is based on INCITS 38:200x, Formerly FIPS 5-2  County Code is based on INCITS 31:200x Formerly FIPS 6-4  Place Code is formerly FIPS 55, also known as Census Code.
    "gnis", -- Permanent, unique feature record identifier for Named Physical and Cultural Geographic Features (Except Roads and Highways) of the United States, Its Territories, Outlying Areas, and Freely Associated Areas, and the Waters of the Same to the Limit of the Twelve-Mile Statutory Zone (INCITS 446-2008).  Also known as Feature ID in the USGS's  Geographic Names Information System.
    ":@computed_region_g8ff_h7ce",
    ":@computed_region_y683_txed"
FROM
    "mydata-iowa-gov/national-incorporated-places-and-counties-djvt-gf3t:latest"."national_incorporated_places_and_counties"
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 mydata-iowa-gov/national-incorporated-places-and-counties-djvt-gf3t with SQL in under 60 seconds.

This repository is an "external" repository. That means it's hosted elsewhere, in this case at mydata.iowa.gov. When you querymydata-iowa-gov/national-incorporated-places-and-counties-djvt-gf3t: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 mydata.iowa.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 \
  "mydata-iowa-gov/national-incorporated-places-and-counties-djvt-gf3t" \
  --handler-options '{
    "domain": "mydata.iowa.gov",
    "tables": {
        "national_incorporated_places_and_counties": "djvt-gf3t"
    }
}'

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, mydata-iowa-gov/national-incorporated-places-and-counties-djvt-gf3t is just another Postgres schema.