@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.9 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 e from"../../request.js";import{loadParquetModule as t}from"./loadParquetModule.js";import{GeometryInfoDescriptor as a,MultiScaleInfo as n,GeometryType as r}from"../../chunks/bundle.js";const i=t=>async function(a,n,r){const i=t(),{data:s}=await e(a,{responseType:"array-buffer",query:i,headers:{range:`bytes=${n}-${r}`},useRequestQueue:!0});return s},s=t=>async function(a){const n=t(),{data:r}=await e(a,{responseType:"native",method:"head",query:n,useRequestQueue:!0}),i=r.headers.get("Content-Length");if(null==i)throw new Error("Unable to parse content length");return parseInt(i,10)};class o{static async create(e,a){const n=await t(),r=await n.readMetadata(e,i(a),s(a));return o.fromFileMetadata(r)}static fromFileMetadata(e){const t=[];for(let a=0;a<e.numFields();a++){const n=e.getFieldByIndex(a);t.push({name:n.name,type:n.type,alias:n.name,index:n.index}),n.free()}return new o(e,t)}constructor(e,t){this._inner=e,this.fields=t}destroy(){this._inner.free()}[Symbol.dispose](){this.destroy()}get size(){return this._inner.numRows()}getFieldIndex(e){return this._inner.getFieldIndex(e)}tryReadGeoMetadata(){const e=this._inner.keyValueMetadata("geo");return null==e?null:JSON.parse(e)}tryReadEsriMetadata(){const e=this._inner.keyValueMetadata("esri");return null==e?null:JSON.parse(e)}}function d(e){switch(e){case"esriGeometryPoint":return r.Point;case"esriGeometryPolygon":return r.Polygon;case"esriGeometryPolyline":return r.Polyline;case"esriGeometryMultipoint":return r.Multipoint;default:throw new Error(`InternalError: Found unexpected GeometryType: ${e}`)}}function l(e,t,r){const i=a.new();if(i.geometryType=d(e.geometryType),"location"===e.encoding.type)i.latIndex=t.getFieldIndex(e.encoding.latitudeFieldName),i.lngIndex=t.getFieldIndex(e.encoding.longitudeFieldName);else if(i.wkbIndex=t.getFieldIndex(e.encoding.primaryFieldName),e.encoding.multiscale){const a=n.new();for(const n of e.encoding.multiscale.levels){const[e,r]=n.transform.translate,[i,s]=n.transform.scale,o=t.getFieldIndex(n.column);a.push(o,e,r,i,s)}i.setMultiscaleInfo(a)}return i.inWkid=e.spatialReference.wkid,r&&(i.outWkid=r.wkid),i}class u{static async create(e,a){const n=await t(),r=i(a.getCustomParameters),d=s(a.getCustomParameters),c=await n.readMetadata(e,r,d),m=l(a.geometryInfo,c,a.outSpatialReference),y=await n.readFile(e,r,d,c,m);return new u(y,o.fromFileMetadata(y.metadata()))}static async fromFile(e,a,n){const r=await t(),i=await r.readMetadataFromFile(e),s=a?l(a,i,n):void 0,d=await r.readFileFromBinary(s,e);return new u(d,o.fromFileMetadata(d.metadata()))}constructor(e,t){this.inner=e,this.metadata=t}destroy(){this.inner.free(),this.metadata.destroy()}[Symbol.dispose](){this.destroy()}}export{u as ParquetFile,o as ParquetMetadata};