Skip to content

Instantly share code, notes, and snippets.

@connormanning
Created March 8, 2018 19:20
Show Gist options
  • Save connormanning/838f03525d59703f6baed2fdc7589645 to your computer and use it in GitHub Desktop.
Save connormanning/838f03525d59703f6baed2fdc7589645 to your computer and use it in GitHub Desktop.
Sample addon dimensions

Assuming ~/data will be the greyhound data directory.

Index data:

docker run -it -v ~/data:/opt/data connormanning/entwine build \
    -i https://entwine.io/sample-data/red-rocks.laz \
    -o /opt/data/red-rocks

Create ~/data/config.json to allow the /write greyhound endpoint:

{ "allowWrite": true }

Run greyhound:

docker run -it -v ~/data:/opt/data -p 8080:8080 connormanning greyhound \
    -c /opt/data/config.json

Create file write.js:

var request = require('request-promise');
var base = 'http://localhost:8080/resource/red-rocks/';
var query = null;

request({ uri: base + 'info' , json: true })
.then((info) => {
    // Get lower quadrant in 2D.
    var b = info.bounds;
    b = [b[0], b[1], b[3], b[4]];
    b = [b[0], b[1], b[0] + (b[2] - b[0]) / 2, b[1] + (b[3] - b[1]) / 2];

    query = '?bounds=' + JSON.stringify(b);
    console.log(query);
    return request({ url: base + 'read' + query, encoding: null });
})
.then((data) => {
    var points = data.readUInt32LE(data.length - 4);
    var buffer = Buffer.alloc(points, 42);
    var schema = [{ name: 'MyDim', type: 'unsigned', size: 1 }];
    console.log('Points:', points);

    var url = base + 'write' + query +
        '&schema=' + JSON.stringify(schema) +
        '&name="MyDataset"';

    console.log('Write URL:', url);
    return request({ url: url, method: 'PUT', encoding: null, body: buffer });
})
.then(() => console.log('Done'))
.catch((err) => console.log('Caught:', err));

Install the HTTP request dependency and run the script, which queries the southeast quadrant and then writes a new dimension MyDim with values set to 42 for that quadrant:

npm install request-promise
node write.js

Color by this new dimension in speck.ly here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment