UNPKG

@ciag/sentinel-hub-wms

Version:

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

133 lines 6.32 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 GetMap_1 = require("./GetMap"); const Cropper_1 = require("./Cropper"); const rxjs_1 = require("rxjs"); const WMSParameters_1 = require("./WMSParameters"); const colorPiker_1 = require("./colorPiker"); var WMSParameters_2 = require("./WMSParameters"); exports.WMSParameters = WMSParameters_2.WMSParameters; var SentinelHubWms; (function (SentinelHubWms) { function latLngToXYTool(geoJson) { if (("features" in geoJson)) { return Cropper_1.Cropper.getLagLngXY(geoJson); } else { return Cropper_1.Cropper.getLagLngXY({ features: [geoJson], type: "FeatureCollection", }); } } SentinelHubWms.latLngToXYTool = latLngToXYTool; /** * @description used to get sentinel's satellite image of a polygon, with the image cropped for the polygon */ function getShapeFromSentinel(feature, uuid, options) { return __awaiter(this, void 0, void 0, function* () { const latLng = latLngToXYTool(feature); const sentinelResult = yield getImage(uuid, latLng[0].getBobxConnors(), options); const latLngTool = latLngToXYTool(feature)[0]; const shape = yield Cropper_1.Cropper.cropImage(feature, URL.createObjectURL(sentinelResult.blob), latLngTool); return { img: shape.img, feature, bbox: shape.LatLng, link: sentinelResult.link }; }); } SentinelHubWms.getShapeFromSentinel = getShapeFromSentinel; /** * @description used to get sentinel's satellite image of a polygon, with the image cropped for the polygon * `RxJs Version` */ SentinelHubWms.getShapeFromSentinelAsync = (feature, uuid, options) => rxjs_1.defer(() => rxjs_1.from(getShapeFromSentinel(feature, uuid, options))); /** * @description used to get multiple sentinel's satellite image of a collection of polygons, with the image cropped for the polygon */ function getShapesFromSentinel(featureCollection, uuid, options) { return __awaiter(this, void 0, void 0, function* () { const promises = featureCollection.features.map(i => getShapeFromSentinel(i, uuid, options)); return yield Promise.all(promises.map((p) => __awaiter(this, void 0, void 0, function* () { try { return yield p; } catch (e) { console.error(e); return undefined; } })).filter(i => !!i)); }); } SentinelHubWms.getShapesFromSentinel = getShapesFromSentinel; /** * @description used to get multiple sentinel's satellite image of a collection of polygons, with the image cropped for the polygon * `RxJs Version` */ SentinelHubWms.getShapesFromSentinelAsync = (featureCollection, uuid, options) => featureCollection.features.map(feature => rxjs_1.defer(() => rxjs_1.from(getShapeFromSentinel(feature, uuid, options)))); /** * @description used to get the sentinel's satellite image of a square */ function getImage(uuid = "", bbox, options) { return __awaiter(this, void 0, void 0, function* () { const getMap = new GetMap_1.GetMap(uuid, { DATE: options.date, BBOX: bbox, FORMAT: WMSParameters_1.WMSParameters.Format.image_png, LAYERS: options.layers, WIDTH: "1024", HEIGHT: "780" }); if (options.proxy) getMap.proxy = options.proxy; if (options.proxyOption) getMap.proxyOptions = options.proxyOption; return yield getMap.request(); }); } SentinelHubWms.getImage = getImage; /** * @deprecated `new code in development` * @description used to find and remove non organic pixels in the satellite data (remove roads/houses/...) * @beta */ function getDangerZone(feature, image) { return __awaiter(this, void 0, void 0, function* () { const geoJson = { "type": "FeatureCollection", "features": [] }; let convertedImage; if (typeof image === "string") { convertedImage = yield new Promise((resolve, reject) => { const imgConverter = new Image(); imgConverter.src = image; imgConverter.onload = () => { resolve(imgConverter); }; imgConverter.onerror = () => { reject('fail to convert string to image'); }; }); } else { convertedImage = image; } const points = yield new colorPiker_1.ColorFinder(convertedImage).getfindColor(feature); points.forEach(item => { geoJson.features.push(item); }); return geoJson; }); } SentinelHubWms.getDangerZone = getDangerZone; /** * @deprecated `new code in development` * @description Crop user provided image to shape * @beta */ function createShapeAsImage(feature, img, latLongXY) { return Cropper_1.Cropper.cropImage(feature, img, latLongXY); } SentinelHubWms.createShapeAsImage = createShapeAsImage; })(SentinelHubWms = exports.SentinelHubWms || (exports.SentinelHubWms = {})); //# sourceMappingURL=index.js.map