Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

koop-socrata

koopjs20Apache-2.01.0.4

Socrata provider for Koop

csv, data, etl, feature-service, geojson, koop, open, open-data, opendata, provider, socrata

readme

koop-socrata

Socrata Provider for Koop

npm version build status

This provider makes it possible to access Socrata's JSON API as either GeoJSON or an Esri FeatureService. This is particularly useful for making maps and doing analysis on the web.

Install

To use this provider you first need a working installation of Koop. Then from within the koop directory you'll need to run the following:

npm install koop-socrata --save

Usage

koop-socrata needs to be registered as a provider in your Koop app in order to work.

var socrata = require('koop-socrata')
koop.register(socrata)

If you are using Postgres you will need to then create a database and enable Postgis

createdb koop
psql -d "koop" -c "create extension postgis;"

Once that's done you can restart your server and the Socrata routes will be available.

If you're using the koop-sample-app template, you can start the server like this:

node server.js

Registering Socrata Hosts

Once this provider's been installed you need to register a particular instance of Socrata with your Koop instance. To do this you make POST request to the /socrata endpoint like so:

curl --data "host=https://data.nola.gov&id=nola" localhost:1337/socrata

for Windows users, download cURL from http://curl.haxx.se/download.html or use a tool of your choice to generate the POST request

What you'll need for that request to work is an ID and the URL of the Socrata instance. The ID is what you'll use to reference datasets that come from Socrata in Koop.

To make sure this works you can visit: http://localhost:1337/socrata and you should see all of the registered hosts.

Add your app key

Socrata allows 1,000 requests per rolling hour period if you have an app key. If not, there is no guarantee of the number of queries you can make. It is strongly recommended to include an app token if you plan to run Koop-Socrata in production. See:

http://dev.socrata.com/docs/app-tokens.html

  1. Go to dev.socrata.com/register to create an app key
  2. Edit the default.json in your koop-app config to add
    {
    "socrata": {
     "token": "your-app-token"
    }
    }

Accessing Socrata Data

To access a dataset hosted in Socrata you'll need a "Resource ID" from Socrata. Datasets in Socrata can be accessed as raw JSON like this:

And then the ID fwm6-d78i can be referenced in Koop like so:

http://koop.dc.esri.com/socrata/nola/fwm6-d78i

If your Socrata data has more than one location column, you can specify the desired location column in the http request like this:

https://path_to_koop/socrata/socrataProvider/dataSetID!spatialColumn

Handling Large Datasets

Koop-Socrata will page through large datasets to gather all the rows. The default is set to 10,000 rows per request, but the Socrata API handles up to 50,000 requests very well. For production deployments it is recommended to set the Koop Configuration for the Socrata page limit to 50,000.

{
    "socrata": {
        "pageLimit": 50000
    }
}

Clearing Koop's cache for individual resources

If you find yourself in a situation where Koop isn't returning data for a particular resource and you'd like to make sure it makes a fresh request, you can blow out the cobwebs by making the following request in the browser.

http://[koop]/socrata/[provider]/[resourceID]/drop
>>> true

Examples

Here are a few examples of data hosted in Socrata and accessed via Koop.

Contributing

Esri welcomes contributions from anyone and everyone. Please see our guidelines for contributing.

License

Apache 2.0

changelog

Change Log

All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.

1.0.4 2016-04-03

Fixed

  • New hosts can be registered without manually creating a services table

1.0.3 - 2015-12-30

Changed

  • Replace '::' in fixture filenames

1.0.2 - 2015-12-29

Changed

  • bumped version of leaflet/esri leaflet used by preview
  • cleaned up views/demo.ejs
  • ensured log files created by passing tests have valid filenames and are ignored by git

Fixed

  • Fields are no longer erroneously cast to date

1.0.1 - 2015-07-29

Fixed

  • Cache expiration really works now

1.0.0 - 2015-07-28

Fixed

  • Alternate location fields are respected
  • Cache now expires correctly

0.4.1 - 2015-07-02

Fixed

  • Feature service count respects JSONP

0.4.0 - 2015-06-10

Added

  • Non-point spatial datasets are now supported

Changed

  • Refactored processing logic

0.3.4 - 2015-06-09

Fixed

  • Bug with failed stats requests to use a fallback request to the resource

0.3.3 - 2015-06-09

Fixed

  • No exception thrown when requesting a service that is processing
  • Can get resources that are filtered views of other resources
  • Not to send response after processing has been sent

0.3.2 - 2015-06-09

Fixed

  • Do not check for count on brand new services

0.3.1 - 2015-06-08

Added

  • 502 response contains error messages
  • New unit and integration tests + fixtures
  • Logging all errors and progress

Changed

  • Feature service counts occur without fetching features from the cache
  • Report 202 immediately when processing new dataset
  • JSON is processed in streams
  • All requests are made with gzip
  • Requests are made for table metadata, count and first row before paging
  • Default page limit is set to 10,000 can be controlled in Koop Config

Fixed

  • Cache expiration is checked every 24 hours
  • Duplicate data is no longer entered when making quick sequential requests for a new dataset

0.2.2 - 2015-05-28

Changed

  • Respecting resultOffset, resultOffsetCount, and limit/offset when querying featureservices

0.2.1 - 2015-05-08

Added

  • Allows provider to make requests using an app token, if available

0.2.0 - 2015-05-08

Changed

  • Implements a new paging style that uses an async request queue to control how many requests we make at once
  • Adds the concept of returning 202 response much like koop-agol when paging is in progress

0.1.2 - 2015-05-07

Changed

  • Changed the order in which object properties get flattened. Location objects were getting flattened too early in the process and cause location lookups to fail when building the geojson

0.1.1 - 2015-05-06

Added

  • Flattening all object based properties
  • ensuring that each feature contains each field

0.1.0 - 2015-04-21

Changed

  • This project now uses standard as its code formatting
  • Keeping a legit changelog
  • Added tape testing with sinon stubs in the controller tests