0.4.7 • Published 17 days ago

@sentinel-hub/sentinelhub-js v0.4.7

Weekly downloads
489
License
-
Repository
-
Last release
17 days ago

Warning

The interface of the library is not final yet - expect breaking changes!

Installation

$ npm install @sentinel-hub/sentinelhub-js

Usage

The core data structure is Layer, which corresponds to a layer as returned by OGC WMS GetCapabilities request. If the URL matches one of the Sentinel Hub service URLs, additional capabilities are unlocked.

Basic (WMS-capable) Layer can be initialized like this:

  import { WmsLayer } from 'sentinelhub-js';

  const layer = new WmsLayer('https://services.sentinel-hub.com/ogc/wms/<your-instance-id>', '<layer-id>', 'Title', 'Description');

Such layer would only allow WMS requests. However, Layer is also a superclass for multiple dataset-specific subclasses (like S1GRDIWAWSLayer) which can be instantiated with their own specific parameters and thus unlock additional powers.

When it comes to Sentinel Hub layers, there are four ways to determine their content:

  • by layerId: ID of the layer, as used by OGC WMS and SentinelHub Configurator
  • by evalscript: custom (javascript) code that will be executed by the service per each pixel and will calculate the (usually RGB/RGBA) values
  • by evalscriptUrl: the URL from which the evalscript can be downloaded from
  • by dataProduct: the structure which contains an ID of a pre-existing product
  import { S1GRDIWAWSLayer } from 'sentinelhub-js';

  layerS1 = new S1GRDIWAWSLayer(instanceId, '<layer-id>', null, null, null, 'Title', 'Description');
  layerS1 = new S1GRDIWAWSLayer(instanceId, null, myEvalscript);
  layerS1 = new S1GRDIWAWSLayer(instanceId, null, null, myEvalscriptUrl);
  layerS1 = new S1GRDIWAWSLayer(instanceId, null, null, null, '<data-product-id>');
  layerS1 = new S1GRDIWAWSLayer(instanceId, '<layer-id>', null, null, null, 'Title', 'Description', orthorectified=true);

It is also possible to get the list of the layers that service endpoint supports:

  import { LayersFactory } from 'sentinelhub-js';

  const layers = LayersFactory.getLayers('https://services.sentinel-hub.com/ogc/wms/<your-instance-id>');
    // [ layer1, layer2, ... ] - a list of Layer objects

  const layersIds = layers.map(l => l.layerId);
    // [ '<layer-id-1>', '<layer-id-2>',... ]

Depending on baseUrl, method getLayers() tries to determine if a specific Layer subclass would be better suited and instantiates it with all applicable parameters.

Alternatively, the list can be filtered to include only some of the layers:

  // this will return only a list of layers whose IDs start with "ABC_":
  const layers = LayersFactory.getLayers(
    'https://services.sentinel-hub.com/ogc/wms/<your-instance-id>',
    (layerId, datasetId) => layerId.startsWith("ABC_"),
  );

It is also possible to get min and max date as defined on the dataset:

  const minDate = layer.getDatasetMinDate();
  const maxDate = layer.getDatasetMaxDate();

Some information about the layer is only accessible to authenticated users. In case of Playground and EO Browser, ReCaptcha auth token is sufficient to fetch layer information (such as evalscript / dataProduct). To avoid updating every layer when auth token changes, we have a global function for updating it:

  import { isAuthTokenSet, setAuthToken } from 'sentinelhub-js';

  const before = isAuthTokenSet(); // false
  setAuthToken(newAuthToken);
  const after = isAuthTokenSet(); // true

Fetching images

Maps which correspond to these layers can be fetched via different protocols like WMS and Processing. Not all of the protocols can be used in all cases; for example, Processing can only render layers for which it has access to the evalscript and for which evalscript version 3 is used.

  import { BBox, CRS_EPSG4326, MimeTypes, ApiType } from 'sentinelhub-js';

  const bbox = new BBox(CRS_EPSG4326, 18, 20, 20, 22);
  const getMapParams = {
    bbox: bbox,
    from: new Date(Date.UTC(2018, 11 - 1, 22, 0, 0, 0)),
    to: new Date(Date.UTC(2018, 12 - 1, 22, 23, 59, 59)),
    width: 512,
    height: 512,
    format: MimeTypes.JPEG,
  };

  const imageBlob = await layer.getMap(getMapParams, ApiType.WMS);
  const imageBlob2 = await layer.getMap(getMapParams, ApiType.PROCESSING);

Note that in theory both images should be exactly the same. If there are any (minor) differences, they are a consequence of how service processes requests, not because of different interpretation of getMapParams on the side of this library.

In some cases we can retrieve just the image URL instead of a blob:

  const imageUrl = await layer.getMapUrl(getMapParams, ApiType.WMS);
  const imageUrl2 = await layer.getMapUrl(getMapParams, ApiType.PROCESSING); // exception thrown - Processing API does not support HTTP GET method

Searching for data

Searching for the data is a domain either of a layer or its dataset (if available). This library supports different services, some of which (ProbaV and GIBS for example) specify availability dates per layer and not dataset.

We can always use layer to search for data availability:

  const searchParams: DatasetSpecificSearchParams = {
    cloudCoveragePercent: 50,
  }
  const dates = layer.findDatesUTC(bbox, fromDate, toDate, searchParams);
  const flyovers = layer.findFlyovers(bbox, fromDate, toDate, searchParams);
  const tiles = layer.findTiles(bbox, fromDate, toDate, searchParams);

Backwards compatibility

To make it easier to use this library with legacy code, there are two functions that are implemented on top of the library:

  const imageBlob1 = await legacyGetMapFromParams(rootUrl, wmsParams);
  const imageBlob2 = await legacyGetMapFromParams(rootUrl, wmsParams, ApiType.PROCESSING); // ApiType.WMS is default

If we already have a WMS GetMap URL, we can use it directly:

  const imageBlob3 = await legacyGetMapFromUrl(fullUrlWithWmsQueryString);
  const imageBlob4 = await legacyGetMapFromUrl(fullUrlWithWmsQueryString, ApiType.PROCESSING);

Example

$ npm run build
$ cd example/node
$ node index.js
0.4.8-rc2

17 days ago

0.4.8-rc1

18 days ago

0.4.7

2 months ago

0.4.7-rc1

2 months ago

0.4.6

3 months ago

0.4.6-rc1

3 months ago

0.4.5

3 months ago

0.4.5-rc3

3 months ago

0.4.5-rc2

3 months ago

0.4.5-rc1

3 months ago

0.4.4

3 months ago

0.4.4-rc2

3 months ago

0.4.4-rc1

3 months ago

0.4.3

3 months ago

0.4.2

5 months ago

0.4.1-rc5

5 months ago

0.4.1-rc4

5 months ago

0.4.1-rc3

5 months ago

0.3.5-rc3

10 months ago

0.3.5-rc2

10 months ago

0.3.5-rc1

10 months ago

0.4.1-rc2

5 months ago

0.4.1-rc1

5 months ago

0.3.9-rc2

7 months ago

0.3.9-rc1

8 months ago

0.3.1-rc3

10 months ago

0.3.1-rc2

10 months ago

0.3.1-rc1

10 months ago

0.3.5

10 months ago

0.3.8

9 months ago

0.3.7

9 months ago

0.3.1

10 months ago

0.3.2-rc2

10 months ago

0.3.2-rc1

10 months ago

0.3.7-rc1

10 months ago

0.4.0

6 months ago

0.2.98-rc2

10 months ago

0.2.98-rc3

10 months ago

0.3.6-rc2

10 months ago

0.3.6-rc1

10 months ago

0.4.0-rc1

7 months ago

0.3.9

8 months ago

0.2.97-rc1

11 months ago

0.2.96

11 months ago

0.2.95

12 months ago

0.2.94

12 months ago

0.2.93

12 months ago

0.2.92

12 months ago

0.2.97

11 months ago

0.2.96-rc.1

11 months ago

0.3.0

10 months ago

0.2.98-rc1

11 months ago

0.2.93-rc.1

12 months ago

0.2.91

1 year ago

0.2.90

1 year ago

0.2.89

1 year ago

0.2.89-rc.1

1 year ago

0.2.92-rc.3

1 year ago

0.2.92-rc.2

1 year ago

0.2.92-rc.1

1 year ago

0.2.91-rc.1

1 year ago

0.2.91-rc.2

1 year ago

0.2.88

1 year ago

0.2.88-rc.1

1 year ago

0.2.85

1 year ago

0.2.87

1 year ago

0.2.86

1 year ago

0.2.87-rc1

1 year ago

0.2.85-rc1

1 year ago

0.2.86-rc4

1 year ago

0.2.86-rc2

1 year ago

0.2.86-rc3

1 year ago

0.2.86-rc1

1 year ago

0.2.82-rc1

2 years ago

0.2.84

1 year ago

0.2.83

2 years ago

0.2.82

2 years ago

0.2.81

2 years ago

0.2.79

2 years ago

0.2.81-rc2

2 years ago

0.2.81-rc1

2 years ago

0.2.84-rc1

1 year ago

0.2.80-rc2

2 years ago

0.2.80-rc1

2 years ago

0.2.83-rc2

2 years ago

0.2.83-rc1

2 years ago

0.2.78

2 years ago

0.2.79-rc1

2 years ago

0.2.78-rc1

2 years ago

0.2.77

2 years ago

0.2.77-rc.3

2 years ago

0.2.77-rc.2

2 years ago

0.2.76-rc.3

2 years ago

0.2.76

2 years ago

0.2.77-rc.1

2 years ago

0.2.76-rc.1

2 years ago

0.2.76-rc.2

2 years ago

0.2.74

2 years ago

0.2.75

2 years ago

0.2.75-rc.1

2 years ago

0.2.74-rc.5

2 years ago

0.2.74-rc.3

2 years ago

0.2.74-rc.4

2 years ago

0.2.74-rc.2

2 years ago

0.2.74-rc.1

2 years ago

0.2.73

2 years ago

0.2.72

2 years ago

0.2.73-rc.1

2 years ago

0.2.70-rc.2

2 years ago

0.2.70-rc.1

2 years ago

0.2.70-rc.3

2 years ago

0.2.71

2 years ago

0.2.70

2 years ago

0.2.71-rc.4

2 years ago

0.2.71-rc.5

2 years ago

0.2.71-rc.6

2 years ago

0.2.71-rc.1

2 years ago

0.2.71-rc.2

2 years ago

0.2.71-rc.3

2 years ago

0.2.69-rc.1

2 years ago

0.2.69-rc.2

2 years ago

0.2.69-rc.3

2 years ago

0.2.69-rc.4

2 years ago

0.2.69

2 years ago

0.2.66-rc.2

2 years ago

0.2.68-rc.1

2 years ago

0.2.68-rc.3

2 years ago

0.2.68-rc.2

2 years ago

0.2.68

2 years ago

0.2.67

2 years ago

0.2.66

2 years ago

0.2.67-rc.8

2 years ago

0.2.67-rc.7

2 years ago

0.2.67-rc.9

2 years ago

0.2.67-rc.4

2 years ago

0.2.67-rc.3

2 years ago

0.2.67-rc.6

2 years ago

0.2.67-rc.5

2 years ago

0.2.67-rc.2

2 years ago

0.2.67-rc.1

2 years ago

0.2.66-rc.1

2 years ago

0.2.65

3 years ago

0.2.65-rc.1

3 years ago

0.2.64

3 years ago

0.2.63

3 years ago

0.2.63-rc.2

3 years ago

0.2.63-rc.3

3 years ago

0.2.63-rc.1

3 years ago

0.2.62

3 years ago

0.2.62-rc.3

3 years ago

0.2.62-rc.2

3 years ago

0.2.61-rc.6

3 years ago

0.2.62-rc.1

3 years ago

0.2.61

3 years ago

0.2.61-rc.5

3 years ago

0.2.61-rc.4

3 years ago

0.2.61-rc.3

3 years ago

0.2.61-rc.2

3 years ago

0.2.61-rc.1

3 years ago

0.2.60

3 years ago

0.2.59

3 years ago

