Giter VIP home page Giter VIP logo

sampleterrain's Introduction

sampleterrain - Update coordinates of a GeoJSON file from node.js with sampled elevation data from a Cesium Terrain Provider

When you work with Cesium, often times you need to incorporate elevation data in your geo features so that they are properly positioned relative to the ground when using terrain visualization. You can do it in the browser by invoking the Cesium.sampleTerrain function, but if your features have tons of coordinates, it will be very slow. Many times it will be much better to preprocess the data off-line to include elevation information.

This small library allows you to do that from a node.js application.

Performance note: For large files, it is better to explicitly specify level of detail as the default 'sampleTerrainMostDetailed' can be very slow.

Install

npm install sampleterrain

Use as library

var sampleterrain = require('sampleterrain');

sampleterrain.sample(data, fOptions).then((result) => {
  console.log(JSON.stringify(result));
}).catch(e => {
  console.warn('Sample terrain error', e);
});

Where:
  data - GeoJSON object
  fOptions - {level: level, terrainProviderUrl: url}
              level - The terrain level-of-detail from which to sample terrain heights (defaults to maximum detail)
              url - The url of the terrain provider (default to the Cesium Ion world terrain provider)
              token - The Cesium Ion access token (required if accessing Cesium Ion's world terrain provider)
  result - Updated GeoJSON object

Use from the command line

Usage:
  sampleterrain.js [OPTIONS] [ARGS]

Options:
  -f, --file FILE        GeoJson File
  -l, --level NUMBER     Terrain level of detail
  -u, --url URL          Terrain provider url
  -t, --token STRING     Cesium Ion access token  
  -h, --help             Display help and usage details

Note: As an alternative to the --token option, set the CESIUM_ION_TOKEN environment variable

Example

node sampleterrain.js -f ./sampledata/test1.json -t 'your Cesium Ion token'  > sampled.json

Running the test suite

Running the test suite (npm run test) requires the CESIUM_ION_TOKEN environment variable to be set with a valid access token.

sampleterrain's People

Contributors

baloola avatar dependabot[bot] avatar jimmyangel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sampleterrain's Issues

Get request error when running example command

Hi @jimmyangel,

When I was running the example command node sampleterrain.js -f ./sampledata/test1.json > sampled.json, I got the following error:

Sample terrain error RequestErrorEvent {
  statusCode: 401,
  response: IncomingMessage {
    _readableState: ReadableState {
      objectMode: false,
      highWaterMark: 16384,
      buffer: BufferList { head: [Object], tail: [Object], length: 1 },
      length: 62,
      pipes: null,
      pipesCount: 0,
      flowing: null,
      ended: true,
      endEmitted: false,
      reading: false,
      sync: true,
      needReadable: false,
      emittedReadable: false,
      readableListening: false,
      resumeScheduled: false,
      emitClose: true,
      autoDestroy: false,
      destroyed: false,
      defaultEncoding: 'utf8',
      awaitDrainWriters: null,
      multiAwaitDrain: false,
      readingMore: true,
      decoder: null,
      encoding: null,
      [Symbol(kPaused)]: null
    },
......
}

How can I fix it? Thanks a lot

Oliver

Height value is undefined

Hi @jimmyangel,

I got the following error:

node sampleterrain.js -f data.json -t 'my Cesium Ion token'  > sampled.json

Sample terrain error TypeError: Cannot read property 'toFixed' of undefined
    at /home/geostud/oliverProjects/sampleterrain-master/lib/index.js:39:119
    at Array.forEach (<anonymous>)
    at /home/geostud/oliverProjects/sampleterrain-master/lib/index.js:37:19
    at Promise$1.then (/home/geostud/oliverProjects/sampleterrain-master/node_modules/cesium/Build/CesiumUnminified/Cesium.js:12630:36)
    at /home/geostud/oliverProjects/sampleterrain-master/node_modules/cesium/Build/CesiumUnminified/Cesium.js:12731:15
    at processQueue (/home/geostud/oliverProjects/sampleterrain-master/node_modules/cesium/Build/CesiumUnminified/Cesium.js:13081:6)
    at _resolve (/home/geostud/oliverProjects/sampleterrain-master/node_modules/cesium/Build/CesiumUnminified/Cesium.js:12767:6)
    at promiseResolve (/home/geostud/oliverProjects/sampleterrain-master/node_modules/cesium/Build/CesiumUnminified/Cesium.js:12793:13)
    at Promise$1.then (/home/geostud/oliverProjects/sampleterrain-master/node_modules/cesium/Build/CesiumUnminified/Cesium.js:12630:36)
    at /home/geostud/oliverProjects/sampleterrain-master/node_modules/cesium/Build/CesiumUnminified/Cesium.js:12731:15

This is because the some height values are undefined.

If I take a smaller data.json as input, the code can be executed successfully and smoothly. Hence, I guess this might be relative to my data size? Cesium.sampleTerrain can not process such an amount of data at the same time?

Oliver

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.