ny-gov/aquatic-biological-monitoring-sampling-locations-absp-7rbm
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 aquatic_biological_monitoring_sampling_locations table in this repository, by referencing it like:

"ny-gov/aquatic-biological-monitoring-sampling-locations-absp-7rbm:latest"."aquatic_biological_monitoring_sampling_locations"

or in a full query, like:

SELECT
    ":id", -- Socrata column ID
    "description", -- Narrative description of site, navigation aids. Describes exact point of sampling. “m” designates distance in meters; if field includes “above,” it means that the sampling was conducted upstream of the mentioned structure, such as “above the Mill St. bridge” means in the stream on the upstream side of the bridge; similarly, “below” indicates downstream
    "latitude", -- Latitude in decimal degrees
    "name", -- Name of the waterbody on which the sampling site is located
    "site_loc_id", -- Unique site identifier composed of the two-digit drainage
    "longitude", -- Longitude in decimal degrees
    ":@computed_region_wbg7_3whc", -- This column was automatically created in order to record in what polygon from the dataset 'New York Zip Codes' (wbg7-3whc) the point in column 'georeference' is located.  This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
    "huc_8", -- 8-digit Hydrologic Unit Code. HUC codes are a means of delineating an area of drainage of a stream or river; designated by the United States Geological Survey (http://water.usgs.gov/GIS/huc.html )
    "georeference", -- Open Data/Socrata-generated geocoding information from supplied address components.
    ":@computed_region_yamh_8v7k", -- This column was automatically created in order to record in what polygon from the dataset 'NYS Municipal Boundaries' (yamh-8v7k) the point in column 'georeference' is located.  This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
    ":@computed_region_kjdx_g34t", -- This column was automatically created in order to record in what polygon from the dataset 'Counties' (kjdx-g34t) the point in column 'georeference' is located.  This enables the creation of region maps (choropleths) in the visualization canvas and data lens.
    "last_year_sampled", -- The year during which the most current sampling was conducted at this stream and location.
    "county", -- County name in which the sampling site is located; if location is outside of New York, the state is noted here as well as the county name.
    "dec_region", -- Region 1: Nassau County and Suffolk counties; Region 2: Kings, Bronx, New York, Queens and Richmond Counties; Region 3: Dutchess, Orange, Putnam, Rockland, Sullivan, Ulster and Westchester counties; Region 4: Albany, Columbia, Delaware, Greene, Montgomery, Otsego, Rensselaer, Schenectady and Schoharie counties; Region 5: Clinton, Essex, Franklin, Fulton, Hamilton, Saratoga, Warren and Washington counties; Region 6: Herkimer, Jefferson, Lewis, Oneida and St. Lawrence counties; Region 7: Broome, Cayuga, Chenango, Cortland, Madison, Onondaga, Oswego, Tioga and Tompkins counties; Region 8: Chemung, Genesee, Livingston, Monroe, Ontario, Orleans, Schuyler, Seneca, Steuben, Wayne and Yates counties; Region 9: Allegany, Chautauqua, Cattaraugus, Erie, Niagara and Wyoming counties 
    "basin", --  Two-digit code of the basin in which the sampling site is located; one of the seventeen major hydrologic basins defined for New York State (parts of the basin may exist outside the state). Codes are as follows: 01: Niagara River/Lake Erie basin; 02: Allegheny River basin; 03: Lake Ontario basin; 04: Genesee River basin; 05: Chemung River basin; 06: Susquehanna River basin; 07: Seneca Oneida Onondaga Rivers basin; 08: Black River basin; 09: St. Lawrence River basin; 10: Lake Champlain basin; 11: Upper Hudson River basin; 12: Mohawk River basin; 13: Lower Hudson River basin; 14: Delaware River basin; 15: Passaic River/Newark Bay basin; 16: Housatonic River basin; 17: Atlantic Ocean Long Island Sound basin 
    "municipality" -- Name of municipality (town, city, village, hamlet) in which the site is located or the municipality in closest proximity to the site; if field includes “up” or “down” of a municipality, the sampling location is upstream or downstream of, but close to the named town, city, village or hamlet
FROM
    "ny-gov/aquatic-biological-monitoring-sampling-locations-absp-7rbm:latest"."aquatic_biological_monitoring_sampling_locations"
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 ny-gov/aquatic-biological-monitoring-sampling-locations-absp-7rbm 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 ny-gov/aquatic-biological-monitoring-sampling-locations-absp-7rbm: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 ny-gov/aquatic-biological-monitoring-sampling-locations-absp-7rbm

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 ny-gov/aquatic-biological-monitoring-sampling-locations-absp-7rbm:latest

This will download all the objects for the latest tag of ny-gov/aquatic-biological-monitoring-sampling-locations-absp-7rbm 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 ny-gov/aquatic-biological-monitoring-sampling-locations-absp-7rbm: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 ny-gov/aquatic-biological-monitoring-sampling-locations-absp-7rbm: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, ny-gov/aquatic-biological-monitoring-sampling-locations-absp-7rbm is just another Postgres schema.

Related Documentation:

Loading...