2.2.2 • Published 7 years ago

cardboard v2.2.2

Weekly downloads
8
License
ISC
Repository
github
Last release
7 years ago

cardboard

Build Status Coverage Status

Cardboard is a JavaScript library for managing the storage of GeoJSON features on an AWS backend. It relies on DynamoDB for indexing and small-feature storage, and S3 for large-feature storage. Cardboard provides functions to create, read, update, and delete single features or in batch, as well as simple bounding-box spatial query capabilities.

Installation

npm install cardboard
# or globally
npm install -g cardboard

Configuration

Generate a client by passing the following configuration options to cardboard:

optionrequireddescription
tableXthe name of the DynamoDB table to use
regionXthe region containing the given DynamoDB table
bucketXthe name of an S3 bucket to use for large-object storage
prefixXa folder prefix to use within the S3 bucket
accessKeyIdAWS credentials
secretAccessKeyAWS credentials
sessionTokenAWS credentials
dynoa pre-configured dyno client to use for DynamoDB interactions
s3a pre-configured s3 client to use for S3 interactions

Providing AWS credentials is optional. Cardboard depends on the AWS SDK for JavaScript, and so credentials can be provided in any way supported by that library. See configuring the SDK in Node.js for more configuration options.

If you provide a preconfigured dyno client, you do not need to specify table and region when initializing cardboard.

Example

var Cardboard = require('cardboard');
var cardboard = Cardboard({
    table: 'my-cardboard-table',
    region: 'us-east-1',
    bucket: 'my-cardboard-bucket',
    prefix: 'test'
});

Creating a Cardboard table

Once you've initialized the client, you can use it to create a table for you:

cardboard.createTable(callback);

You don't have to create the table each time; you can provide the name of a pre-existing table to your configuration options to use that table.

API documentation

See api.md.

Concepts

Datasets

Most cardboard functions require you to specify a dataset. This is a way of grouping sets of features within a single Cardboard table. It is similar in concept to "layers" in many other GIS systems, but there are no restrictions on the types of features that can be associated with each other in a single dataset. Each feature managed by cardboard can only belong to one dataset.

Identifiers

Features within a single dataset must each have a unique id. Cardboard uses a GeoJSON feature's top-level id property to determine and persist the feature's identifier. If you provide a cardboard function with a GeoJSON feature that does not have an id property, it will assign one for you, otherwise, it will use the id that you provide. Be aware that inserting two features to a single dataset with the same id value will result in only the last feature being persisted in cardboard.

Collections

Whenever dealing with individual GeoJSON features, cardboard will expect or return a GeoJSON object of type Feature. In batch situations, or in any request that returns multiple features, cardboard will expect/return a FeatureCollection.

Pagination

As datasets become large, retrieving all the features they contain can become a prohibitively expensive / slow operation. Functions in cardboard that may return large numbers of features allow you to provide pagination options, allowing you to gather all the features in a single dataset through a series of consecutive requests.

Pagination options are an object with two properties:

optiontypedescription
maxFeaturesnumberinstructs cardboard to provide no more than this many features in a single .list() request
startstringoptional instructs cardboard to begin providing results after the specified key.

Cardboard will attempt to return maxFeatures number of results per paginated request. However, if the individual features in the dataset are very large, or you've specifed maxFeatures very high, cardboard may return fewer results. It will never return more than this number of features.

Once you've received a set of results, find the id of the last feature in the FeatureCollection, i.e.

var lastId = featureCollection.features.pop().id;

By using this as the start option for the next request, cardboard will provide you with the next set of results.

You have received all the features when the request returns a FeatureCollection with no features in it.

Example: paginated cardboard.list()

var Cardboard = require('cardboard');
var cardboard = Cardboard({
    table: 'my-cardboard-table',
    region: 'us-east-1',
    bucket: 'my-cardboard-bucket',
    prefix: 'test'
});

var features = [];
getFeatures();

function getFeatures(start) {
    var options = { maxFeatures: 10 };
    if (start) options.start = start;

    cardboard.list('my-dataset', options, function(err, featureCollection) {
        if (err) throw err;
        if (!featureCollection.features.length) return;

        features = features.concat(featureCollection.features);

        var lastId = featureCollection.features.pop().id;
        getFeatures(lastId);
    });
}

Metadata

Metadata can be stored pertaining to each dataset in the cardboard table:

propertydescription
westwest-bound of dataset's extent
southsouth-bound of dataset's extent
easteast-bound of dataset's extent
northnorth-bound of dataset's extent
countnumber of features in the dataset
sizeapproximate size (in bytes) of the entire dataset
updatedunix timestamp of the last update to this metadata record,
minzoomsuggested minimum zoom for this dataset
maxzoomsuggested maximum zoom for this dataset

Use the cardboard.getDatasetInfo function to retrieve a dataset's metadata. By default, dataset metadata is not updated incrementally as features are added, updated, or removed. The metadata record can be updated by calling cardboard.calculateDatasetInfo. This operation gathers all the features in the dataset and recalculates the metadata cache.

cardboard.metadata.addFeature, cardboard.metadata.updateFeature, and cardboard.metadata.removeFeature provide mechanisms to incrementally adjust metadata information on a per-feature basis. Note that these operations will only expand the extent information. If you've performed numerous deletes and need to contract the extent, use cardboard.calculateDatasetInfo.

Precision

Cardboard retains the precision of a feature's coordinates to six decimal places.

2.2.2

7 years ago

2.2.1

7 years ago

3.0.0

7 years ago

2.2.0

8 years ago

2.1.1

8 years ago

2.1.0

8 years ago

2.0.0

8 years ago

1.6.4

8 years ago

1.6.3

8 years ago

1.6.2

8 years ago

1.6.1

8 years ago

1.6.0

8 years ago

1.5.0

8 years ago

1.4.0

8 years ago

1.3.1

8 years ago

1.3.0

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.14.2

9 years ago

0.14.1

9 years ago

0.14.0

9 years ago

0.13.1

9 years ago

0.13.0

9 years ago

0.12.0

9 years ago

0.11.1

9 years ago

0.11.0

9 years ago

0.10.0

9 years ago

0.9.12

9 years ago

0.9.11

9 years ago

0.9.10

9 years ago

0.9.9

9 years ago

0.9.8

9 years ago

0.9.7

9 years ago

0.9.6

9 years ago

0.9.5

9 years ago

0.9.4

9 years ago

0.9.3

9 years ago

0.9.2

9 years ago

0.9.1

10 years ago

0.9.0

10 years ago

0.8.0

10 years ago

0.7.3

10 years ago

0.7.2

10 years ago

0.7.1

10 years ago

0.7.0

10 years ago

0.6.3

10 years ago

0.6.2

10 years ago

0.6.1

10 years ago

0.6.0

10 years ago

0.5.0

10 years ago

0.4.4

10 years ago

0.4.3

10 years ago

0.4.2

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.4

10 years ago

0.3.3

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago