@loaders.gl/shapefile 3.4.0-alpha.2 → 3.4.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dbf-worker.js +1 -1
- package/dist/dist.min.js +47 -0
- package/dist/es5/dbf-loader.js +7 -11
- package/dist/es5/dbf-loader.js.map +1 -1
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/lib/parsers/parse-dbf.js +47 -75
- package/dist/es5/lib/parsers/parse-dbf.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shapefile.js +239 -249
- package/dist/es5/lib/parsers/parse-shapefile.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shp-geometry.js +0 -16
- package/dist/es5/lib/parsers/parse-shp-geometry.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shp-header.js +0 -1
- package/dist/es5/lib/parsers/parse-shp-header.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shp.js +74 -79
- package/dist/es5/lib/parsers/parse-shp.js.map +1 -1
- package/dist/es5/lib/parsers/parse-shx.js +0 -1
- package/dist/es5/lib/parsers/parse-shx.js.map +1 -1
- package/dist/es5/lib/streaming/binary-chunk-reader.js +9 -33
- package/dist/es5/lib/streaming/binary-chunk-reader.js.map +1 -1
- package/dist/es5/lib/streaming/binary-reader.js +4 -11
- package/dist/es5/lib/streaming/binary-reader.js.map +1 -1
- package/dist/es5/lib/streaming/zip-batch-iterators.js +54 -58
- package/dist/es5/lib/streaming/zip-batch-iterators.js.map +1 -1
- package/dist/es5/shapefile-loader.js +1 -2
- package/dist/es5/shapefile-loader.js.map +1 -1
- package/dist/es5/shp-loader.js +7 -11
- package/dist/es5/shp-loader.js.map +1 -1
- package/dist/es5/workers/dbf-worker.js.map +1 -1
- package/dist/es5/workers/shp-worker.js.map +1 -1
- package/dist/esm/bundle.js +0 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/dbf-loader.js +1 -4
- package/dist/esm/dbf-loader.js.map +1 -1
- package/dist/esm/lib/parsers/parse-dbf.js +34 -45
- package/dist/esm/lib/parsers/parse-dbf.js.map +1 -1
- package/dist/esm/lib/parsers/parse-shapefile.js +0 -16
- package/dist/esm/lib/parsers/parse-shapefile.js.map +1 -1
- package/dist/esm/lib/parsers/parse-shp-geometry.js +0 -18
- package/dist/esm/lib/parsers/parse-shp-geometry.js.map +1 -1
- package/dist/esm/lib/parsers/parse-shp-header.js +0 -1
- package/dist/esm/lib/parsers/parse-shp-header.js.map +1 -1
- package/dist/esm/lib/parsers/parse-shp.js +0 -4
- package/dist/esm/lib/parsers/parse-shp.js.map +1 -1
- package/dist/esm/lib/parsers/parse-shx.js +0 -1
- package/dist/esm/lib/parsers/parse-shx.js.map +1 -1
- package/dist/esm/lib/streaming/binary-chunk-reader.js +0 -16
- package/dist/esm/lib/streaming/binary-chunk-reader.js.map +1 -1
- package/dist/esm/lib/streaming/binary-reader.js +0 -3
- package/dist/esm/lib/streaming/binary-reader.js.map +1 -1
- package/dist/esm/lib/streaming/zip-batch-iterators.js +0 -5
- package/dist/esm/lib/streaming/zip-batch-iterators.js.map +1 -1
- package/dist/esm/shapefile-loader.js +1 -3
- package/dist/esm/shapefile-loader.js.map +1 -1
- package/dist/esm/shp-loader.js +1 -4
- package/dist/esm/shp-loader.js.map +1 -1
- package/dist/shp-worker.js +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-shapefile.js","names":["parseShapefileInBatches","asyncIterator","options","context","gis","reproject","_targetCrs","loadShapefileSidecarFiles","shx","cpg","prj","parseInBatches","SHPLoader","shapeIterable","fetch","replaceExtension","url","dbfResponse","ok","DBFLoader","dbf","encoding","propertyIterable","next","shapeHeader","value","batchType","dbfHeader","iterator","zipBatchIterators","item","geometries","properties","geojsonGeometries","parseGeometries","features","joinProperties","reprojectFeatures","header","data","parseShapefile","arrayBuffer","parse","geom","push","binaryToGeometry","i","length","geometry","feature","type","sourceCrs","targetCrs","projection","Proj4Projection","from","to","transformGeoJsonCoords","coord","project","shxPromise","cpgPromise","prjPromise","Promise","all","shxResponse","parseShx","cpgResponse","text","prjResponse","newExtension","baseName","basename","extension","extname","isUpperCase","toUpperCase","extIndex","lastIndexOf","substr"],"sources":["../../../../src/lib/parsers/parse-shapefile.ts"],"sourcesContent":["// import type {Feature} from '@loaders.gl/gis';\nimport type {SHXOutput} from './parse-shx';\nimport type {SHPHeader} from './parse-shp-header';\nimport type {LoaderContext} from '@loaders.gl/loader-utils';\nimport type {ShapefileLoaderOptions} from './types';\n\nimport {binaryToGeometry, transformGeoJsonCoords} from '@loaders.gl/gis';\nimport {Proj4Projection} from '@math.gl/proj4';\nimport {parseShx} from './parse-shx';\nimport {zipBatchIterators} from '../streaming/zip-batch-iterators';\nimport {SHPLoader} from '../../shp-loader';\nimport {DBFLoader} from '../../dbf-loader';\n\ntype Feature = any;\ninterface ShapefileOutput {\n encoding?: string;\n prj?: string;\n shx?: SHXOutput;\n header: SHPHeader;\n data: object[];\n}\n/**\n * Parsing of file in batches\n */\n// eslint-disable-next-line max-statements, complexity\nexport async function* parseShapefileInBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options?: ShapefileLoaderOptions,\n context?: LoaderContext\n): AsyncIterable<ShapefileOutput> {\n const {reproject = false, _targetCrs = 'WGS84'} = options?.gis || {};\n const {shx, cpg, prj} = await loadShapefileSidecarFiles(options, context);\n\n // parse geometries\n // @ts-ignore context must be defined\n const shapeIterable: any = await context.parseInBatches(asyncIterator, SHPLoader, options);\n\n // parse properties\n let propertyIterable: any;\n // @ts-ignore context must be defined\n const dbfResponse = await context.fetch(replaceExtension(context?.url || '', 'dbf'));\n if (dbfResponse.ok) {\n // @ts-ignore context must be defined\n propertyIterable = await context.parseInBatches(dbfResponse, DBFLoader, {\n ...options,\n dbf: {encoding: cpg || 'latin1'}\n });\n }\n\n // When `options.metadata` is `true`, there's an extra initial `metadata`\n // object before the iterator starts. zipBatchIterators expects to receive\n // batches of Array objects, and will fail with non-iterable batches, so it's\n // important to skip over the first batch.\n let shapeHeader = (await shapeIterable.next()).value;\n if (shapeHeader && shapeHeader.batchType === 'metadata') {\n shapeHeader = (await shapeIterable.next()).value;\n }\n\n let dbfHeader: {batchType?: string} = {};\n if (propertyIterable) {\n dbfHeader = (await propertyIterable.next()).value;\n if (dbfHeader && dbfHeader.batchType === 'metadata') {\n dbfHeader = (await propertyIterable.next()).value;\n }\n }\n\n let iterator: any;\n if (propertyIterable) {\n iterator = zipBatchIterators(shapeIterable, propertyIterable);\n } else {\n iterator = shapeIterable;\n }\n\n for await (const item of iterator) {\n let geometries: any;\n let properties: any;\n if (!propertyIterable) {\n geometries = item;\n } else {\n [geometries, properties] = item;\n }\n\n const geojsonGeometries = parseGeometries(geometries);\n let features = joinProperties(geojsonGeometries, properties);\n if (reproject) {\n // @ts-ignore\n features = reprojectFeatures(features, prj, _targetCrs);\n }\n yield {\n encoding: cpg,\n prj,\n shx,\n header: shapeHeader,\n data: features\n };\n }\n}\n\n/**\n * Parse shapefile\n *\n * @param arrayBuffer\n * @param options\n * @param context\n * @returns output of shapefile\n */\nexport async function parseShapefile(\n arrayBuffer: ArrayBuffer,\n options?: ShapefileLoaderOptions,\n context?: LoaderContext\n): Promise<ShapefileOutput> {\n const {reproject = false, _targetCrs = 'WGS84'} = options?.gis || {};\n const {shx, cpg, prj} = await loadShapefileSidecarFiles(options, context);\n\n // parse geometries\n // @ts-ignore context must be defined\n const {header, geometries} = await context.parse(arrayBuffer, SHPLoader, options); // {shp: shx}\n\n const geojsonGeometries = parseGeometries(geometries);\n\n // parse properties\n let properties = [];\n\n // @ts-ignore context must be defined\n const dbfResponse = await context.fetch(replaceExtension(context.url, 'dbf'));\n if (dbfResponse.ok) {\n // @ts-ignore context must be defined\n properties = await context.parse(dbfResponse, DBFLoader, {dbf: {encoding: cpg || 'latin1'}});\n }\n\n let features = joinProperties(geojsonGeometries, properties);\n if (reproject) {\n features = reprojectFeatures(features, prj, _targetCrs);\n }\n\n return {\n encoding: cpg,\n prj,\n shx,\n header,\n data: features\n };\n}\n\n/**\n * Parse geometries\n *\n * @param geometries\n * @returns geometries as an array\n */\nfunction parseGeometries(geometries: any[]): any[] {\n const geojsonGeometries: any[] = [];\n for (const geom of geometries) {\n geojsonGeometries.push(binaryToGeometry(geom));\n }\n return geojsonGeometries;\n}\n\n/**\n * Join properties and geometries into features\n *\n * @param geometries [description]\n * @param properties [description]\n * @return [description]\n */\nfunction joinProperties(geometries: object[], properties: object[]): Feature[] {\n const features: Feature[] = [];\n for (let i = 0; i < geometries.length; i++) {\n const geometry = geometries[i];\n const feature: Feature = {\n type: 'Feature',\n geometry,\n // properties can be undefined if dbfResponse above was empty\n properties: (properties && properties[i]) || {}\n };\n features.push(feature);\n }\n\n return features;\n}\n\n/**\n * Reproject GeoJSON features to output CRS\n *\n * @param features parsed GeoJSON features\n * @param sourceCrs source coordinate reference system\n * @param targetCrs †arget coordinate reference system\n * @return Reprojected Features\n */\nfunction reprojectFeatures(features: Feature[], sourceCrs?: string, targetCrs?: string): Feature[] {\n if (!sourceCrs && !targetCrs) {\n return features;\n }\n\n const projection = new Proj4Projection({from: sourceCrs || 'WGS84', to: targetCrs || 'WGS84'});\n return transformGeoJsonCoords(features, (coord) => projection.project(coord));\n}\n\n/**\n *\n * @param options\n * @param context\n * @returns Promise\n */\n// eslint-disable-next-line max-statements\nexport async function loadShapefileSidecarFiles(\n options?: object,\n context?: LoaderContext\n): Promise<{\n shx?: SHXOutput;\n cpg?: string;\n prj?: string;\n}> {\n // Attempt a parallel load of the small sidecar files\n // @ts-ignore context must be defined\n const {url, fetch} = context;\n const shxPromise = fetch(replaceExtension(url, 'shx'));\n const cpgPromise = fetch(replaceExtension(url, 'cpg'));\n const prjPromise = fetch(replaceExtension(url, 'prj'));\n await Promise.all([shxPromise, cpgPromise, prjPromise]);\n\n let shx: SHXOutput | undefined;\n let cpg: string | undefined;\n let prj: string | undefined;\n\n const shxResponse = await shxPromise;\n if (shxResponse.ok) {\n const arrayBuffer = await shxResponse.arrayBuffer();\n shx = parseShx(arrayBuffer);\n }\n\n const cpgResponse = await cpgPromise;\n if (cpgResponse.ok) {\n cpg = await cpgResponse.text();\n }\n\n const prjResponse = await prjPromise;\n if (prjResponse.ok) {\n prj = await prjResponse.text();\n }\n\n return {\n shx,\n cpg,\n prj\n };\n}\n\n/**\n * Replace the extension at the end of a path.\n *\n * Matches the case of new extension with the case of the original file extension,\n * to increase the chance of finding files without firing off a request storm looking for various case combinations\n *\n * NOTE: Extensions can be both lower and uppercase\n * per spec, extensions should be lower case, but that doesn't mean they always are. See:\n * calvinmetcalf/shapefile-js#64, mapserver/mapserver#4712\n * https://trac.osgeo.org/mapserver/ticket/166\n */\nexport function replaceExtension(url: string, newExtension: string): string {\n const baseName = basename(url);\n const extension = extname(url);\n const isUpperCase = extension === extension.toUpperCase();\n if (isUpperCase) {\n newExtension = newExtension.toUpperCase();\n }\n return `${baseName}.${newExtension}`;\n}\n\n// NOTE - this gives the entire path minus extension (i.e. NOT same as path.basename)\n/**\n * @param url\n * @returns string\n */\nfunction basename(url: string): string {\n const extIndex = url && url.lastIndexOf('.');\n if (typeof extIndex === 'number') {\n return extIndex >= 0 ? url.substr(0, extIndex) : '';\n }\n return extIndex;\n}\n/**\n * @param url\n * @returns string\n */\nfunction extname(url: string): string {\n const extIndex = url && url.lastIndexOf('.');\n if (typeof extIndex === 'number') {\n return extIndex >= 0 ? url.substr(extIndex + 1) : '';\n }\n return extIndex;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAMA;AACA;AACA;AACA;AACA;AACA;AAA2C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAcpBA,uBAAuB;EAAA;AAAA;AAAA;EAAA,uFAAvC,iBACLC,aAAiE,EACjEC,OAAgC,EAChCC,OAAuB;IAAA;IAAA;MAAA;QAAA;UAAA;YAAA,OAE2B,CAAAD,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAA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AA;MAAA;IAAA;EAAA,CACF;EAAA;AAAA;AAaM,SAASK,gBAAgB,CAACC,GAAW,EAAEsD,YAAoB,EAAU;EAC1E,IAAMC,QAAQ,GAAGC,QAAQ,CAACxD,GAAG,CAAC;EAC9B,IAAMyD,SAAS,GAAGC,OAAO,CAAC1D,GAAG,CAAC;EAC9B,IAAM2D,WAAW,GAAGF,SAAS,KAAKA,SAAS,CAACG,WAAW,EAAE;EACzD,IAAID,WAAW,EAAE;IACfL,YAAY,GAAGA,YAAY,CAACM,WAAW,EAAE;EAC3C;EACA,iBAAUL,QAAQ,cAAID,YAAY;AACpC;;AAOA,SAASE,QAAQ,CAACxD,GAAW,EAAU;EACrC,IAAM6D,QAAQ,GAAG7D,GAAG,IAAIA,GAAG,CAAC8D,WAAW,CAAC,GAAG,CAAC;EAC5C,IAAI,OAAOD,QAAQ,KAAK,QAAQ,EAAE;IAChC,OAAOA,QAAQ,IAAI,CAAC,GAAG7D,GAAG,CAAC+D,MAAM,CAAC,CAAC,EAAEF,QAAQ,CAAC,GAAG,EAAE;EACrD;EACA,OAAOA,QAAQ;AACjB;AAKA,SAASH,OAAO,CAAC1D,GAAW,EAAU;EACpC,IAAM6D,QAAQ,GAAG7D,GAAG,IAAIA,GAAG,CAAC8D,WAAW,CAAC,GAAG,CAAC;EAC5C,IAAI,OAAOD,QAAQ,KAAK,QAAQ,EAAE;IAChC,OAAOA,QAAQ,IAAI,CAAC,GAAG7D,GAAG,CAAC+D,MAAM,CAACF,QAAQ,GAAG,CAAC,CAAC,GAAG,EAAE;EACtD;EACA,OAAOA,QAAQ;AACjB"}
|
|
1
|
+
{"version":3,"file":"parse-shapefile.js","names":["_gis","require","_proj","_parseShx","_zipBatchIterators","_shpLoader","_dbfLoader","_createForOfIteratorHelper","o","allowArrayLike","it","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","length","i","F","s","n","done","value","e","_e","f","TypeError","normalCompletion","didErr","err","call","step","next","_e2","return","minLen","_arrayLikeToArray","Object","prototype","toString","slice","constructor","name","from","test","arr","len","arr2","ownKeys","object","enumerableOnly","keys","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","arguments","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","_asyncIterator","iterable","method","async","sync","retry","asyncIterator","AsyncFromSyncIterator","AsyncFromSyncIteratorContinuation","r","Promise","reject","resolve","then","_return","ret","throw","_throw","thr","parseShapefileInBatches","_x","_x2","_x3","_parseShapefileInBatches","_wrapAsyncGenerator2","_regenerator","mark","_callee","options","context","_ref","_ref$reproject","reproject","_ref$_targetCrs","_targetCrs","_yield$_awaitAsyncGen","shx","cpg","prj","shapeIterable","propertyIterable","dbfResponse","shapeHeader","dbfHeader","_iteratorAbruptCompletion","_didIteratorError","_iteratorError","_iterator","_step","item","geometries","properties","_item","geojsonGeometries","features","wrap","_callee$","_context","prev","gis","_awaitAsyncGenerator2","loadShapefileSidecarFiles","sent","parseInBatches","SHPLoader","fetch","replaceExtension","url","ok","DBFLoader","dbf","encoding","batchType","zipBatchIterators","_slicedToArray2","parseGeometries","joinProperties","reprojectFeatures","header","data","t0","finish","stop","parseShapefile","_x4","_x5","_x6","_parseShapefile","_asyncToGenerator2","_callee2","arrayBuffer","_ref2","_ref2$reproject","_ref2$_targetCrs","_yield$loadShapefileS","_yield$context$parse","_callee2$","_context2","parse","abrupt","_iterator2","_step2","geom","binaryToGeometry","geometry","feature","type","sourceCrs","targetCrs","projection","Proj4Projection","to","transformGeoJsonCoords","coord","project","_x7","_x8","_loadShapefileSidecarFiles","_callee3","shxPromise","cpgPromise","prjPromise","shxResponse","cpgResponse","prjResponse","_callee3$","_context3","all","parseShx","text","newExtension","baseName","basename","extension","extname","isUpperCase","toUpperCase","concat","extIndex","lastIndexOf","substr"],"sources":["../../../../src/lib/parsers/parse-shapefile.ts"],"sourcesContent":["// import type {Feature} from '@loaders.gl/gis';\nimport type {SHXOutput} from './parse-shx';\nimport type {SHPHeader} from './parse-shp-header';\nimport type {LoaderContext} from '@loaders.gl/loader-utils';\nimport type {ShapefileLoaderOptions} from './types';\n\nimport {binaryToGeometry, transformGeoJsonCoords} from '@loaders.gl/gis';\nimport {Proj4Projection} from '@math.gl/proj4';\nimport {parseShx} from './parse-shx';\nimport {zipBatchIterators} from '../streaming/zip-batch-iterators';\nimport {SHPLoader} from '../../shp-loader';\nimport {DBFLoader} from '../../dbf-loader';\n\ntype Feature = any;\ninterface ShapefileOutput {\n encoding?: string;\n prj?: string;\n shx?: SHXOutput;\n header: SHPHeader;\n data: object[];\n}\n/**\n * Parsing of file in batches\n */\n// eslint-disable-next-line max-statements, complexity\nexport async function* parseShapefileInBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options?: ShapefileLoaderOptions,\n context?: LoaderContext\n): AsyncIterable<ShapefileOutput> {\n const {reproject = false, _targetCrs = 'WGS84'} = options?.gis || {};\n const {shx, cpg, prj} = await loadShapefileSidecarFiles(options, context);\n\n // parse geometries\n // @ts-ignore context must be defined\n const shapeIterable: any = await context.parseInBatches(asyncIterator, SHPLoader, options);\n\n // parse properties\n let propertyIterable: any;\n // @ts-ignore context must be defined\n const dbfResponse = await context.fetch(replaceExtension(context?.url || '', 'dbf'));\n if (dbfResponse.ok) {\n // @ts-ignore context must be defined\n propertyIterable = await context.parseInBatches(dbfResponse, DBFLoader, {\n ...options,\n dbf: {encoding: cpg || 'latin1'}\n });\n }\n\n // When `options.metadata` is `true`, there's an extra initial `metadata`\n // object before the iterator starts. zipBatchIterators expects to receive\n // batches of Array objects, and will fail with non-iterable batches, so it's\n // important to skip over the first batch.\n let shapeHeader = (await shapeIterable.next()).value;\n if (shapeHeader && shapeHeader.batchType === 'metadata') {\n shapeHeader = (await shapeIterable.next()).value;\n }\n\n let dbfHeader: {batchType?: string} = {};\n if (propertyIterable) {\n dbfHeader = (await propertyIterable.next()).value;\n if (dbfHeader && dbfHeader.batchType === 'metadata') {\n dbfHeader = (await propertyIterable.next()).value;\n }\n }\n\n let iterator: any;\n if (propertyIterable) {\n iterator = zipBatchIterators(shapeIterable, propertyIterable);\n } else {\n iterator = shapeIterable;\n }\n\n for await (const item of iterator) {\n let geometries: any;\n let properties: any;\n if (!propertyIterable) {\n geometries = item;\n } else {\n [geometries, properties] = item;\n }\n\n const geojsonGeometries = parseGeometries(geometries);\n let features = joinProperties(geojsonGeometries, properties);\n if (reproject) {\n // @ts-ignore\n features = reprojectFeatures(features, prj, _targetCrs);\n }\n yield {\n encoding: cpg,\n prj,\n shx,\n header: shapeHeader,\n data: features\n };\n }\n}\n\n/**\n * Parse shapefile\n *\n * @param arrayBuffer\n * @param options\n * @param context\n * @returns output of shapefile\n */\nexport async function parseShapefile(\n arrayBuffer: ArrayBuffer,\n options?: ShapefileLoaderOptions,\n context?: LoaderContext\n): Promise<ShapefileOutput> {\n const {reproject = false, _targetCrs = 'WGS84'} = options?.gis || {};\n const {shx, cpg, prj} = await loadShapefileSidecarFiles(options, context);\n\n // parse geometries\n // @ts-ignore context must be defined\n const {header, geometries} = await context.parse(arrayBuffer, SHPLoader, options); // {shp: shx}\n\n const geojsonGeometries = parseGeometries(geometries);\n\n // parse properties\n let properties = [];\n\n // @ts-ignore context must be defined\n const dbfResponse = await context.fetch(replaceExtension(context.url, 'dbf'));\n if (dbfResponse.ok) {\n // @ts-ignore context must be defined\n properties = await context.parse(dbfResponse, DBFLoader, {dbf: {encoding: cpg || 'latin1'}});\n }\n\n let features = joinProperties(geojsonGeometries, properties);\n if (reproject) {\n features = reprojectFeatures(features, prj, _targetCrs);\n }\n\n return {\n encoding: cpg,\n prj,\n shx,\n header,\n data: features\n };\n}\n\n/**\n * Parse geometries\n *\n * @param geometries\n * @returns geometries as an array\n */\nfunction parseGeometries(geometries: any[]): any[] {\n const geojsonGeometries: any[] = [];\n for (const geom of geometries) {\n geojsonGeometries.push(binaryToGeometry(geom));\n }\n return geojsonGeometries;\n}\n\n/**\n * Join properties and geometries into features\n *\n * @param geometries [description]\n * @param properties [description]\n * @return [description]\n */\nfunction joinProperties(geometries: object[], properties: object[]): Feature[] {\n const features: Feature[] = [];\n for (let i = 0; i < geometries.length; i++) {\n const geometry = geometries[i];\n const feature: Feature = {\n type: 'Feature',\n geometry,\n // properties can be undefined if dbfResponse above was empty\n properties: (properties && properties[i]) || {}\n };\n features.push(feature);\n }\n\n return features;\n}\n\n/**\n * Reproject GeoJSON features to output CRS\n *\n * @param features parsed GeoJSON features\n * @param sourceCrs source coordinate reference system\n * @param targetCrs †arget coordinate reference system\n * @return Reprojected Features\n */\nfunction reprojectFeatures(features: Feature[], sourceCrs?: string, targetCrs?: string): Feature[] {\n if (!sourceCrs && !targetCrs) {\n return features;\n }\n\n const projection = new Proj4Projection({from: sourceCrs || 'WGS84', to: targetCrs || 'WGS84'});\n return transformGeoJsonCoords(features, (coord) => projection.project(coord));\n}\n\n/**\n *\n * @param options\n * @param context\n * @returns Promise\n */\n// eslint-disable-next-line max-statements\nexport async function loadShapefileSidecarFiles(\n options?: object,\n context?: LoaderContext\n): Promise<{\n shx?: SHXOutput;\n cpg?: string;\n prj?: string;\n}> {\n // Attempt a parallel load of the small sidecar files\n // @ts-ignore context must be defined\n const {url, fetch} = context;\n const shxPromise = fetch(replaceExtension(url, 'shx'));\n const cpgPromise = fetch(replaceExtension(url, 'cpg'));\n const prjPromise = fetch(replaceExtension(url, 'prj'));\n await Promise.all([shxPromise, cpgPromise, prjPromise]);\n\n let shx: SHXOutput | undefined;\n let cpg: string | undefined;\n let prj: string | undefined;\n\n const shxResponse = await shxPromise;\n if (shxResponse.ok) {\n const arrayBuffer = await shxResponse.arrayBuffer();\n shx = parseShx(arrayBuffer);\n }\n\n const cpgResponse = await cpgPromise;\n if (cpgResponse.ok) {\n cpg = await cpgResponse.text();\n }\n\n const prjResponse = await prjPromise;\n if (prjResponse.ok) {\n prj = await prjResponse.text();\n }\n\n return {\n shx,\n cpg,\n prj\n };\n}\n\n/**\n * Replace the extension at the end of a path.\n *\n * Matches the case of new extension with the case of the original file extension,\n * to increase the chance of finding files without firing off a request storm looking for various case combinations\n *\n * NOTE: Extensions can be both lower and uppercase\n * per spec, extensions should be lower case, but that doesn't mean they always are. See:\n * calvinmetcalf/shapefile-js#64, mapserver/mapserver#4712\n * https://trac.osgeo.org/mapserver/ticket/166\n */\nexport function replaceExtension(url: string, newExtension: string): string {\n const baseName = basename(url);\n const extension = extname(url);\n const isUpperCase = extension === extension.toUpperCase();\n if (isUpperCase) {\n newExtension = newExtension.toUpperCase();\n }\n return `${baseName}.${newExtension}`;\n}\n\n// NOTE - this gives the entire path minus extension (i.e. NOT same as path.basename)\n/**\n * @param url\n * @returns string\n */\nfunction basename(url: string): string {\n const extIndex = url && url.lastIndexOf('.');\n if (typeof extIndex === 'number') {\n return extIndex >= 0 ? url.substr(0, extIndex) : '';\n }\n return extIndex;\n}\n/**\n * @param url\n * @returns string\n */\nfunction extname(url: string): string {\n const extIndex = url && url.lastIndexOf('.');\n if (typeof extIndex === 'number') {\n return extIndex >= 0 ? url.substr(extIndex + 1) : '';\n }\n return extIndex;\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAMA,IAAAA,IAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAA2C,SAAAM,2BAAAC,CAAA,EAAAC,cAAA,QAAAC,EAAA,UAAAC,MAAA,oBAAAH,CAAA,CAAAG,MAAA,CAAAC,QAAA,KAAAJ,CAAA,qBAAAE,EAAA,QAAAG,KAAA,CAAAC,OAAA,CAAAN,CAAA,MAAAE,EAAA,GAAAK,2BAAA,CAAAP,CAAA,MAAAC,cAAA,IAAAD,CAAA,WAAAA,CAAA,CAAAQ,MAAA,qBAAAN,EAAA,EAAAF,CAAA,GAAAE,EAAA,MAAAO,CAAA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A,CAACnE,GAAW,EAAU;EACpC,IAAMuE,QAAQ,GAAGvE,GAAG,IAAIA,GAAG,CAACwE,WAAW,CAAC,GAAG,CAAC;EAC5C,IAAI,OAAOD,QAAQ,KAAK,QAAQ,EAAE;IAChC,OAAOA,QAAQ,IAAI,CAAC,GAAGvE,GAAG,CAACyE,MAAM,CAACF,QAAQ,GAAG,CAAC,CAAC,GAAG,EAAE;EACtD;EACA,OAAOA,QAAQ;AACjB"}
|
|
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.parseRecord = parseRecord;
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
9
|
var LITTLE_ENDIAN = true;
|
|
10
|
-
|
|
11
10
|
function parseRecord(view, options) {
|
|
12
11
|
var _ref = (options === null || options === void 0 ? void 0 : options.shp) || {},
|
|
13
12
|
_ref$_maxDimensions = _ref._maxDimensions,
|
|
@@ -46,11 +45,9 @@ function parseRecord(view, options) {
|
|
|
46
45
|
throw new Error("unsupported shape type: ".concat(type));
|
|
47
46
|
}
|
|
48
47
|
}
|
|
49
|
-
|
|
50
48
|
function parseNull() {
|
|
51
49
|
return null;
|
|
52
50
|
}
|
|
53
|
-
|
|
54
51
|
function parsePoint(view, offset, dim) {
|
|
55
52
|
var positions;
|
|
56
53
|
var _parsePositions = parsePositions(view, offset, 1, dim);
|
|
@@ -65,7 +62,6 @@ function parsePoint(view, offset, dim) {
|
|
|
65
62
|
type: 'Point'
|
|
66
63
|
};
|
|
67
64
|
}
|
|
68
|
-
|
|
69
65
|
function parseMultiPoint(view, offset, dim) {
|
|
70
66
|
offset += 4 * Float64Array.BYTES_PER_ELEMENT;
|
|
71
67
|
var nPoints = view.getInt32(offset, LITTLE_ENDIAN);
|
|
@@ -84,7 +80,6 @@ function parseMultiPoint(view, offset, dim) {
|
|
|
84
80
|
zPositions = _parsePositions6[0];
|
|
85
81
|
offset = _parsePositions6[1];
|
|
86
82
|
}
|
|
87
|
-
|
|
88
83
|
if (dim >= 3) {
|
|
89
84
|
offset += 2 * Float64Array.BYTES_PER_ELEMENT;
|
|
90
85
|
var _parsePositions7 = parsePositions(view, offset, nPoints, 1);
|
|
@@ -101,14 +96,12 @@ function parseMultiPoint(view, offset, dim) {
|
|
|
101
96
|
type: 'Point'
|
|
102
97
|
};
|
|
103
98
|
}
|
|
104
|
-
|
|
105
99
|
function parsePoly(view, offset, dim, type) {
|
|
106
100
|
offset += 4 * Float64Array.BYTES_PER_ELEMENT;
|
|
107
101
|
var nParts = view.getInt32(offset, LITTLE_ENDIAN);
|
|
108
102
|
offset += Int32Array.BYTES_PER_ELEMENT;
|
|
109
103
|
var nPoints = view.getInt32(offset, LITTLE_ENDIAN);
|
|
110
104
|
offset += Int32Array.BYTES_PER_ELEMENT;
|
|
111
|
-
|
|
112
105
|
var bufferOffset = view.byteOffset + offset;
|
|
113
106
|
var bufferLength = nParts * Int32Array.BYTES_PER_ELEMENT;
|
|
114
107
|
var ringIndices = new Int32Array(nParts + 1);
|
|
@@ -129,7 +122,6 @@ function parsePoly(view, offset, dim, type) {
|
|
|
129
122
|
zPositions = _parsePositions12[0];
|
|
130
123
|
offset = _parsePositions12[1];
|
|
131
124
|
}
|
|
132
|
-
|
|
133
125
|
if (dim >= 3) {
|
|
134
126
|
offset += 2 * Float64Array.BYTES_PER_ELEMENT;
|
|
135
127
|
var _parsePositions13 = parsePositions(view, offset, nPoints, 1);
|
|
@@ -138,7 +130,6 @@ function parsePoly(view, offset, dim, type) {
|
|
|
138
130
|
offset = _parsePositions14[1];
|
|
139
131
|
}
|
|
140
132
|
var positions = concatPositions(xyPositions, mPositions, zPositions);
|
|
141
|
-
|
|
142
133
|
if (type === 'LineString') {
|
|
143
134
|
return {
|
|
144
135
|
type: type,
|
|
@@ -152,14 +143,12 @@ function parsePoly(view, offset, dim, type) {
|
|
|
152
143
|
}
|
|
153
144
|
};
|
|
154
145
|
}
|
|
155
|
-
|
|
156
146
|
var polygonIndices = [];
|
|
157
147
|
for (var i = 1; i < ringIndices.length; i++) {
|
|
158
148
|
var startRingIndex = ringIndices[i - 1];
|
|
159
149
|
var endRingIndex = ringIndices[i];
|
|
160
150
|
var ring = xyPositions.subarray(startRingIndex * 2, endRingIndex * 2);
|
|
161
151
|
var sign = getWindingDirection(ring);
|
|
162
|
-
|
|
163
152
|
if (sign > 0) {
|
|
164
153
|
polygonIndices.push(startRingIndex);
|
|
165
154
|
}
|
|
@@ -181,13 +170,11 @@ function parsePoly(view, offset, dim, type) {
|
|
|
181
170
|
}
|
|
182
171
|
};
|
|
183
172
|
}
|
|
184
|
-
|
|
185
173
|
function parsePositions(view, offset, nPoints, dim) {
|
|
186
174
|
var bufferOffset = view.byteOffset + offset;
|
|
187
175
|
var bufferLength = nPoints * dim * Float64Array.BYTES_PER_ELEMENT;
|
|
188
176
|
return [new Float64Array(view.buffer.slice(bufferOffset, bufferOffset + bufferLength)), offset + bufferLength];
|
|
189
177
|
}
|
|
190
|
-
|
|
191
178
|
function concatPositions(xyPositions, mPositions, zPositions) {
|
|
192
179
|
if (!(mPositions || zPositions)) {
|
|
193
180
|
return xyPositions;
|
|
@@ -219,14 +206,11 @@ function concatPositions(xyPositions, mPositions, zPositions) {
|
|
|
219
206
|
}
|
|
220
207
|
return positions;
|
|
221
208
|
}
|
|
222
|
-
|
|
223
209
|
function getWindingDirection(positions) {
|
|
224
210
|
return Math.sign(getSignedArea(positions));
|
|
225
211
|
}
|
|
226
|
-
|
|
227
212
|
function getSignedArea(positions) {
|
|
228
213
|
var area = 0;
|
|
229
|
-
|
|
230
214
|
var nCoords = positions.length / 2 - 1;
|
|
231
215
|
for (var i = 0; i < nCoords; i++) {
|
|
232
216
|
area += (positions[i * 2] + positions[(i + 1) * 2]) * (positions[i * 2 + 1] - positions[(i + 1) * 2 + 1]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-shp-geometry.js","names":["LITTLE_ENDIAN","parseRecord","view","options","shp","_maxDimensions","offset","type","getInt32","Int32Array","BYTES_PER_ELEMENT","parseNull","parsePoint","Math","min","parsePoly","parseMultiPoint","Error","dim","positions","parsePositions","value","size","Float64Array","nPoints","xyPositions","mPositions","zPositions","concatPositions","nParts","bufferOffset","byteOffset","bufferLength","ringIndices","set","buffer","slice","pathIndices","polygonIndices","i","length","startRingIndex","endRingIndex","ring","subarray","sign","getWindingDirection","push","primitivePolygonIndices","Uint32Array","arrayLength","nDim","getSignedArea","area","nCoords"],"sources":["../../../../src/lib/parsers/parse-shp-geometry.ts"],"sourcesContent":["import {BinaryGeometry, BinaryGeometryType} from '@loaders.gl/schema';\nimport {SHPLoaderOptions} from './types';\n\nconst LITTLE_ENDIAN = true;\n\n/**\n * Parse individual record\n *\n * @param view Record data\n * @return Binary Geometry Object\n */\n// eslint-disable-next-line complexity\nexport function parseRecord(view: DataView, options?: SHPLoaderOptions): BinaryGeometry | null {\n const {_maxDimensions = 4} = options?.shp || {};\n\n let offset = 0;\n const type: number = view.getInt32(offset, LITTLE_ENDIAN);\n offset += Int32Array.BYTES_PER_ELEMENT;\n\n switch (type) {\n case 0:\n // Null Shape\n return parseNull();\n case 1:\n // Point\n return parsePoint(view, offset, Math.min(2, _maxDimensions));\n case 3:\n // PolyLine\n return parsePoly(view, offset, Math.min(2, _maxDimensions), 'LineString');\n case 5:\n // Polygon\n return parsePoly(view, offset, Math.min(2, _maxDimensions), 'Polygon');\n case 8:\n // MultiPoint\n return parseMultiPoint(view, offset, Math.min(2, _maxDimensions));\n // GeometryZ can have 3 or 4 dimensions, since the M is not required to\n // exist\n case 11:\n // PointZ\n return parsePoint(view, offset, Math.min(4, _maxDimensions));\n case 13:\n // PolyLineZ\n return parsePoly(view, offset, Math.min(4, _maxDimensions), 'LineString');\n case 15:\n // PolygonZ\n return parsePoly(view, offset, Math.min(4, _maxDimensions), 'Polygon');\n case 18:\n // MultiPointZ\n return parseMultiPoint(view, offset, Math.min(4, _maxDimensions));\n case 21:\n // PointM\n return parsePoint(view, offset, Math.min(3, _maxDimensions));\n case 23:\n // PolyLineM\n return parsePoly(view, offset, Math.min(3, _maxDimensions), 'LineString');\n case 25:\n // PolygonM\n return parsePoly(view, offset, Math.min(3, _maxDimensions), 'Polygon');\n case 28:\n // MultiPointM\n return parseMultiPoint(view, offset, Math.min(3, _maxDimensions));\n default:\n throw new Error(`unsupported shape type: ${type}`);\n }\n}\n\n// TODO handle null\n/**\n * Parse Null geometry\n *\n * @return null\n */\nfunction parseNull(): null {\n return null;\n}\n\n/**\n * Parse point geometry\n *\n * @param view Geometry data\n * @param offset Offset in view\n * @param dim Dimension size\n */\nfunction parsePoint(view: DataView, offset: number, dim: number): BinaryGeometry {\n let positions: Float64Array;\n [positions, offset] = parsePositions(view, offset, 1, dim);\n\n return {\n positions: {value: positions, size: dim},\n type: 'Point'\n };\n}\n\n/**\n * Parse MultiPoint geometry\n *\n * @param view Geometry data\n * @param offset Offset in view\n * @param dim Input dimension\n * @return Binary geometry object\n */\nfunction parseMultiPoint(view: DataView, offset: number, dim: number): BinaryGeometry {\n // skip parsing box\n offset += 4 * Float64Array.BYTES_PER_ELEMENT;\n\n const nPoints = view.getInt32(offset, LITTLE_ENDIAN);\n offset += Int32Array.BYTES_PER_ELEMENT;\n\n let xyPositions: Float64Array | null = null;\n let mPositions: Float64Array | null = null;\n let zPositions: Float64Array | null = null;\n [xyPositions, offset] = parsePositions(view, offset, nPoints, 2);\n\n // Parse Z coordinates\n if (dim === 4) {\n // skip parsing range\n offset += 2 * Float64Array.BYTES_PER_ELEMENT;\n [zPositions, offset] = parsePositions(view, offset, nPoints, 1);\n }\n\n // Parse M coordinates\n if (dim >= 3) {\n // skip parsing range\n offset += 2 * Float64Array.BYTES_PER_ELEMENT;\n [mPositions, offset] = parsePositions(view, offset, nPoints, 1);\n }\n\n const positions = concatPositions(xyPositions, mPositions, zPositions);\n\n return {\n positions: {value: positions, size: dim},\n type: 'Point'\n };\n}\n\n/**\n * Polygon and PolyLine parsing\n *\n * @param view Geometry data\n * @param offset Offset in view\n * @param dim Input dimension\n * @param type Either 'Polygon' or 'Polyline'\n * @return Binary geometry object\n */\n// eslint-disable-next-line max-statements\nfunction parsePoly(\n view: DataView,\n offset: number,\n dim: number,\n type: BinaryGeometryType\n): BinaryGeometry {\n // skip parsing bounding box\n offset += 4 * Float64Array.BYTES_PER_ELEMENT;\n\n const nParts = view.getInt32(offset, LITTLE_ENDIAN);\n offset += Int32Array.BYTES_PER_ELEMENT;\n const nPoints = view.getInt32(offset, LITTLE_ENDIAN);\n offset += Int32Array.BYTES_PER_ELEMENT;\n\n // Create longer indices array by 1 because output format is expected to\n // include the last index as the total number of positions\n const bufferOffset = view.byteOffset + offset;\n const bufferLength = nParts * Int32Array.BYTES_PER_ELEMENT;\n const ringIndices = new Int32Array(nParts + 1);\n ringIndices.set(new Int32Array(view.buffer.slice(bufferOffset, bufferOffset + bufferLength)));\n ringIndices[nParts] = nPoints;\n offset += nParts * Int32Array.BYTES_PER_ELEMENT;\n\n let xyPositions: Float64Array | null = null;\n let mPositions: Float64Array | null = null;\n let zPositions: Float64Array | null = null;\n [xyPositions, offset] = parsePositions(view, offset, nPoints, 2);\n\n // Parse Z coordinates\n if (dim === 4) {\n // skip parsing range\n offset += 2 * Float64Array.BYTES_PER_ELEMENT;\n [zPositions, offset] = parsePositions(view, offset, nPoints, 1);\n }\n\n // Parse M coordinates\n if (dim >= 3) {\n // skip parsing range\n offset += 2 * Float64Array.BYTES_PER_ELEMENT;\n [mPositions, offset] = parsePositions(view, offset, nPoints, 1);\n }\n\n const positions = concatPositions(xyPositions, mPositions, zPositions);\n\n // parsePoly only accepts type = LineString or Polygon\n if (type === 'LineString') {\n return {\n type,\n positions: {value: positions, size: dim},\n pathIndices: {value: ringIndices, size: 1}\n };\n }\n\n // for every ring, determine sign of polygon\n // Use only 2D positions for ring calc\n const polygonIndices: number[] = [];\n for (let i = 1; i < ringIndices.length; i++) {\n const startRingIndex = ringIndices[i - 1];\n const endRingIndex = ringIndices[i];\n // @ts-ignore\n const ring = xyPositions.subarray(startRingIndex * 2, endRingIndex * 2);\n const sign = getWindingDirection(ring);\n\n // A positive sign implies clockwise\n // A clockwise ring is a filled ring\n if (sign > 0) {\n polygonIndices.push(startRingIndex);\n }\n }\n\n polygonIndices.push(nPoints);\n\n return {\n type,\n positions: {value: positions, size: dim},\n primitivePolygonIndices: {value: ringIndices, size: 1},\n // TODO: Dynamically choose Uint32Array over Uint16Array only when\n // necessary. I believe the implementation requires nPoints to be the\n // largest value in the array, so you should be able to use Uint32Array only\n // when nPoints > 65535.\n polygonIndices: {value: new Uint32Array(polygonIndices), size: 1}\n };\n}\n\n/**\n * Parse a contiguous block of positions into a Float64Array\n *\n * @param view Geometry data\n * @param offset Offset in view\n * @param nPoints Number of points\n * @param dim Input dimension\n * @return Data and offset\n */\nfunction parsePositions(\n view: DataView,\n offset: number,\n nPoints: number,\n dim: number\n): [Float64Array, number] {\n const bufferOffset = view.byteOffset + offset;\n const bufferLength = nPoints * dim * Float64Array.BYTES_PER_ELEMENT;\n return [\n new Float64Array(view.buffer.slice(bufferOffset, bufferOffset + bufferLength)),\n offset + bufferLength\n ];\n}\n\n/**\n * Concatenate and interleave positions arrays\n * xy positions are interleaved; mPositions, zPositions are their own arrays\n *\n * @param xyPositions 2d positions\n * @param mPositions M positions\n * @param zPositions Z positions\n * @return Combined interleaved positions\n */\n// eslint-disable-next-line complexity\nfunction concatPositions(\n xyPositions: Float64Array,\n mPositions: Float64Array | null,\n zPositions: Float64Array | null\n): Float64Array {\n if (!(mPositions || zPositions)) {\n return xyPositions;\n }\n\n let arrayLength = xyPositions.length;\n let nDim = 2;\n\n if (zPositions && zPositions.length) {\n arrayLength += zPositions.length;\n nDim++;\n }\n\n if (mPositions && mPositions.length) {\n arrayLength += mPositions.length;\n nDim++;\n }\n\n const positions = new Float64Array(arrayLength);\n for (let i = 0; i < xyPositions.length / 2; i++) {\n positions[nDim * i] = xyPositions[i * 2];\n positions[nDim * i + 1] = xyPositions[i * 2 + 1];\n }\n\n if (zPositions && zPositions.length) {\n for (let i = 0; i < zPositions.length; i++) {\n // If Z coordinates exist; used as third coord in positions array\n positions[nDim * i + 2] = zPositions[i];\n }\n }\n\n if (mPositions && mPositions.length) {\n for (let i = 0; i < mPositions.length; i++) {\n // M is always last, either 3rd or 4th depending on if Z exists\n positions[nDim * i + (nDim - 1)] = mPositions[i];\n }\n }\n\n return positions;\n}\n\n/**\n * Returns the direction of the polygon path\n * A positive number is clockwise.\n * A negative number is counter clockwise.\n *\n * @param positions\n * @return Sign of polygon ring\n */\nfunction getWindingDirection(positions: Float64Array): number {\n return Math.sign(getSignedArea(positions));\n}\n\n/**\n * Get signed area of flat typed array of 2d positions\n *\n * @param positions\n * @return Signed area of polygon ring\n */\nfunction getSignedArea(positions: Float64Array): number {\n let area = 0;\n\n // Rings are closed according to shapefile spec\n const nCoords = positions.length / 2 - 1;\n for (let i = 0; i < nCoords; i++) {\n area +=\n (positions[i * 2] + positions[(i + 1) * 2]) *\n (positions[i * 2 + 1] - positions[(i + 1) * 2 + 1]);\n }\n\n return area / 2;\n}\n"],"mappings":";;;;;;;;AAGA,IAAMA,aAAa,GAAG,IAAI;;AASnB,SAASC,WAAW,CAACC,IAAc,EAAEC,OAA0B,EAAyB;EAC7F,WAA6B,CAAAA,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEC,GAAG,KAAI,CAAC,CAAC;IAAA,2BAAxCC,cAAc;IAAdA,cAAc,oCAAG,CAAC;EAEzB,IAAIC,MAAM,GAAG,CAAC;EACd,IAAMC,IAAY,GAAGL,IAAI,CAACM,QAAQ,CAACF,MAAM,EAAEN,aAAa,CAAC;EACzDM,MAAM,IAAIG,UAAU,CAACC,iBAAiB;EAEtC,QAAQH,IAAI;IACV,KAAK,CAAC;MAEJ,OAAOI,SAAS,EAAE;IACpB,KAAK,CAAC;MAEJ,OAAOC,UAAU,CAACV,IAAI,EAAEI,MAAM,EAAEO,IAAI,CAACC,GAAG,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AEA,OAAOpB,SAAS;AAClB;;AAUA,SAAS2B,mBAAmB,CAAC3B,SAAuB,EAAU;EAC5D,OAAON,IAAI,CAACgC,IAAI,CAACO,aAAa,CAACjC,SAAS,CAAC,CAAC;AAC5C;;AAQA,SAASiC,aAAa,CAACjC,SAAuB,EAAU;EACtD,IAAIkC,IAAI,GAAG,CAAC;;EAGZ,IAAMC,OAAO,GAAGnC,SAAS,CAACqB,MAAM,GAAG,CAAC,GAAG,CAAC;EACxC,KAAK,IAAID,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGe,OAAO,EAAEf,CAAC,EAAE,EAAE;IAChCc,IAAI,IACF,CAAClC,SAAS,CAACoB,CAAC,GAAG,CAAC,CAAC,GAAGpB,SAAS,CAAC,CAACoB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,KACzCpB,SAAS,CAACoB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAGpB,SAAS,CAAC,CAACoB,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;EACvD;EAEA,OAAOc,IAAI,GAAG,CAAC;AACjB"}
|
|
1
|
+
{"version":3,"file":"parse-shp-geometry.js","names":["LITTLE_ENDIAN","parseRecord","view","options","_ref","shp","_ref$_maxDimensions","_maxDimensions","offset","type","getInt32","Int32Array","BYTES_PER_ELEMENT","parseNull","parsePoint","Math","min","parsePoly","parseMultiPoint","Error","concat","dim","positions","_parsePositions","parsePositions","_parsePositions2","_slicedToArray2","default","value","size","Float64Array","nPoints","xyPositions","mPositions","zPositions","_parsePositions3","_parsePositions4","_parsePositions5","_parsePositions6","_parsePositions7","_parsePositions8","concatPositions","nParts","bufferOffset","byteOffset","bufferLength","ringIndices","set","buffer","slice","_parsePositions9","_parsePositions10","_parsePositions11","_parsePositions12","_parsePositions13","_parsePositions14","pathIndices","polygonIndices","i","length","startRingIndex","endRingIndex","ring","subarray","sign","getWindingDirection","push","primitivePolygonIndices","Uint32Array","arrayLength","nDim","getSignedArea","area","nCoords"],"sources":["../../../../src/lib/parsers/parse-shp-geometry.ts"],"sourcesContent":["import {BinaryGeometry, BinaryGeometryType} from '@loaders.gl/schema';\nimport {SHPLoaderOptions} from './types';\n\nconst LITTLE_ENDIAN = true;\n\n/**\n * Parse individual record\n *\n * @param view Record data\n * @return Binary Geometry Object\n */\n// eslint-disable-next-line complexity\nexport function parseRecord(view: DataView, options?: SHPLoaderOptions): BinaryGeometry | null {\n const {_maxDimensions = 4} = options?.shp || {};\n\n let offset = 0;\n const type: number = view.getInt32(offset, LITTLE_ENDIAN);\n offset += Int32Array.BYTES_PER_ELEMENT;\n\n switch (type) {\n case 0:\n // Null Shape\n return parseNull();\n case 1:\n // Point\n return parsePoint(view, offset, Math.min(2, _maxDimensions));\n case 3:\n // PolyLine\n return parsePoly(view, offset, Math.min(2, _maxDimensions), 'LineString');\n case 5:\n // Polygon\n return parsePoly(view, offset, Math.min(2, _maxDimensions), 'Polygon');\n case 8:\n // MultiPoint\n return parseMultiPoint(view, offset, Math.min(2, _maxDimensions));\n // GeometryZ can have 3 or 4 dimensions, since the M is not required to\n // exist\n case 11:\n // PointZ\n return parsePoint(view, offset, Math.min(4, _maxDimensions));\n case 13:\n // PolyLineZ\n return parsePoly(view, offset, Math.min(4, _maxDimensions), 'LineString');\n case 15:\n // PolygonZ\n return parsePoly(view, offset, Math.min(4, _maxDimensions), 'Polygon');\n case 18:\n // MultiPointZ\n return parseMultiPoint(view, offset, Math.min(4, _maxDimensions));\n case 21:\n // PointM\n return parsePoint(view, offset, Math.min(3, _maxDimensions));\n case 23:\n // PolyLineM\n return parsePoly(view, offset, Math.min(3, _maxDimensions), 'LineString');\n case 25:\n // PolygonM\n return parsePoly(view, offset, Math.min(3, _maxDimensions), 'Polygon');\n case 28:\n // MultiPointM\n return parseMultiPoint(view, offset, Math.min(3, _maxDimensions));\n default:\n throw new Error(`unsupported shape type: ${type}`);\n }\n}\n\n// TODO handle null\n/**\n * Parse Null geometry\n *\n * @return null\n */\nfunction parseNull(): null {\n return null;\n}\n\n/**\n * Parse point geometry\n *\n * @param view Geometry data\n * @param offset Offset in view\n * @param dim Dimension size\n */\nfunction parsePoint(view: DataView, offset: number, dim: number): BinaryGeometry {\n let positions: Float64Array;\n [positions, offset] = parsePositions(view, offset, 1, dim);\n\n return {\n positions: {value: positions, size: dim},\n type: 'Point'\n };\n}\n\n/**\n * Parse MultiPoint geometry\n *\n * @param view Geometry data\n * @param offset Offset in view\n * @param dim Input dimension\n * @return Binary geometry object\n */\nfunction parseMultiPoint(view: DataView, offset: number, dim: number): BinaryGeometry {\n // skip parsing box\n offset += 4 * Float64Array.BYTES_PER_ELEMENT;\n\n const nPoints = view.getInt32(offset, LITTLE_ENDIAN);\n offset += Int32Array.BYTES_PER_ELEMENT;\n\n let xyPositions: Float64Array | null = null;\n let mPositions: Float64Array | null = null;\n let zPositions: Float64Array | null = null;\n [xyPositions, offset] = parsePositions(view, offset, nPoints, 2);\n\n // Parse Z coordinates\n if (dim === 4) {\n // skip parsing range\n offset += 2 * Float64Array.BYTES_PER_ELEMENT;\n [zPositions, offset] = parsePositions(view, offset, nPoints, 1);\n }\n\n // Parse M coordinates\n if (dim >= 3) {\n // skip parsing range\n offset += 2 * Float64Array.BYTES_PER_ELEMENT;\n [mPositions, offset] = parsePositions(view, offset, nPoints, 1);\n }\n\n const positions = concatPositions(xyPositions, mPositions, zPositions);\n\n return {\n positions: {value: positions, size: dim},\n type: 'Point'\n };\n}\n\n/**\n * Polygon and PolyLine parsing\n *\n * @param view Geometry data\n * @param offset Offset in view\n * @param dim Input dimension\n * @param type Either 'Polygon' or 'Polyline'\n * @return Binary geometry object\n */\n// eslint-disable-next-line max-statements\nfunction parsePoly(\n view: DataView,\n offset: number,\n dim: number,\n type: BinaryGeometryType\n): BinaryGeometry {\n // skip parsing bounding box\n offset += 4 * Float64Array.BYTES_PER_ELEMENT;\n\n const nParts = view.getInt32(offset, LITTLE_ENDIAN);\n offset += Int32Array.BYTES_PER_ELEMENT;\n const nPoints = view.getInt32(offset, LITTLE_ENDIAN);\n offset += Int32Array.BYTES_PER_ELEMENT;\n\n // Create longer indices array by 1 because output format is expected to\n // include the last index as the total number of positions\n const bufferOffset = view.byteOffset + offset;\n const bufferLength = nParts * Int32Array.BYTES_PER_ELEMENT;\n const ringIndices = new Int32Array(nParts + 1);\n ringIndices.set(new Int32Array(view.buffer.slice(bufferOffset, bufferOffset + bufferLength)));\n ringIndices[nParts] = nPoints;\n offset += nParts * Int32Array.BYTES_PER_ELEMENT;\n\n let xyPositions: Float64Array | null = null;\n let mPositions: Float64Array | null = null;\n let zPositions: Float64Array | null = null;\n [xyPositions, offset] = parsePositions(view, offset, nPoints, 2);\n\n // Parse Z coordinates\n if (dim === 4) {\n // skip parsing range\n offset += 2 * Float64Array.BYTES_PER_ELEMENT;\n [zPositions, offset] = parsePositions(view, offset, nPoints, 1);\n }\n\n // Parse M coordinates\n if (dim >= 3) {\n // skip parsing range\n offset += 2 * Float64Array.BYTES_PER_ELEMENT;\n [mPositions, offset] = parsePositions(view, offset, nPoints, 1);\n }\n\n const positions = concatPositions(xyPositions, mPositions, zPositions);\n\n // parsePoly only accepts type = LineString or Polygon\n if (type === 'LineString') {\n return {\n type,\n positions: {value: positions, size: dim},\n pathIndices: {value: ringIndices, size: 1}\n };\n }\n\n // for every ring, determine sign of polygon\n // Use only 2D positions for ring calc\n const polygonIndices: number[] = [];\n for (let i = 1; i < ringIndices.length; i++) {\n const startRingIndex = ringIndices[i - 1];\n const endRingIndex = ringIndices[i];\n // @ts-ignore\n const ring = xyPositions.subarray(startRingIndex * 2, endRingIndex * 2);\n const sign = getWindingDirection(ring);\n\n // A positive sign implies clockwise\n // A clockwise ring is a filled ring\n if (sign > 0) {\n polygonIndices.push(startRingIndex);\n }\n }\n\n polygonIndices.push(nPoints);\n\n return {\n type,\n positions: {value: positions, size: dim},\n primitivePolygonIndices: {value: ringIndices, size: 1},\n // TODO: Dynamically choose Uint32Array over Uint16Array only when\n // necessary. I believe the implementation requires nPoints to be the\n // largest value in the array, so you should be able to use Uint32Array only\n // when nPoints > 65535.\n polygonIndices: {value: new Uint32Array(polygonIndices), size: 1}\n };\n}\n\n/**\n * Parse a contiguous block of positions into a Float64Array\n *\n * @param view Geometry data\n * @param offset Offset in view\n * @param nPoints Number of points\n * @param dim Input dimension\n * @return Data and offset\n */\nfunction parsePositions(\n view: DataView,\n offset: number,\n nPoints: number,\n dim: number\n): [Float64Array, number] {\n const bufferOffset = view.byteOffset + offset;\n const bufferLength = nPoints * dim * Float64Array.BYTES_PER_ELEMENT;\n return [\n new Float64Array(view.buffer.slice(bufferOffset, bufferOffset + bufferLength)),\n offset + bufferLength\n ];\n}\n\n/**\n * Concatenate and interleave positions arrays\n * xy positions are interleaved; mPositions, zPositions are their own arrays\n *\n * @param xyPositions 2d positions\n * @param mPositions M positions\n * @param zPositions Z positions\n * @return Combined interleaved positions\n */\n// eslint-disable-next-line complexity\nfunction concatPositions(\n xyPositions: Float64Array,\n mPositions: Float64Array | null,\n zPositions: Float64Array | null\n): Float64Array {\n if (!(mPositions || zPositions)) {\n return xyPositions;\n }\n\n let arrayLength = xyPositions.length;\n let nDim = 2;\n\n if (zPositions && zPositions.length) {\n arrayLength += zPositions.length;\n nDim++;\n }\n\n if (mPositions && mPositions.length) {\n arrayLength += mPositions.length;\n nDim++;\n }\n\n const positions = new Float64Array(arrayLength);\n for (let i = 0; i < xyPositions.length / 2; i++) {\n positions[nDim * i] = xyPositions[i * 2];\n positions[nDim * i + 1] = xyPositions[i * 2 + 1];\n }\n\n if (zPositions && zPositions.length) {\n for (let i = 0; i < zPositions.length; i++) {\n // If Z coordinates exist; used as third coord in positions array\n positions[nDim * i + 2] = zPositions[i];\n }\n }\n\n if (mPositions && mPositions.length) {\n for (let i = 0; i < mPositions.length; i++) {\n // M is always last, either 3rd or 4th depending on if Z exists\n positions[nDim * i + (nDim - 1)] = mPositions[i];\n }\n }\n\n return positions;\n}\n\n/**\n * Returns the direction of the polygon path\n * A positive number is clockwise.\n * A negative number is counter clockwise.\n *\n * @param positions\n * @return Sign of polygon ring\n */\nfunction getWindingDirection(positions: Float64Array): number {\n return Math.sign(getSignedArea(positions));\n}\n\n/**\n * Get signed area of flat typed array of 2d positions\n *\n * @param positions\n * @return Signed area of polygon ring\n */\nfunction getSignedArea(positions: Float64Array): number {\n let area = 0;\n\n // Rings are closed according to shapefile spec\n const nCoords = positions.length / 2 - 1;\n for (let i = 0; i < nCoords; i++) {\n area +=\n (positions[i * 2] + positions[(i + 1) * 2]) *\n (positions[i * 2 + 1] - positions[(i + 1) * 2 + 1]);\n }\n\n return area / 2;\n}\n"],"mappings":";;;;;;;;AAGA,IAAMA,aAAa,GAAG,IAAI;AASnB,SAASC,WAAWA,CAACC,IAAc,EAAEC,OAA0B,EAAyB;EAC7F,IAAAC,IAAA,GAA6B,CAAAD,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEE,GAAG,KAAI,CAAC,CAAC;IAAAC,mBAAA,GAAAF,IAAA,CAAxCG,cAAc;IAAdA,cAAc,GAAAD,mBAAA,cAAG,CAAC,GAAAA,mBAAA;EAEzB,IAAIE,MAAM,GAAG,CAAC;EACd,IAAMC,IAAY,GAAGP,IAAI,CAACQ,QAAQ,CAACF,MAAM,EAAER,aAAa,CAAC;EACzDQ,MAAM,IAAIG,UAAU,CAACC,iBAAiB;EAEtC,QAAQH,IAAI;IACV,KAAK,CAAC;MAEJ,OAAOI,SAAS,CAAC,CAAC;IACpB,KAAK,CAAC;MAEJ,OAAOC,UAAU,CAACZ,IAAI,EAAEM,MAAM,EAAEO,IAAI,CAACC,GAAG,CAAC,CAAC,EAAET,cAAc,CAAC,CAAC;IAC9D,KAAK,CAAC;MAEJ,OAAOU,SAAS,CAACf,IAAI,EAAEM,MAAM,EAAEO,IAAI,CAACC,GAAG,CAAC,CAAC,EAAET,cAAc,CAAC,EAAE,YAAY,CAAC;IAC3E,KAAK,CAAC;MAEJ,OAAOU,SAAS,CAACf,IAAI,EAAEM,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AAOc,IAAI,GAAG,CAAC;AACjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-shp-header.js","names":["LITTLE_ENDIAN","BIG_ENDIAN","SHP_MAGIC_NUMBER","parseSHPHeader","headerView","header","magic","getInt32","length","version","type","bbox","minX","getFloat64","minY","minZ","minM","maxX","maxY","maxZ","maxM","console","error"],"sources":["../../../../src/lib/parsers/parse-shp-header.ts"],"sourcesContent":["export interface SHPHeader {\n /** SHP Magic number */\n magic: number;\n\n /** Number of bytes in file */\n length: number;\n version: number;\n type: number;\n bbox: {\n minX: number;\n minY: number;\n minZ: number;\n minM: number;\n maxX: number;\n maxY: number;\n maxZ: number;\n maxM: number;\n };\n}\n\nconst LITTLE_ENDIAN = true;\nconst BIG_ENDIAN = false;\nconst SHP_MAGIC_NUMBER = 0x0000270a;\n\n/**\n * Extract the binary header\n * Note: Also used by SHX\n * @param headerView\n * @returns SHPHeader\n */\nexport function parseSHPHeader(headerView: DataView): SHPHeader {\n // Note: The SHP format switches endianness between fields!\n // https://www.esri.com/library/whitepapers/pdfs/shapefile.pdf\n const header = {\n magic: headerView.getInt32(0, BIG_ENDIAN),\n // Length is stored as # of 2-byte words; multiply by 2 to get # of bytes\n length: headerView.getInt32(24, BIG_ENDIAN) * 2,\n version: headerView.getInt32(28, LITTLE_ENDIAN),\n type: headerView.getInt32(32, LITTLE_ENDIAN),\n bbox: {\n minX: headerView.getFloat64(36, LITTLE_ENDIAN),\n minY: headerView.getFloat64(44, LITTLE_ENDIAN),\n minZ: headerView.getFloat64(68, LITTLE_ENDIAN),\n minM: headerView.getFloat64(84, LITTLE_ENDIAN),\n maxX: headerView.getFloat64(52, LITTLE_ENDIAN),\n maxY: headerView.getFloat64(60, LITTLE_ENDIAN),\n maxZ: headerView.getFloat64(76, LITTLE_ENDIAN),\n maxM: headerView.getFloat64(92, LITTLE_ENDIAN)\n }\n };\n if (header.magic !== SHP_MAGIC_NUMBER) {\n // eslint-disable-next-line\n console.error(`SHP file: bad magic number ${header.magic}`);\n }\n if (header.version !== 1000) {\n // eslint-disable-next-line\n console.error(`SHP file: bad version ${header.version}`);\n }\n return header;\n}\n"],"mappings":";;;;;;AAoBA,IAAMA,aAAa,GAAG,IAAI;AAC1B,IAAMC,UAAU,GAAG,KAAK;AACxB,IAAMC,gBAAgB,GAAG,UAAU
|
|
1
|
+
{"version":3,"file":"parse-shp-header.js","names":["LITTLE_ENDIAN","BIG_ENDIAN","SHP_MAGIC_NUMBER","parseSHPHeader","headerView","header","magic","getInt32","length","version","type","bbox","minX","getFloat64","minY","minZ","minM","maxX","maxY","maxZ","maxM","console","error","concat"],"sources":["../../../../src/lib/parsers/parse-shp-header.ts"],"sourcesContent":["export interface SHPHeader {\n /** SHP Magic number */\n magic: number;\n\n /** Number of bytes in file */\n length: number;\n version: number;\n type: number;\n bbox: {\n minX: number;\n minY: number;\n minZ: number;\n minM: number;\n maxX: number;\n maxY: number;\n maxZ: number;\n maxM: number;\n };\n}\n\nconst LITTLE_ENDIAN = true;\nconst BIG_ENDIAN = false;\nconst SHP_MAGIC_NUMBER = 0x0000270a;\n\n/**\n * Extract the binary header\n * Note: Also used by SHX\n * @param headerView\n * @returns SHPHeader\n */\nexport function parseSHPHeader(headerView: DataView): SHPHeader {\n // Note: The SHP format switches endianness between fields!\n // https://www.esri.com/library/whitepapers/pdfs/shapefile.pdf\n const header = {\n magic: headerView.getInt32(0, BIG_ENDIAN),\n // Length is stored as # of 2-byte words; multiply by 2 to get # of bytes\n length: headerView.getInt32(24, BIG_ENDIAN) * 2,\n version: headerView.getInt32(28, LITTLE_ENDIAN),\n type: headerView.getInt32(32, LITTLE_ENDIAN),\n bbox: {\n minX: headerView.getFloat64(36, LITTLE_ENDIAN),\n minY: headerView.getFloat64(44, LITTLE_ENDIAN),\n minZ: headerView.getFloat64(68, LITTLE_ENDIAN),\n minM: headerView.getFloat64(84, LITTLE_ENDIAN),\n maxX: headerView.getFloat64(52, LITTLE_ENDIAN),\n maxY: headerView.getFloat64(60, LITTLE_ENDIAN),\n maxZ: headerView.getFloat64(76, LITTLE_ENDIAN),\n maxM: headerView.getFloat64(92, LITTLE_ENDIAN)\n }\n };\n if (header.magic !== SHP_MAGIC_NUMBER) {\n // eslint-disable-next-line\n console.error(`SHP file: bad magic number ${header.magic}`);\n }\n if (header.version !== 1000) {\n // eslint-disable-next-line\n console.error(`SHP file: bad version ${header.version}`);\n }\n return header;\n}\n"],"mappings":";;;;;;AAoBA,IAAMA,aAAa,GAAG,IAAI;AAC1B,IAAMC,UAAU,GAAG,KAAK;AACxB,IAAMC,gBAAgB,GAAG,UAAU;AAQ5B,SAASC,cAAcA,CAACC,UAAoB,EAAa;EAG9D,IAAMC,MAAM,GAAG;IACbC,KAAK,EAAEF,UAAU,CAACG,QAAQ,CAAC,CAAC,EAAEN,UAAU,CAAC;IAEzCO,MAAM,EAAEJ,UAAU,CAACG,QAAQ,CAAC,EAAE,EAAEN,UAAU,CAAC,GAAG,CAAC;IAC/CQ,OAAO,EAAEL,UAAU,CAACG,QAAQ,CAAC,EAAE,EAAEP,aAAa,CAAC;IAC/CU,IAAI,EAAEN,UAAU,CAACG,QAAQ,CAAC,EAAE,EAAEP,aAAa,CAAC;IAC5CW,IAAI,EAAE;MACJC,IAAI,EAAER,UAAU,CAACS,UAAU,CAAC,EAAE,EAAEb,aAAa,CAAC;MAC9Cc,IAAI,EAAEV,UAAU,CAACS,UAAU,CAAC,EAAE,EAAEb,aAAa,CAAC;MAC9Ce,IAAI,EAAEX,UAAU,CAACS,UAAU,CAAC,EAAE,EAAEb,aAAa,CAAC;MAC9CgB,IAAI,EAAEZ,UAAU,CAACS,UAAU,CAAC,EAAE,EAAEb,aAAa,CAAC;MAC9CiB,IAAI,EAAEb,UAAU,CAACS,UAAU,CAAC,EAAE,EAAEb,aAAa,CAAC;MAC9CkB,IAAI,EAAEd,UAAU,CAACS,UAAU,CAAC,EAAE,EAAEb,aAAa,CAAC;MAC9CmB,IAAI,EAAEf,UAAU,CAACS,UAAU,CAAC,EAAE,EAAEb,aAAa,CAAC;MAC9CoB,IAAI,EAAEhB,UAAU,CAACS,UAAU,CAAC,EAAE,EAAEb,aAAa;IAC/C;EACF,CAAC;EACD,IAAIK,MAAM,CAACC,KAAK,KAAKJ,gBAAgB,EAAE;IAErCmB,OAAO,CAACC,KAAK,+BAAAC,MAAA,CAA+BlB,MAAM,CAACC,KAAK,CAAE,CAAC;EAC7D;EACA,IAAID,MAAM,CAACI,OAAO,KAAK,IAAI,EAAE;IAE3BY,OAAO,CAACC,KAAK,0BAAAC,MAAA,CAA0BlB,MAAM,CAACI,OAAO,CAAE,CAAC;EAC1D;EACA,OAAOJ,MAAM;AACf"}
|
|
@@ -69,10 +69,8 @@ function parseSHP(arrayBuffer, options) {
|
|
|
69
69
|
var shpParser = new SHPParser(options);
|
|
70
70
|
shpParser.write(arrayBuffer);
|
|
71
71
|
shpParser.end();
|
|
72
|
-
|
|
73
72
|
return shpParser.result;
|
|
74
73
|
}
|
|
75
|
-
|
|
76
74
|
function parseSHPInBatches(_x, _x2) {
|
|
77
75
|
return _parseSHPInBatches.apply(this, arguments);
|
|
78
76
|
}
|
|
@@ -80,87 +78,85 @@ function _parseSHPInBatches() {
|
|
|
80
78
|
_parseSHPInBatches = (0, _wrapAsyncGenerator2.default)(_regenerator.default.mark(function _callee(asyncIterator, options) {
|
|
81
79
|
var parser, headerReturned, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, arrayBuffer;
|
|
82
80
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
83
|
-
while (1) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (!(!headerReturned && parser.result.header)) {
|
|
103
|
-
_context.next = 15;
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
headerReturned = true;
|
|
81
|
+
while (1) switch (_context.prev = _context.next) {
|
|
82
|
+
case 0:
|
|
83
|
+
parser = new SHPParser(options);
|
|
84
|
+
headerReturned = false;
|
|
85
|
+
_iteratorAbruptCompletion = false;
|
|
86
|
+
_didIteratorError = false;
|
|
87
|
+
_context.prev = 4;
|
|
88
|
+
_iterator = _asyncIterator(asyncIterator);
|
|
89
|
+
case 6:
|
|
90
|
+
_context.next = 8;
|
|
91
|
+
return (0, _awaitAsyncGenerator2.default)(_iterator.next());
|
|
92
|
+
case 8:
|
|
93
|
+
if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) {
|
|
94
|
+
_context.next = 22;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
arrayBuffer = _step.value;
|
|
98
|
+
parser.write(arrayBuffer);
|
|
99
|
+
if (!(!headerReturned && parser.result.header)) {
|
|
107
100
|
_context.next = 15;
|
|
108
|
-
return parser.result.header;
|
|
109
|
-
case 15:
|
|
110
|
-
if (!(parser.result.geometries.length > 0)) {
|
|
111
|
-
_context.next = 19;
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
_context.next = 18;
|
|
115
|
-
return parser.result.geometries;
|
|
116
|
-
case 18:
|
|
117
|
-
parser.result.geometries = [];
|
|
118
|
-
case 19:
|
|
119
|
-
_iteratorAbruptCompletion = false;
|
|
120
|
-
_context.next = 6;
|
|
121
101
|
break;
|
|
122
|
-
|
|
123
|
-
|
|
102
|
+
}
|
|
103
|
+
headerReturned = true;
|
|
104
|
+
_context.next = 15;
|
|
105
|
+
return parser.result.header;
|
|
106
|
+
case 15:
|
|
107
|
+
if (!(parser.result.geometries.length > 0)) {
|
|
108
|
+
_context.next = 19;
|
|
124
109
|
break;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
110
|
+
}
|
|
111
|
+
_context.next = 18;
|
|
112
|
+
return parser.result.geometries;
|
|
113
|
+
case 18:
|
|
114
|
+
parser.result.geometries = [];
|
|
115
|
+
case 19:
|
|
116
|
+
_iteratorAbruptCompletion = false;
|
|
117
|
+
_context.next = 6;
|
|
118
|
+
break;
|
|
119
|
+
case 22:
|
|
120
|
+
_context.next = 28;
|
|
121
|
+
break;
|
|
122
|
+
case 24:
|
|
123
|
+
_context.prev = 24;
|
|
124
|
+
_context.t0 = _context["catch"](4);
|
|
125
|
+
_didIteratorError = true;
|
|
126
|
+
_iteratorError = _context.t0;
|
|
127
|
+
case 28:
|
|
128
|
+
_context.prev = 28;
|
|
129
|
+
_context.prev = 29;
|
|
130
|
+
if (!(_iteratorAbruptCompletion && _iterator.return != null)) {
|
|
137
131
|
_context.next = 33;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
_context.next = 33;
|
|
135
|
+
return (0, _awaitAsyncGenerator2.default)(_iterator.return());
|
|
136
|
+
case 33:
|
|
137
|
+
_context.prev = 33;
|
|
138
|
+
if (!_didIteratorError) {
|
|
139
|
+
_context.next = 36;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
throw _iteratorError;
|
|
143
|
+
case 36:
|
|
144
|
+
return _context.finish(33);
|
|
145
|
+
case 37:
|
|
146
|
+
return _context.finish(28);
|
|
147
|
+
case 38:
|
|
148
|
+
parser.end();
|
|
149
|
+
if (!(parser.result.geometries.length > 0)) {
|
|
156
150
|
_context.next = 42;
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
_context.next = 42;
|
|
154
|
+
return parser.result.geometries;
|
|
155
|
+
case 42:
|
|
156
|
+
return _context.abrupt("return");
|
|
157
|
+
case 43:
|
|
158
|
+
case "end":
|
|
159
|
+
return _context.stop();
|
|
164
160
|
}
|
|
165
161
|
}, _callee, null, [[4, 24, 28, 38], [29,, 33, 37]]);
|
|
166
162
|
}));
|
|
@@ -201,7 +197,6 @@ function parseState(state, result, binaryReader, options) {
|
|
|
201
197
|
return state;
|
|
202
198
|
}
|
|
203
199
|
var invalidRecord = recordHeader.byteLength < 4 || recordHeader.type !== ((_result$header = result.header) === null || _result$header === void 0 ? void 0 : _result$header.type) || recordHeader.recordNumber !== result.currentIndex;
|
|
204
|
-
|
|
205
200
|
if (invalidRecord) {
|
|
206
201
|
binaryReader.rewind(SHP_RECORD_HEADER_SIZE - 4);
|
|
207
202
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-shp.js","names":["LITTLE_ENDIAN","BIG_ENDIAN","SHP_HEADER_SIZE","SHP_RECORD_HEADER_SIZE","STATE","EXPECTING_HEADER","EXPECTING_RECORD","END","ERROR","SHPParser","options","BinaryChunkReader","maxRewindBytes","geometries","progress","bytesTotal","NaN","bytesUsed","rows","currentIndex","arrayBuffer","binaryReader","write","state","parseState","result","end","error","parseSHP","shpParser","parseSHPInBatches","asyncIterator","parser","headerReturned","header","length","dataView","getDataView","parseSHPHeader","hasAvailableBytes","recordHeaderView","recordHeader","recordNumber","getInt32","byteLength","type","rewind","invalidRecord","recordView","geometry","parseRecord","push","ended","message"],"sources":["../../../../src/lib/parsers/parse-shp.ts"],"sourcesContent":["import type {BinaryGeometry} from '@loaders.gl/schema';\nimport BinaryChunkReader from '../streaming/binary-chunk-reader';\nimport {parseSHPHeader, SHPHeader} from './parse-shp-header';\nimport {parseRecord} from './parse-shp-geometry';\nimport {SHPLoaderOptions} from './types';\n\nconst LITTLE_ENDIAN = true;\nconst BIG_ENDIAN = false;\n\nconst SHP_HEADER_SIZE = 100;\n// According to the spec, the record header is just 8 bytes, but here we set it\n// to 12 so that we can also access the record's type\nconst SHP_RECORD_HEADER_SIZE = 12;\n\nconst STATE = {\n EXPECTING_HEADER: 0,\n EXPECTING_RECORD: 1,\n END: 2,\n ERROR: 3\n};\n\ntype SHPResult = {\n geometries: (BinaryGeometry | null)[];\n header?: SHPHeader;\n error?: string;\n progress: {\n bytesUsed: number;\n bytesTotal: number;\n rows: number;\n };\n currentIndex: number;\n};\n\nclass SHPParser {\n options?: SHPLoaderOptions = {};\n binaryReader = new BinaryChunkReader({maxRewindBytes: SHP_RECORD_HEADER_SIZE});\n state = STATE.EXPECTING_HEADER;\n result: SHPResult = {\n geometries: [],\n // Initialize with number values to make TS happy\n // These are initialized for real in STATE.EXPECTING_HEADER\n progress: {\n bytesTotal: NaN,\n bytesUsed: NaN,\n rows: NaN\n },\n currentIndex: NaN\n };\n\n constructor(options?: SHPLoaderOptions) {\n this.options = options;\n }\n\n write(arrayBuffer: ArrayBuffer) {\n this.binaryReader.write(arrayBuffer);\n this.state = parseState(this.state, this.result, this.binaryReader, this.options);\n }\n\n end() {\n this.binaryReader.end();\n this.state = parseState(this.state, this.result, this.binaryReader, this.options);\n // this.result.progress.bytesUsed = this.binaryReader.bytesUsed();\n if (this.state !== STATE.END) {\n this.state = STATE.ERROR;\n this.result.error = 'SHP incomplete file';\n }\n }\n}\n\nexport function parseSHP(arrayBuffer: ArrayBuffer, options?: SHPLoaderOptions): BinaryGeometry[] {\n const shpParser = new SHPParser(options);\n shpParser.write(arrayBuffer);\n shpParser.end();\n\n // @ts-ignore\n return shpParser.result;\n}\n\n/**\n * @param asyncIterator\n * @param options\n * @returns\n */\nexport async function* parseSHPInBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options?: SHPLoaderOptions\n): AsyncIterable<BinaryGeometry | object> {\n const parser = new SHPParser(options);\n let headerReturned = false;\n for await (const arrayBuffer of asyncIterator) {\n parser.write(arrayBuffer);\n if (!headerReturned && parser.result.header) {\n headerReturned = true;\n yield parser.result.header;\n }\n\n if (parser.result.geometries.length > 0) {\n yield parser.result.geometries;\n parser.result.geometries = [];\n }\n }\n parser.end();\n if (parser.result.geometries.length > 0) {\n yield parser.result.geometries;\n }\n\n return;\n}\n\n/**\n * State-machine parser for SHP data\n *\n * Note that whenever more data is needed, a `return`, not a `break`, is\n * necessary, as the `break` keeps the context within `parseState`, while\n * `return` releases context so that more data can be written into the\n * BinaryChunkReader.\n *\n * @param state Current state\n * @param result An object to hold result data\n * @param binaryReader\n * @return State at end of current parsing\n */\n/* eslint-disable complexity, max-depth */\nfunction parseState(\n state: number,\n result: SHPResult,\n binaryReader: BinaryChunkReader,\n options?: SHPLoaderOptions\n): number {\n // eslint-disable-next-line no-constant-condition\n while (true) {\n try {\n switch (state) {\n case STATE.ERROR:\n case STATE.END:\n return state;\n\n case STATE.EXPECTING_HEADER:\n // Parse initial file header\n const dataView = binaryReader.getDataView(SHP_HEADER_SIZE);\n if (!dataView) {\n return state;\n }\n\n result.header = parseSHPHeader(dataView);\n result.progress = {\n bytesUsed: 0,\n bytesTotal: result.header.length,\n rows: 0\n };\n // index numbering starts at 1\n result.currentIndex = 1;\n state = STATE.EXPECTING_RECORD;\n break;\n\n case STATE.EXPECTING_RECORD:\n while (binaryReader.hasAvailableBytes(SHP_RECORD_HEADER_SIZE)) {\n const recordHeaderView = binaryReader.getDataView(SHP_RECORD_HEADER_SIZE) as DataView;\n const recordHeader = {\n recordNumber: recordHeaderView.getInt32(0, BIG_ENDIAN),\n // 2 byte words; includes the four words of record header\n byteLength: recordHeaderView.getInt32(4, BIG_ENDIAN) * 2,\n // This is actually part of the record, not the header...\n type: recordHeaderView.getInt32(8, LITTLE_ENDIAN)\n };\n\n if (!binaryReader.hasAvailableBytes(recordHeader.byteLength - 4)) {\n binaryReader.rewind(SHP_RECORD_HEADER_SIZE);\n return state;\n }\n\n const invalidRecord =\n recordHeader.byteLength < 4 ||\n recordHeader.type !== result.header?.type ||\n recordHeader.recordNumber !== result.currentIndex;\n\n // All records must have at least four bytes (for the record shape type)\n if (invalidRecord) {\n // Malformed record, try again, advancing just 4 bytes\n // Note: this is a rewind because binaryReader.getDataView above\n // moved the pointer forward 12 bytes, so rewinding 8 bytes still\n // leaves us 4 bytes ahead\n binaryReader.rewind(SHP_RECORD_HEADER_SIZE - 4);\n } else {\n // Note: type is actually part of the record, not the header, so\n // rewind 4 bytes before reading record\n binaryReader.rewind(4);\n\n const recordView = binaryReader.getDataView(recordHeader.byteLength) as DataView;\n const geometry = parseRecord(recordView, options);\n result.geometries.push(geometry);\n\n result.currentIndex++;\n result.progress.rows = result.currentIndex - 1;\n }\n }\n\n if (binaryReader.ended) {\n state = STATE.END;\n }\n\n return state;\n\n default:\n state = STATE.ERROR;\n result.error = `illegal parser state ${state}`;\n return state;\n }\n } catch (error) {\n state = STATE.ERROR;\n result.error = `SHP parsing failed: ${(error as Error)?.message}`;\n return state;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AACA;AACA;AACA;AAAiD;AAAA;AAGjD,IAAMA,aAAa,GAAG,IAAI;AAC1B,IAAMC,UAAU,GAAG,KAAK;AAExB,IAAMC,eAAe,GAAG,GAAG;AAG3B,IAAMC,sBAAsB,GAAG,EAAE;AAEjC,IAAMC,KAAK,GAAG;EACZC,gBAAgB,EAAE,CAAC;EACnBC,gBAAgB,EAAE,CAAC;EACnBC,GAAG,EAAE,CAAC;EACNC,KAAK,EAAE;AACT,CAAC;AAAC,IAcIC,SAAS;EAgBb,mBAAYC,OAA0B,EAAE;IAAA;IAAA,+CAfX,CAAC,CAAC;IAAA,oDAChB,IAAIC,0BAAiB,CAAC;MAACC,cAAc,EAAET;IAAsB,CAAC,CAAC;IAAA,6CACtEC,KAAK,CAACC,gBAAgB;IA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ACN,YAAY;;YAGnD,IAAI4B,aAAa,EAAE;cAKjB1B,YAAY,CAACyB,MAAM,CAAC3C,sBAAsB,GAAG,CAAC,CAAC;YACjD,CAAC,MAAM;cAGLkB,YAAY,CAACyB,MAAM,CAAC,CAAC,CAAC;cAEtB,IAAME,UAAU,GAAG3B,YAAY,CAACgB,WAAW,CAACI,YAAY,CAACG,UAAU,CAAa;cAChF,IAAMK,QAAQ,GAAG,IAAAC,6BAAW,EAACF,UAAU,EAAEtC,OAAO,CAAC;cACjDe,MAAM,CAACZ,UAAU,CAACsC,IAAI,CAACF,QAAQ,CAAC;cAEhCxB,MAAM,CAACN,YAAY,EAAE;cACrBM,MAAM,CAACX,QAAQ,CAACI,IAAI,GAAGO,MAAM,CAACN,YAAY,GAAG,CAAC;YAChD;UACF;UAEA,IAAIE,YAAY,CAAC+B,KAAK,EAAE;YACtB7B,KAAK,GAAGnB,KAAK,CAACG,GAAG;UACnB;UAEA,OAAOgB,KAAK;QAEd;UACEA,KAAK,GAAGnB,KAAK,CAACI,KAAK;UACnBiB,MAAM,CAACE,KAAK,kCAA2BJ,KAAK,CAAE;UAC9C,OAAOA,KAAK;MAAC;IAEnB,CAAC,CAAC,OAAOI,KAAK,EAAE;MACdJ,KAAK,GAAGnB,KAAK,CAACI,KAAK;MACnBiB,MAAM,CAACE,KAAK,iCAA2BA,KAAK,aAALA,KAAK,uBAALA,KAAK,CAAY0B,OAAO,CAAE;MACjE,OAAO9B,KAAK;IACd;EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"parse-shp.js","names":["_binaryChunkReader","_interopRequireDefault","require","_parseShpHeader","_parseShpGeometry","_asyncIterator","iterable","method","async","sync","retry","Symbol","asyncIterator","iterator","call","AsyncFromSyncIterator","TypeError","s","AsyncFromSyncIteratorContinuation","r","Object","Promise","reject","done","resolve","value","then","n","next","prototype","apply","arguments","return","_return","ret","throw","_throw","thr","LITTLE_ENDIAN","BIG_ENDIAN","SHP_HEADER_SIZE","SHP_RECORD_HEADER_SIZE","STATE","EXPECTING_HEADER","EXPECTING_RECORD","END","ERROR","SHPParser","options","_classCallCheck2","default","_defineProperty2","BinaryChunkReader","maxRewindBytes","geometries","progress","bytesTotal","NaN","bytesUsed","rows","currentIndex","_createClass2","key","write","arrayBuffer","binaryReader","state","parseState","result","end","error","parseSHP","shpParser","parseSHPInBatches","_x","_x2","_parseSHPInBatches","_wrapAsyncGenerator2","_regenerator","mark","_callee","parser","headerReturned","_iteratorAbruptCompletion","_didIteratorError","_iteratorError","_iterator","_step","wrap","_callee$","_context","prev","_awaitAsyncGenerator2","sent","header","length","t0","finish","abrupt","stop","dataView","getDataView","parseSHPHeader","hasAvailableBytes","_result$header","recordHeaderView","recordHeader","recordNumber","getInt32","byteLength","type","rewind","invalidRecord","recordView","geometry","parseRecord","push","ended","concat","message"],"sources":["../../../../src/lib/parsers/parse-shp.ts"],"sourcesContent":["import type {BinaryGeometry} from '@loaders.gl/schema';\nimport BinaryChunkReader from '../streaming/binary-chunk-reader';\nimport {parseSHPHeader, SHPHeader} from './parse-shp-header';\nimport {parseRecord} from './parse-shp-geometry';\nimport {SHPLoaderOptions} from './types';\n\nconst LITTLE_ENDIAN = true;\nconst BIG_ENDIAN = false;\n\nconst SHP_HEADER_SIZE = 100;\n// According to the spec, the record header is just 8 bytes, but here we set it\n// to 12 so that we can also access the record's type\nconst SHP_RECORD_HEADER_SIZE = 12;\n\nconst STATE = {\n EXPECTING_HEADER: 0,\n EXPECTING_RECORD: 1,\n END: 2,\n ERROR: 3\n};\n\ntype SHPResult = {\n geometries: (BinaryGeometry | null)[];\n header?: SHPHeader;\n error?: string;\n progress: {\n bytesUsed: number;\n bytesTotal: number;\n rows: number;\n };\n currentIndex: number;\n};\n\nclass SHPParser {\n options?: SHPLoaderOptions = {};\n binaryReader = new BinaryChunkReader({maxRewindBytes: SHP_RECORD_HEADER_SIZE});\n state = STATE.EXPECTING_HEADER;\n result: SHPResult = {\n geometries: [],\n // Initialize with number values to make TS happy\n // These are initialized for real in STATE.EXPECTING_HEADER\n progress: {\n bytesTotal: NaN,\n bytesUsed: NaN,\n rows: NaN\n },\n currentIndex: NaN\n };\n\n constructor(options?: SHPLoaderOptions) {\n this.options = options;\n }\n\n write(arrayBuffer: ArrayBuffer) {\n this.binaryReader.write(arrayBuffer);\n this.state = parseState(this.state, this.result, this.binaryReader, this.options);\n }\n\n end() {\n this.binaryReader.end();\n this.state = parseState(this.state, this.result, this.binaryReader, this.options);\n // this.result.progress.bytesUsed = this.binaryReader.bytesUsed();\n if (this.state !== STATE.END) {\n this.state = STATE.ERROR;\n this.result.error = 'SHP incomplete file';\n }\n }\n}\n\nexport function parseSHP(arrayBuffer: ArrayBuffer, options?: SHPLoaderOptions): BinaryGeometry[] {\n const shpParser = new SHPParser(options);\n shpParser.write(arrayBuffer);\n shpParser.end();\n\n // @ts-ignore\n return shpParser.result;\n}\n\n/**\n * @param asyncIterator\n * @param options\n * @returns\n */\nexport async function* parseSHPInBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options?: SHPLoaderOptions\n): AsyncIterable<BinaryGeometry | object> {\n const parser = new SHPParser(options);\n let headerReturned = false;\n for await (const arrayBuffer of asyncIterator) {\n parser.write(arrayBuffer);\n if (!headerReturned && parser.result.header) {\n headerReturned = true;\n yield parser.result.header;\n }\n\n if (parser.result.geometries.length > 0) {\n yield parser.result.geometries;\n parser.result.geometries = [];\n }\n }\n parser.end();\n if (parser.result.geometries.length > 0) {\n yield parser.result.geometries;\n }\n\n return;\n}\n\n/**\n * State-machine parser for SHP data\n *\n * Note that whenever more data is needed, a `return`, not a `break`, is\n * necessary, as the `break` keeps the context within `parseState`, while\n * `return` releases context so that more data can be written into the\n * BinaryChunkReader.\n *\n * @param state Current state\n * @param result An object to hold result data\n * @param binaryReader\n * @return State at end of current parsing\n */\n/* eslint-disable complexity, max-depth */\nfunction parseState(\n state: number,\n result: SHPResult,\n binaryReader: BinaryChunkReader,\n options?: SHPLoaderOptions\n): number {\n // eslint-disable-next-line no-constant-condition\n while (true) {\n try {\n switch (state) {\n case STATE.ERROR:\n case STATE.END:\n return state;\n\n case STATE.EXPECTING_HEADER:\n // Parse initial file header\n const dataView = binaryReader.getDataView(SHP_HEADER_SIZE);\n if (!dataView) {\n return state;\n }\n\n result.header = parseSHPHeader(dataView);\n result.progress = {\n bytesUsed: 0,\n bytesTotal: result.header.length,\n rows: 0\n };\n // index numbering starts at 1\n result.currentIndex = 1;\n state = STATE.EXPECTING_RECORD;\n break;\n\n case STATE.EXPECTING_RECORD:\n while (binaryReader.hasAvailableBytes(SHP_RECORD_HEADER_SIZE)) {\n const recordHeaderView = binaryReader.getDataView(SHP_RECORD_HEADER_SIZE) as DataView;\n const recordHeader = {\n recordNumber: recordHeaderView.getInt32(0, BIG_ENDIAN),\n // 2 byte words; includes the four words of record header\n byteLength: recordHeaderView.getInt32(4, BIG_ENDIAN) * 2,\n // This is actually part of the record, not the header...\n type: recordHeaderView.getInt32(8, LITTLE_ENDIAN)\n };\n\n if (!binaryReader.hasAvailableBytes(recordHeader.byteLength - 4)) {\n binaryReader.rewind(SHP_RECORD_HEADER_SIZE);\n return state;\n }\n\n const invalidRecord =\n recordHeader.byteLength < 4 ||\n recordHeader.type !== result.header?.type ||\n recordHeader.recordNumber !== result.currentIndex;\n\n // All records must have at least four bytes (for the record shape type)\n if (invalidRecord) {\n // Malformed record, try again, advancing just 4 bytes\n // Note: this is a rewind because binaryReader.getDataView above\n // moved the pointer forward 12 bytes, so rewinding 8 bytes still\n // leaves us 4 bytes ahead\n binaryReader.rewind(SHP_RECORD_HEADER_SIZE - 4);\n } else {\n // Note: type is actually part of the record, not the header, so\n // rewind 4 bytes before reading record\n binaryReader.rewind(4);\n\n const recordView = binaryReader.getDataView(recordHeader.byteLength) as DataView;\n const geometry = parseRecord(recordView, options);\n result.geometries.push(geometry);\n\n result.currentIndex++;\n result.progress.rows = result.currentIndex - 1;\n }\n }\n\n if (binaryReader.ended) {\n state = STATE.END;\n }\n\n return state;\n\n default:\n state = STATE.ERROR;\n result.error = `illegal parser state ${state}`;\n return state;\n }\n } catch (error) {\n state = STATE.ERROR;\n result.error = `SHP parsing failed: ${(error as Error)?.message}`;\n return state;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AACA,IAAAA,kBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AAAiD,SAAAG,eAAAC,QAAA,QAAAC,MAAA,EAAAC,KAAA,EAAAC,IAAA,EAAAC,KAAA,iCAAAC,MAAA,KAAAH,KAAA,GAAAG,MAAA,CAAAC,aAAA,EAAAH,IAAA,GAAAE,MAAA,CAAAE,QAAA,GAAAH,KAAA,WAAAF,KAAA,aAAAD,MAAA,GAAAD,QAAA,CAAAE,KAAA,WAAAD,MAAA,CAAAO,IAAA,CAAAR,QAAA,OAAAG,IAAA,aAAAF,MAAA,GAAAD,QAAA,CAAAG,IAAA,eAAAM,qBAAA,CAAAR,MAAA,CAAAO,IAAA,CAAAR,QAAA,IAAAE,KAAA,sBAAAC,IAAA,6BAAAO,SAAA;AAAA,SAAAD,sBAAAE,CAAA,aAAAC,kCAAAC,CAAA,QAAAC,MAAA,CAAAD,CAAA,MAAAA,CAAA,SAAAE,OAAA,CAAAC,MAAA,KAAAN,SAAA,CAAAG,CAAA,+BAAAI,IAAA,GAAAJ,CAAA,CAAAI,IAAA,SAAAF,OAAA,CAAAG,OAAA,CAAAL,CAAA,CAAAM,KAAA,EAAAC,IAAA,WAAAD,KAAA,aAAAA,KAAA,EAAAA,KAAA,EAAAF,IAAA,EAAAA,IAAA,iBAAAR,qBAAA,YAAAA,sBAAAE,CAAA,SAAAA,CAAA,GAAAA,CAAA,OAAAU,CAAA,GAAAV,CAAA,CAAAW,IAAA,KAAAb,qBAAA,CAAAc,SAAA,KAAAZ,CAAA,QAAAU,CAAA,QAAAC,IAAA,WAAAA,KAAA,WAAAV,iCAAA,M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ShpHeader = require("./parse-shp-header");
|
|
8
8
|
var SHX_HEADER_SIZE = 100;
|
|
9
9
|
var BIG_ENDIAN = false;
|
|
10
|
-
|
|
11
10
|
function parseShx(arrayBuffer) {
|
|
12
11
|
var headerView = new DataView(arrayBuffer, 0, SHX_HEADER_SIZE);
|
|
13
12
|
var header = (0, _parseShpHeader.parseSHPHeader)(headerView);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-shx.js","names":["SHX_HEADER_SIZE","BIG_ENDIAN","parseShx","arrayBuffer","headerView","DataView","header","parseSHPHeader","contentLength","length","contentView","offsets","Int32Array","lengths","i","getInt32"],"sources":["../../../../src/lib/parsers/parse-shx.ts"],"sourcesContent":["import {parseSHPHeader} from './parse-shp-header';\n\nexport interface SHXOutput {\n offsets: Int32Array;\n lengths: Int32Array;\n}\n\nconst SHX_HEADER_SIZE = 100;\nconst BIG_ENDIAN = false;\n\n/**\n * @param arrayBuffer\n * @returns SHXOutput\n */\nexport function parseShx(arrayBuffer: ArrayBuffer): SHXOutput {\n // SHX header is identical to SHP Header\n const headerView = new DataView(arrayBuffer, 0, SHX_HEADER_SIZE);\n const header = parseSHPHeader(headerView);\n const contentLength = header.length - SHX_HEADER_SIZE;\n\n const contentView = new DataView(arrayBuffer, SHX_HEADER_SIZE, contentLength);\n\n const offsets = new Int32Array(contentLength);\n const lengths = new Int32Array(contentLength);\n\n for (let i = 0; i < contentLength / 8; i++) {\n offsets[i] = contentView.getInt32(i * 8, BIG_ENDIAN);\n lengths[i] = contentView.getInt32(i * 8 + 4, BIG_ENDIAN);\n }\n\n return {\n offsets,\n lengths\n };\n}\n"],"mappings":";;;;;;AAAA;AAOA,
|
|
1
|
+
{"version":3,"file":"parse-shx.js","names":["_parseShpHeader","require","SHX_HEADER_SIZE","BIG_ENDIAN","parseShx","arrayBuffer","headerView","DataView","header","parseSHPHeader","contentLength","length","contentView","offsets","Int32Array","lengths","i","getInt32"],"sources":["../../../../src/lib/parsers/parse-shx.ts"],"sourcesContent":["import {parseSHPHeader} from './parse-shp-header';\n\nexport interface SHXOutput {\n offsets: Int32Array;\n lengths: Int32Array;\n}\n\nconst SHX_HEADER_SIZE = 100;\nconst BIG_ENDIAN = false;\n\n/**\n * @param arrayBuffer\n * @returns SHXOutput\n */\nexport function parseShx(arrayBuffer: ArrayBuffer): SHXOutput {\n // SHX header is identical to SHP Header\n const headerView = new DataView(arrayBuffer, 0, SHX_HEADER_SIZE);\n const header = parseSHPHeader(headerView);\n const contentLength = header.length - SHX_HEADER_SIZE;\n\n const contentView = new DataView(arrayBuffer, SHX_HEADER_SIZE, contentLength);\n\n const offsets = new Int32Array(contentLength);\n const lengths = new Int32Array(contentLength);\n\n for (let i = 0; i < contentLength / 8; i++) {\n offsets[i] = contentView.getInt32(i * 8, BIG_ENDIAN);\n lengths[i] = contentView.getInt32(i * 8 + 4, BIG_ENDIAN);\n }\n\n return {\n offsets,\n lengths\n };\n}\n"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AAOA,IAAMC,eAAe,GAAG,GAAG;AAC3B,IAAMC,UAAU,GAAG,KAAK;AAMjB,SAASC,QAAQA,CAACC,WAAwB,EAAa;EAE5D,IAAMC,UAAU,GAAG,IAAIC,QAAQ,CAACF,WAAW,EAAE,CAAC,EAAEH,eAAe,CAAC;EAChE,IAAMM,MAAM,GAAG,IAAAC,8BAAc,EAACH,UAAU,CAAC;EACzC,IAAMI,aAAa,GAAGF,MAAM,CAACG,MAAM,GAAGT,eAAe;EAErD,IAAMU,WAAW,GAAG,IAAIL,QAAQ,CAACF,WAAW,EAAEH,eAAe,EAAEQ,aAAa,CAAC;EAE7E,IAAMG,OAAO,GAAG,IAAIC,UAAU,CAACJ,aAAa,CAAC;EAC7C,IAAMK,OAAO,GAAG,IAAID,UAAU,CAACJ,aAAa,CAAC;EAE7C,KAAK,IAAIM,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGN,aAAa,GAAG,CAAC,EAAEM,CAAC,EAAE,EAAE;IAC1CH,OAAO,CAACG,CAAC,CAAC,GAAGJ,WAAW,CAACK,QAAQ,CAACD,CAAC,GAAG,CAAC,EAAEb,UAAU,CAAC;IACpDY,OAAO,CAACC,CAAC,CAAC,GAAGJ,WAAW,CAACK,QAAQ,CAACD,CAAC,GAAG,CAAC,GAAG,CAAC,EAAEb,UAAU,CAAC;EAC1D;EAEA,OAAO;IACLU,OAAO,EAAPA,OAAO;IACPE,OAAO,EAAPA;EACF,CAAC;AACH"}
|