Skip to content

Instantly share code, notes, and snippets.

@connormanning
Last active April 6, 2018 12:41
Show Gist options
  • Save connormanning/2b72aa3bab69f7105c6fc4e32935aeca to your computer and use it in GitHub Desktop.
Save connormanning/2b72aa3bab69f7105c6fc4e32935aeca to your computer and use it in GitHub Desktop.
PDAL GreyhoundWriter Javascript example

Scripting writers.greyhound

These instructions assume that node.js is installed installed natively. PDAL/Entwine/Greyhound pieces are done via Docker.

Index Autzen with Entwine

Assuming ~/entwine is the storage location for Entwine-indexed data:

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

Start Greyhound with /write permissions

Create ~/entwine/config.json with contents: { "allowWrite": true }.

Launch Greyhound:

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

Run buffered/tiled ground algorithm with Node.js

This example runner simply builds 36 pipelines that split the dataset into a 6x6 grid with a 20% overlapping buffer on each tile, and shells out PDAL's docker container to run each segment serially. It's a proof of concept only and not meant to be scaled to anything production-worthy.

This pipeline runs the SMRF algorithm as well as assigning incrementing values to the BufferedTile dimension for each tile of the 6x6 grid using PDAL's assign filter.

Install dependencies:

npm install lodash request-promise

Run:

node ground.js

Look at results

Ground visualization

Tiling visualization

var _ = require('lodash');
var request = require('request-promise');
var exec = require('child_process').execSync;
var fs = require('fs');
var read = { "type": "readers.greyhound", "url": null, "buffer": 0.2 };
var ground = { "type": "filters.smrf" };
var ferry = { "type": "filters.ferry", "dimensions":
"Classification=BufferedSmrf, Classification=BufferedTile" };
var assign = { "type": "filters.assign", "assignment": null };
var write = { "type": "writers.greyhound", "name": "ConnorBufferedSmrf", "dims":
["BufferedSmrf", "BufferedTile"] };
var base = 'http://localhost:8080/resource/autzen/';
var steps = 6;
request({ uri: base + 'info', json: true })
.then((info) => {
var minx = info.bounds[0];
var miny = info.bounds[1];
var maxx = info.bounds[3];
var maxy = info.bounds[4];
var width = maxx - minx;
var depth = maxy - miny;
var t = 0;
for (var i = 0; i < steps; ++i) {
for (var j = 0; j < steps; ++j) {
var bounds = [
minx + (width / steps) * i,
miny + (depth / steps) * j,
minx + (width / steps) * (i + 1),
miny + (depth / steps) * (j + 1)
];
var pipeline = [
_.merge(read, {
url: base + 'read?bounds=' + JSON.stringify(bounds)
}),
ground,
ferry,
_.merge(assign, { assignment: 'BufferedTile[:]=' + t }),
write
]
var f = t + '.json';
console.log(f);
console.log(pipeline);
fs.writeFileSync(f, JSON.stringify({ pipeline: pipeline }));
console.log(exec('pdal pipeline ' + f, {
encoding: 'utf8'
}));
++t;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment