UNPKG

@ciag/sentinel-hub-wms

Version:

a API to create the sentinel ogs requests, and tools to apply on the data

100 lines 5.56 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const bbox = require("geojson-bbox"); const TYPENAMES_1 = require("./TYPENAMES"); const GetFeaturesRequest_1 = require("./GetFeaturesRequest"); const rxjs_1 = require("rxjs"); const __1 = require("../.."); var SentinelHubWfs; (function (SentinelHubWfs) { /** * default options to the getDate function */ const defaultGetDateOptions = { TYPENAMES: TYPENAMES_1.TYPENAMES["SENTINEL-2 L1C"], OUTPUTFORMAT: 'application/json', }; function GetFeature(polygonList, uuid, options = defaultGetDateOptions, proxy = null, requestOption = null) { //merge the defalt options with the user's options without ever changeing the reference to the original object options = Object.assign(Object.assign({}, defaultGetDateOptions), options); // getting the bbox(aka the top left connor and the bottong right connor of the combined polygons as a square ) and formatting for the sentinel urls format options.BBOX = bbox(polygonList).map(i => String(i).replace('-', '').replace('.', '').slice(0, 7)).join(','); requestOption = Object.assign({ method: 'GET' }, requestOption); const request = new GetFeaturesRequest_1.GetFeaturesRequest(); request.addUUID(uuid); const rawRequsstOptions = {}; // adding allready formated user options to the real request parameters object options.BBOX ? rawRequsstOptions.BBOX = options.BBOX : null; options.FEATURE_OFFSET ? rawRequsstOptions.FEATURE_OFFSET = options.FEATURE_OFFSET : null; options.MAXFEATURES ? rawRequsstOptions.MAXFEATURES = options.MAXFEATURES : null; options.OUTPUTFORMAT ? rawRequsstOptions.OUTPUTFORMAT = options.OUTPUTFORMAT : null; options.SRSNAME ? rawRequsstOptions.SRSNAME = options.SRSNAME : null; options.TYPENAMES ? rawRequsstOptions.TYPENAMES = options.TYPENAMES : null; // formatting Object dates to the paremater TIMES that the GetFeatures acepts (TIME=2019-01-01/2019-04-23) if (options.DATE_START && options.DATE_END) { const formatedDates = [options.DATE_END, options.DATE_START] .map(i => i.toISOString().split('T')[0]) .join('/'); rawRequsstOptions.TIME = formatedDates; } // adding each individual user declared parameter to the url builder Object.keys(rawRequsstOptions).forEach((option) => request.addParameter(option, rawRequsstOptions[option])); let link; if (proxy) { /** * link via proxy * @example ``` * 'http://myapi/REQUEST=GetFeature... * ``` */ link = request.getProxyLink(proxy); } else { /** * direct sentinel link * @example ``` * 'https://services.sentinel-hub.com/ogc/wfs/{uuid}?REQUEST=GetFeature... * ``` */ link = request.getDirectLink(uuid); } return new Promise(r => r(__1.SafeFetch(link, requestOption))); } SentinelHubWfs.GetFeature = GetFeature; function GetFeatureAsync(polygonList, uuid, options = defaultGetDateOptions, proxy = null, requestOption = null) { // corverts js promise to RxJs observable return rxjs_1.defer(() => rxjs_1.from(GetFeature(polygonList, uuid, options, proxy, requestOption))); } SentinelHubWfs.GetFeatureAsync = GetFeatureAsync; /** * @description Used to fetch avaliable dates for sattelite data * * it can be created with a proxy URL * @param {GetFeaturesRequestOptions} options for each option effect and more details: https://www.sentinel-hub.com/develop/api/ogc/standard-parameters/wfs/ */ function getAvaliableDates(polygonList, uuid, options) { return __awaiter(this, void 0, void 0, function* () { const dates = yield GetFeature(polygonList, uuid, defaultGetDateOptions, options.proxy, options.requestOption).then(r => r.json()); return dates.features.map(i => new Date(i.properties.date)); }); } SentinelHubWfs.getAvaliableDates = getAvaliableDates; /** * @description Used to fetch avaliable dates for sattelite data * `RxJs Version` * * it can be created with a proxy URL * @param {GetFeaturesRequestOptions} options for each option effect and more details: https://www.sentinel-hub.com/develop/api/ogc/standard-parameters/wfs/ */ SentinelHubWfs.getAvaliableDatesAsync = (...args) => rxjs_1.defer(() => rxjs_1.from(getAvaliableDates(...args))); })(SentinelHubWfs = exports.SentinelHubWfs || (exports.SentinelHubWfs = {})); //# sourceMappingURL=index.js.map