@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 4.04 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{_ as t}from"../../../chunks/tslib.es6.js";import e from"../../../core/Error.js";import{eachAlways as s}from"../../../core/promiseUtils.js";import{property as i}from"../../../core/accessorSupport/decorators/property.js";import"../../../core/has.js";import"../../../core/Logger.js";import"../../../core/RandomLCG.js";import{subclass as r}from"../../../core/accessorSupport/decorators/subclass.js";import o from"../../../geometry/Extent.js";import a from"../../../geometry/SpatialReference.js";import l from"../DimensionalDefinition.js";import n from"../RasterInfo.js";import m from"./BaseRaster.js";import{getSliceIndex as c}from"./multidimensionalUtils.js";import{clipTile as p,split as u}from"../rasterFunctions/pixelUtils.js";import{estimateStatisticsHistograms as h,computeStatisticsHistograms as d}from"../rasterFunctions/stretchUtils.js";let f=class extends m{constructor(){super(...arguments),this.datasetFormat="MEMORY",this.source=null}get url(){return""}fetchRawTile(t,e,s,i={}){if(!this._pixelBlockTiles){const{rasterInfo:r}=this,[o,a]=r.storageInfo.tileInfo.size,{sliceId:l}=i,{pixelBlocks:n}=this.source,m={pixelBlock:null==l?n[0]:n[l],useBilinear:"thematic"!==r.dataType,tileSize:{width:o,height:a},level:t,row:e,col:s},c=this.rasterJobHandler?this.rasterJobHandler.clipTile(m,i):p(m);return Promise.resolve(c)}const r=this._pixelBlockTiles.get(`${t}/${e}/${s}`);return Promise.resolve(r)}async _open(t){const e=this.source,{pixelBlocks:s,attributeTable:i,statistics:r,histograms:l,name:m,nativeExtent:c,transform:p}=e,u=s[0],{width:h,height:d,pixelType:f}=u,g=e.extent??new o({xmin:-.5,ymin:.5,xmax:h-.5,ymax:d-.5,spatialReference:new a({wkid:3857})}),x=e.isPseudoSpatialReference??!e.extent,y={x:g.width/h,y:g.height/d},b={...e.keyProperties};i&&(b.DataType="Thematic");const v=new n({width:h,height:d,pixelType:f,extent:g,nativeExtent:c,attributeTable:i,transform:p,pixelSize:y,spatialReference:g.spatialReference,bandCount:u.pixels.length,keyProperties:b,multidimensionalInfo:e.multidimensionalInfo,statistics:r,isPseudoSpatialReference:x,histograms:l});this.ioConfig.skipMapInfo&&this.updateImageSpaceRasterInfo(v),this.createRemoteDatasetStorageInfo(v,512,512),this._set("rasterInfo",v),this.updateTileInfo(),v.multidimensionalInfo?await this._buildMDimStats(e.pixelBlocks,v.multidimensionalInfo):await this._buildInMemoryRaster(u,{width:512,height:512},t),v.multidimensionalInfo||(this.source=null),this.datasetName=m}async _buildInMemoryRaster(t,i,r){const{rasterInfo:o}=this,a=o.storageInfo.maximumPyramidLevel??0,l="thematic"!==o.dataType,n=this.rasterJobHandler?this.rasterJobHandler.split({pixelBlock:t,tileSize:i,maximumPyramidLevel:a,useBilinear:l},r):Promise.resolve(u(t,i,a,l)),m=null!=o.statistics,c=null!=o.histograms,p=this.ioConfig.skipStatistics||m?Promise.resolve({statistics:null,histograms:null}):this.rasterJobHandler?this.rasterJobHandler.estimateStatisticsHistograms({pixelBlock:t},r):Promise.resolve(h(t)),d=await s([n,p]);if(!d[0].value&&d[1].value)throw new e("inmemory-raster:open","failed to build in memory raster");this._pixelBlockTiles=d[0].value,m||(o.statistics=d[1].value?.statistics),c||(o.histograms=d[1].value?.histograms)}async _buildMDimStats(t,e,s){for(let i=0;i<e.variables.length;i++){const r=e.variables[i];if(r.statistics)continue;const o=r.dimensions.map((t=>new l({variableName:r.name,dimensionName:t.name,values:[t.values?.[0]??t.extent?.[0]],isSlice:!0}))),a=c(o,e),n=null==a?null:t[a];if(null==n)continue;const m=this.rasterJobHandler?await this.rasterJobHandler.computeStatisticsHistograms({pixelBlock:n},s):d(n);r.statistics=m.statistics,r.histograms||(r.histograms=m.histograms)}}};t([i({type:String,json:{write:!0}})],f.prototype,"datasetFormat",void 0),t([i()],f.prototype,"source",void 0),t([i()],f.prototype,"url",null),f=t([r("esri.layers.support.rasterDatasets.InMemoryRaster")],f);const g=f;export{g as default};