0.2.58-rc.2

3 years ago

0.2.59-rc.1

3 years ago

0.2.58

3 years ago

0.2.58-rc.1

3 years ago

0.2.57

3 years ago

0.2.57-rc.6

3 years ago

0.2.57-rc.3

3 years ago

0.2.57-rc.4

3 years ago

0.2.57-rc.5

3 years ago

0.2.57-rc.1

3 years ago

0.2.57-rc.2

3 years ago

0.2.56

3 years ago

0.2.56-rc.3

3 years ago

0.2.56-rc.2

3 years ago

0.2.56-rc.1

3 years ago

0.2.55

3 years ago

0.2.55-rc.2

3 years ago

0.2.55-rc.1

3 years ago

0.2.54

3 years ago

0.2.54-rc.1

3 years ago

0.2.53

3 years ago

0.2.53-rc.8

3 years ago

0.2.53-rc.7

3 years ago

0.2.53-rc.6

3 years ago

0.2.53-rc.5

3 years ago

0.2.53-rc.4

3 years ago

0.2.53-rc.3

3 years ago

0.2.53-rc.2

3 years ago

0.2.53-rc.1

3 years ago

0.2.52

3 years ago

0.2.52-rc.2

3 years ago

0.2.52-rc.1

3 years ago

0.2.51

3 years ago

0.2.51-rc.7

3 years ago

0.2.51-rc.6

3 years ago

0.2.51-rc.5

3 years ago

0.2.51-rc.4

3 years ago

0.2.51-rc.3

3 years ago

0.2.51-rc.2

3 years ago

0.2.51-rc.1

3 years ago

0.2.50-rc.1

3 years ago

0.2.50

3 years ago

0.2.49

3 years ago

0.2.49-rc.2

3 years ago

0.2.49-rc.3

3 years ago

0.2.49-rc.1

3 years ago

0.2.48

3 years ago

0.2.47

3 years ago

0.2.47-rc.3

3 years ago

0.2.47-rc.4

3 years ago

0.2.47-rc.2

3 years ago

0.2.46

3 years ago

0.2.46-rc.4

3 years ago

0.2.46-rc.3

3 years ago

0.2.46-rc.2

3 years ago

0.2.46-rc.1

3 years ago

0.2.45

3 years ago

0.2.45-rc.2

3 years ago

0.2.44

3 years ago

0.2.43

3 years ago

0.2.43-rc.1

3 years ago

0.2.42

3 years ago

0.2.42-rc.2

3 years ago

0.2.42-rc.1

3 years ago

0.2.41

3 years ago

0.2.41-rc.2

3 years ago

0.2.41-rc.1

3 years ago

0.2.40

3 years ago

0.2.39

3 years ago

0.2.39-rc.1

3 years ago

0.2.38

3 years ago

0.2.38-rc.1

3 years ago

0.2.37-rc.2

3 years ago

0.2.37-rc.3

3 years ago

0.2.37

3 years ago

0.2.37-rc.1

3 years ago

0.2.36

3 years ago

0.2.36-rc.1

3 years ago

0.2.35

4 years ago

0.2.34

4 years ago

0.2.34-rc.1

4 years ago

0.2.33

4 years ago

0.2.32

4 years ago

0.2.32-rc.3

4 years ago

0.2.32-rc.2

4 years ago

0.2.32-rc.1

4 years ago

0.2.31

4 years ago

0.2.31-rc.3

4 years ago

0.2.31-rc.2

4 years ago

0.2.31-rc.1

4 years ago

0.2.30

4 years ago

0.2.30-rc.6

4 years ago

0.2.30-rc.5

4 years ago

0.2.30-rc.2

4 years ago

0.2.30-rc.3

4 years ago

0.2.30-rc.4

4 years ago

0.2.30-rc.1

4 years ago

0.2.29

4 years ago

0.2.29-rc.4

4 years ago

0.2.29-rc.3

4 years ago

0.2.29-rc.2

4 years ago

0.2.29-rc.1

4 years ago

0.2.28

4 years ago

0.2.28-rc.4

4 years ago

0.2.28-rc.5

4 years ago

