Skip to content

Commit

Permalink
moar buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
normanrz committed Aug 12, 2018
1 parent 5e58cf7 commit 927ff29
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ RUN yarn install

ENV TILE_SET_CACHE 128
ENV TILE_SET_PATH /app/data
ENV MAX_POST_SIZE 500kb
ENV MAX_POST_SIZE 700kb

CMD ["yarn", "run", "start"]
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Elevation service that works with the [Terrain data provided on Amazon AWS S3](h

Inspired by:

* https://github.com/perliedman/elevation-service
* https://github.com/perliedman/node-hgt
- https://github.com/perliedman/elevation-service
- https://github.com/perliedman/node-hgt

## API usage
The service has a very simple API. Just post your latitude-longitude pairs as a JSON array to the service and receive an array of elevations as response. Maximum post payload is by default 500 KB.

The service has a very simple API. Just post your latitude-longitude pairs as a JSON array to the service and receive an array of elevations as response. Maximum post payload is by default 700 KB (which fits roughly 10,000 points).

```bash
# > [[lat, lng], ...]
Expand All @@ -19,21 +20,25 @@ curl -d '[[51.3, 13.4], [51.4, 13.3]]' -XPOST -H 'Content-Type: application/json
## Usage with pre-downloaded data

Download data (ca. 200 GB):

```bash
aws s3 cp --recursive s3://elevation-tiles-prod/skadi /path/to/data/folder
```

Run the docker container:

```bash
docker run --rm -v/path/to/data/folder:/app/data -p3000:3000 normanrz/elevation-service
```

## Usage with S3-hosted data

Run the docker container:

```bash
docker run --rm -eTILE_SET_PATH=s3:// -p3000:3000 normanrz/elevation-service
```

## License
MIT

MIT
17 changes: 13 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const { json, send } = require("micro");
const limitedMap = require("limited-map");
const { FileTileSet, S3TileSet } = require("./tileset");

const cacheSize = process.env.TILE_SET_CACHE || 128;
const tileFolder = process.env.TILE_SET_PATH || __dirname;
const maxPostSize = process.env.MAX_POST_SIZE || "500kb";
const maxParallelProcessing = 500;

const tiles = tileFolder.startsWith("s3://")
? new S3TileSet({ cacheSize })
Expand All @@ -14,11 +16,18 @@ module.exports = async (req, res) => {
return send(res, 405, { error: "Only POST allowed" });
}

const geojson = await json(req, { limit: maxPostSize });
if (!geojson || Object.keys(geojson).length === 0) {
return send(res, 400, { error: "Invalid GeoJSON" });
const payload = await json(req, { limit: maxPostSize });
if (!payload || Object.keys(payload).length === 0) {
return send(res, 400, {
error:
"Invalid Payload. Expected a JSON array with latitude-longitude pairs: [[lat, lng], ...]"
});
}

const result = await Promise.all(geojson.map(ll => tiles.getElevation(ll)));
const result = await limitedMap(
payload,
ll => tiles.getElevation(ll),
maxParallelProcessing
);
return result;
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"author": "Norman Rzepka <[email protected]>",
"license": "MIT",
"dependencies": {
"limited-map": "^0.0.1",
"lru-memoize": "^1.0.2",
"micro": "^9.3.2"
},
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ [email protected]:
version "1.1.0"
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"

limited-map@^0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/limited-map/-/limited-map-0.0.1.tgz#78a24fd73b0fb58312f7d639ca572b1bfd3f0bf0"

lru-memoize@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/lru-memoize/-/lru-memoize-1.0.2.tgz#f5ae84d288e7d55fec8388ec0bd725621bc815d0"
Expand Down

0 comments on commit 927ff29

Please sign in to comment.