Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getHistogram = (raster, geometry, options) => {
const { scaleType, numClasses } = options;
// make sure parameters are valid
if (numClasses % 1 !== 0) {
throw new Error('Please make sure the number of classes is an integer.');
}
if (!geometry) {
throw new Error('Please make sure to select a geography to run the tool on.');
}
// convert to list because react doesn't like storing objects in state
const geojson = geometry.toGeoJSON();
const results = geoblaze.histogram(raster, geojson, options);
return setResults(results);
}
map.on('click', e => {
store.dispatch(unfocusMenu());
if (self.drawingPoints) {
store.dispatch(removeGeometry());
store.dispatch(addGeometry(e.latlng, 'point'));
// temporary - setting results for identify here since
// i can't find a good way of getting it in to the identify
// tool while using leaflet for mapping
const latlng = [e.latlng.lng, e.latlng.lat];
const results = geoblaze.identify(self.raster.georaster, latlng);
store.dispatch(setResults(results));
}
});
runBandArithmetic: (raster, bandArithmetic) => {
if (!raster) return dispatch(showAlert('Please add a raster before running this tool.'));
if (!bandArithmetic) return dispatch(showAlert('Please add an arithmetic operation before running this tool.'));
try {
dispatch(startLoading('Running Band Arithmetic'));
return geoblaze.bandArithmetic(raster, bandArithmetic).then(newRaster => {
dispatch(stopLoading());
dispatch(addRasterFromGeoraster(newRaster));
});
} catch(e) {
dispatch(stopLoading());
dispatch(showAlert(`${SITE_CONFIG.title} was unable to complete the operation. Please make sure you are using a multi-band raster and a valid arithmetic operation`));
}
}
});
return new Promise((resolve, reject) => {
geoblaze.load(input)
.then(georaster => {
let options = {
georaster: georaster,
opacity: 0.7,
resolution: getResolution()
};
const raster = new GeoRasterLayer(options);
resolve(raster);
}, error => {
reject(error);
});
});
},
const calculateMax = (raster, coors) => {
return geoblaze.max(raster, coors)
.map(value => value.toFixed(2)).join(', ');
}
const calculateMean = (raster, coors) => {
return geoblaze.mean(raster, coors)
.map(value => value.toFixed(2)).join(', ');
}
const calculateMedian = (raster, coors) => {
return geoblaze.median(raster, coors)
.map(value => value.toFixed(2)).join(', ');
}
const calculateMin = (raster, coors) => {
return geoblaze.min(raster, coors)
.map(value => value.toFixed(2)).join(', ');
}
const calculateMode = (raster, coors) => {
const modes = geoblaze.mode(raster, coors);
return modes.map(band => {
if (typeof band === 'number') return band;
return band.join(", ");
});
}
runRasterCalculator: (raster, rasterCalculator) => {
if (!raster) return dispatch(showAlert('Please add a raster before running this tool.'));
if (!rasterCalculator) return dispatch(showAlert('Please add a raster calculator operation before running this tool.'));
try {
dispatch(startLoading('Running Raster Calculator'));
return geoblaze.rasterCalculator(raster, rasterCalculator).then(newRaster => {
dispatch(stopLoading());
dispatch(addRasterFromGeoraster(newRaster));
});
} catch(e) {
dispatch(stopLoading());
dispatch(showAlert(`${SITE_CONFIG.title} was unable to complete the operation. Please make sure you are using a multi-band raster and a valid arithmetic operation`));
}
}
});