0.2.28-rc.3

4 years ago

0.2.28-rc.2

4 years ago

0.2.28-rc.1

4 years ago

0.2.27

4 years ago

0.2.27-rc.1

4 years ago

0.2.26

4 years ago

0.2.26-rc.8

4 years ago

0.2.26-rc.7

4 years ago

0.2.26-rc.6

4 years ago

0.2.26-rc.5

4 years ago

0.2.26-rc.4

4 years ago

0.2.26-rc.3

4 years ago

0.2.26-rc.2

4 years ago

0.2.26-rc.1

4 years ago

0.2.25-rc.3

4 years ago

0.2.25-rc.2

4 years ago

0.2.24

4 years ago

0.2.23

4 years ago

0.2.23-rc.1

4 years ago

0.2.23-rc.2

4 years ago

0.2.22

4 years ago

0.2.22-rc.1

4 years ago

0.2.21

4 years ago

0.2.21-rc.1

4 years ago

0.2.20

4 years ago

0.2.20-rc.4

4 years ago

0.2.20-rc.2

4 years ago

0.2.20-rc.3

4 years ago

0.2.20-rc.1

4 years ago

0.2.19

4 years ago

0.2.19-rc.1

4 years ago

0.2.18

4 years ago

0.2.17

4 years ago

0.2.16

4 years ago

0.2.17-rc.1

4 years ago

0.2.17-rc.2

4 years ago

0.2.16-rc.1

4 years ago

0.2.15

4 years ago

0.2.15-rc.1

4 years ago

0.2.14

4 years ago

0.2.13

4 years ago

0.2.12

4 years ago

0.2.12-rc.1

4 years ago

0.2.11

4 years ago

0.2.10

4 years ago

0.2.10-rc.5

4 years ago

0.2.10-rc.4

4 years ago

0.2.10-rc.3

4 years ago

0.2.10-rc.2

4 years ago

0.2.10-rc.1

4 years ago

0.2.9-rc.5

4 years ago

0.2.9

4 years ago

0.2.9-rc.4

4 years ago

0.2.9-rc.2

4 years ago

0.2.9-rc.3

4 years ago

0.2.9-rc.1

4 years ago

0.2.8

4 years ago

0.2.8-rc.2

4 years ago

0.2.8-rc.3

4 years ago

0.2.8-rc.1

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.6-rc.2

4 years ago

0.2.6-rc.1

4 years ago

0.2.5

4 years ago

0.2.5-rc.3

4 years ago

0.2.5-rc.2

4 years ago

0.2.5-rc.1

4 years ago

0.2.4

4 years ago

0.2.4-rc.1

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.1-rc.1

4 years ago

0.2.0-rc.1

4 years ago

0.2.0

4 years ago

0.1.2-rc.20

4 years ago

0.1.2-rc.19

4 years ago

0.1.2-rc.18

4 years ago

0.1.2-rc.17

4 years ago

0.1.2-rc.16

4 years ago

0.1.2-rc.15

4 years ago

0.1.2-rc.14

4 years ago

0.1.2-rc.13

4 years ago

0.1.2-rc.12

4 years ago

0.1.2-rc.11

4 years ago

0.1.2-rc.10

4 years ago

0.1.2-rc.9

4 years ago

0.1.2-rc.8

4 years ago

0.1.2-rc.7

4 years ago

0.1.2-rc.6

4 years ago

0.1.2-rc.4

4 years ago

0.1.2-rc.3

4 years ago

0.1.2-rc.1

4 years ago

0.1.1

4 years ago

0.1.1-rc.2

4 years ago

0.1.1-rc.1

4 years ago

0.1.0

4 years ago

0.0.24-rc.2

4 years ago

0.0.23

4 years ago

0.0.1-rc.7

4 years ago

0.0.1-rc.6

4 years ago

0.0.1-rc.5

4 years ago

0.0.24-rc.1

4 years ago

0.0.23-rc.4

4 years ago

0.0.23-rc.3

4 years ago

0.0.23-rc.2

4 years ago

0.0.22

4 years ago

0.0.23-rc.1

4 years ago

0.0.22-rc.1

4 years ago