@loaders.gl/gis 3.1.0 → 3.1.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.
Files changed (49) hide show
  1. package/dist/es5/index.js +16 -0
  2. package/dist/es5/index.js.map +1 -1
  3. package/dist/es5/lib/extract-geometry-info.js +204 -0
  4. package/dist/es5/lib/extract-geometry-info.js.map +1 -0
  5. package/dist/es5/lib/flat-geojson-to-binary-types.js +2 -0
  6. package/dist/es5/lib/flat-geojson-to-binary-types.js.map +1 -0
  7. package/dist/es5/lib/flat-geojson-to-binary.js +397 -0
  8. package/dist/es5/lib/flat-geojson-to-binary.js.map +1 -0
  9. package/dist/es5/lib/geojson-to-binary.js +15 -579
  10. package/dist/es5/lib/geojson-to-binary.js.map +1 -1
  11. package/dist/es5/lib/geojson-to-flat-geojson.js +169 -0
  12. package/dist/es5/lib/geojson-to-flat-geojson.js.map +1 -0
  13. package/dist/esm/index.js +2 -0
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/esm/lib/extract-geometry-info.js +105 -0
  16. package/dist/esm/lib/extract-geometry-info.js.map +1 -0
  17. package/dist/esm/lib/flat-geojson-to-binary-types.js +2 -0
  18. package/dist/esm/lib/flat-geojson-to-binary-types.js.map +1 -0
  19. package/dist/esm/lib/flat-geojson-to-binary.js +339 -0
  20. package/dist/esm/lib/flat-geojson-to-binary.js.map +1 -0
  21. package/dist/esm/lib/geojson-to-binary.js +17 -410
  22. package/dist/esm/lib/geojson-to-binary.js.map +1 -1
  23. package/dist/esm/lib/geojson-to-flat-geojson.js +116 -0
  24. package/dist/esm/lib/geojson-to-flat-geojson.js.map +1 -0
  25. package/dist/index.d.ts +2 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +5 -1
  28. package/dist/lib/extract-geometry-info.d.ts +8 -0
  29. package/dist/lib/extract-geometry-info.d.ts.map +1 -0
  30. package/dist/lib/extract-geometry-info.js +96 -0
  31. package/dist/lib/flat-geojson-to-binary-types.d.ts +58 -0
  32. package/dist/lib/flat-geojson-to-binary-types.d.ts.map +1 -0
  33. package/dist/lib/flat-geojson-to-binary-types.js +2 -0
  34. package/dist/lib/flat-geojson-to-binary.d.ts +37 -0
  35. package/dist/lib/flat-geojson-to-binary.d.ts.map +1 -0
  36. package/dist/lib/flat-geojson-to-binary.js +375 -0
  37. package/dist/lib/geojson-to-binary.d.ts +12 -36
  38. package/dist/lib/geojson-to-binary.d.ts.map +1 -1
  39. package/dist/lib/geojson-to-binary.js +18 -360
  40. package/dist/lib/geojson-to-flat-geojson.d.ts +17 -0
  41. package/dist/lib/geojson-to-flat-geojson.d.ts.map +1 -0
  42. package/dist/lib/geojson-to-flat-geojson.js +128 -0
  43. package/package.json +5 -4
  44. package/src/index.ts +2 -0
  45. package/src/lib/extract-geometry-info.ts +101 -0
  46. package/src/lib/flat-geojson-to-binary-types.ts +58 -0
  47. package/src/lib/flat-geojson-to-binary.ts +564 -0
  48. package/src/lib/geojson-to-binary.ts +24 -459
  49. package/src/lib/geojson-to-flat-geojson.ts +171 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/lib/geojson-to-binary.ts"],"names":["geojsonToBinary","features","options","firstPassData","firstPass","secondPass","coordLength","numericPropKeys","PositionDataType","Float32Array","TEST_EXPORTS","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","coordLengths","Set","propArrayTypes","feature","geometry","type","add","coordinates","length","point","coord","line","flatten","polygon","Error","properties","key","val","deduceArrayType","size","Math","max","Object","keys","filter","k","Array","GlobalFeatureIdsDataType","Uint32Array","Uint16Array","points","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","object","propName","TypedArray","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","handlePoint","push","keepStringProperties","handleMultiPoint","handleLineString","handleMultiLineString","handlePolygon","handleMultiPolygon","makeAccessorObjects","coords","set","fillNumericProperties","fillCoords","nPositions","fill","ring","returnObj","value","geomType","numericProp","index","numericPropName","numericKeys","props","includes","array","startVertex","arrays","concat","x","constructor","Number","isFinite","Float64Array","fround"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAUO,SAASA,eAAT,CACLC,QADK,EAGW;AAAA,MADhBC,OACgB,uEADkB,EAClB;AAChB,MAAMC,aAAa,GAAGC,SAAS,CAACH,QAAD,CAA/B;AACA,SAAOI,UAAU,CAACJ,QAAD,EAAWE,aAAX,EAA0B;AACzCG,IAAAA,WAAW,EAAEJ,OAAO,CAACI,WAAR,IAAuBH,aAAa,CAACG,WADT;AAEzCC,IAAAA,eAAe,EAAEL,OAAO,CAACK,eAAR,IAA2BJ,aAAa,CAACI,eAFjB;AAGzCC,IAAAA,gBAAgB,EAAEN,OAAO,CAACM,gBAAR,IAA4BC;AAHL,GAA1B,CAAjB;AAKD;;AAEM,IAAMC,YAAY,GAAG;AAC1BN,EAAAA,SAAS,EAATA,SAD0B;AAE1BC,EAAAA,UAAU,EAAVA;AAF0B,CAArB;;;AA6BP,SAASD,SAAT,CAAmBH,QAAnB,EAAuD;AAErD,MAAIU,mBAAmB,GAAG,CAA1B;AACA,MAAIC,kBAAkB,GAAG,CAAzB;AACA,MAAIC,kBAAkB,GAAG,CAAzB;AACA,MAAIC,cAAc,GAAG,CAArB;AACA,MAAIC,iBAAiB,GAAG,CAAxB;AACA,MAAIC,qBAAqB,GAAG,CAA5B;AACA,MAAIC,mBAAmB,GAAG,CAA1B;AACA,MAAIC,iBAAiB,GAAG,CAAxB;AACA,MAAIC,oBAAoB,GAAG,CAA3B;AACA,MAAMC,YAAY,GAAG,IAAIC,GAAJ,EAArB;AACA,MAAMC,cAAc,GAAG,EAAvB;;AAZqD,6CAc/BrB,QAd+B;AAAA;;AAAA;AAcrD,wDAAgC;AAAA,UAArBsB,OAAqB;AAC9B,UAAMC,QAA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AkD;AAChD,WAAOzD,KAAP;AACD;;AAGD,SAAO0D,WAAW,KAAKG,YAAhB,IAAgCnE,IAAI,CAACoE,MAAL,CAAYL,CAAZ,MAAmBA,CAAnD,GAAuDI,YAAvD,GAAsElG,YAA7E;AACD","sourcesContent":["import {Feature, GeoJsonProperties} from '@loaders.gl/schema';\nimport type {BinaryFeatures} from '@loaders.gl/schema';\n\nexport type GeojsonToBinaryOptions = {\n coordLength?: number;\n numericPropKeys?: string[];\n PositionDataType?: Function;\n};\n\n/** Convert GeoJSON features to flat binary arrays */\nexport function geojsonToBinary(\n features: Feature[],\n options: GeojsonToBinaryOptions = {}\n): BinaryFeatures {\n const firstPassData = firstPass(features);\n return secondPass(features, firstPassData, {\n coordLength: options.coordLength || firstPassData.coordLength,\n numericPropKeys: options.numericPropKeys || firstPassData.numericPropKeys,\n PositionDataType: options.PositionDataType || Float32Array\n });\n}\n\nexport const TEST_EXPORTS = {\n firstPass,\n secondPass\n};\n\ntype PropArrayConstructor = Float32ArrayConstructor | Float64ArrayConstructor | ArrayConstructor;\n\ntype FirstPassData = {\n coordLength: number;\n numericPropKeys: string[];\n propArrayTypes: {[key: string]: PropArrayConstructor};\n\n pointPositionsCount: number;\n pointFeaturesCount: number;\n linePositionsCount: number;\n linePathsCount: number;\n lineFeaturesCount: number;\n polygonPositionsCount: number;\n polygonObjectsCount: number;\n polygonRingsCount: number;\n polygonFeaturesCount: number;\n};\n\n/**\n * Initial scan over GeoJSON features\n * Counts number of coordinates of each geometry type and\n * keeps track of the max coordinate dimensions\n */\n// eslint-disable-next-line complexity, max-statements\nfunction firstPass(features: Feature[]): FirstPassData {\n // Counts the number of _positions_, so [x, y, z] counts as one\n let pointPositionsCount = 0;\n let pointFeaturesCount = 0;\n let linePositionsCount = 0;\n let linePathsCount = 0;\n let lineFeaturesCount = 0;\n let polygonPositionsCount = 0;\n let polygonObjectsCount = 0;\n let polygonRingsCount = 0;\n let polygonFeaturesCount = 0;\n const coordLengths = new Set<number>();\n const propArrayTypes = {};\n\n for (const feature of features) {\n const geometry = feature.geometry;\n switch (geometry.type) {\n case 'Point':\n pointFeaturesCount++;\n pointPositionsCount++;\n coordLengths.add(geometry.coordinates.length);\n break;\n case 'MultiPoint':\n pointFeaturesCount++;\n pointPositionsCount += geometry.coordinates.length;\n for (const point of geometry.coordinates) {\n coordLengths.add(point.length);\n }\n break;\n case 'LineString':\n lineFeaturesCount++;\n linePositionsCount += geometry.coordinates.length;\n linePathsCount++;\n\n for (const coord of geometry.coordinates) {\n coordLengths.add(coord.length);\n }\n break;\n case 'MultiLineString':\n lineFeaturesCount++;\n for (const line of geometry.coordinates) {\n linePositionsCount += line.length;\n linePathsCount++;\n\n // eslint-disable-next-line max-depth\n for (const coord of line) {\n coordLengths.add(coord.length);\n }\n }\n break;\n case 'Polygon':\n polygonFeaturesCount++;\n polygonObjectsCount++;\n polygonRingsCount += geometry.coordinates.length;\n polygonPositionsCount += flatten(geometry.coordinates).length;\n\n for (const coord of flatten(geometry.coordinates)) {\n coordLengths.add(coord.length);\n }\n break;\n case 'MultiPolygon':\n polygonFeaturesCount++;\n for (const polygon of geometry.coordinates) {\n polygonObjectsCount++;\n polygonRingsCount += polygon.length;\n polygonPositionsCount += flatten(polygon).length;\n\n // eslint-disable-next-line max-depth\n for (const coord of flatten(polygon)) {\n coordLengths.add(coord.length);\n }\n }\n break;\n default:\n throw new Error(`Unsupported geometry type: ${geometry.type}`);\n }\n\n if (feature.properties) {\n for (const key in feature.properties) {\n const val = feature.properties[key];\n\n // If property has not been seen before, or if property has been numeric\n // in all previous features, check if numeric in this feature\n // If not numeric, Array is stored to prevent rechecking in the future\n // Additionally, detects if 64 bit precision is required\n propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);\n }\n }\n }\n\n return {\n coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,\n\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount,\n\n // Array of keys whose values are always numeric\n numericPropKeys: Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array),\n propArrayTypes\n };\n}\n\n/**\n * Second scan over GeoJSON features\n * Fills coordinates into pre-allocated typed arrays\n */\n// eslint-disable-next-line complexity\nfunction secondPass(\n features,\n firstPassData: FirstPassData,\n options: Required<GeojsonToBinaryOptions>\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n propArrayTypes,\n polygonFeaturesCount\n } = firstPassData;\n const {coordLength, numericPropKeys, PositionDataType = Float32Array} = options;\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points = {\n // @ts-ignore Typescript doesn't like dynamic constructors\n positions: new PositionDataType(pointPositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),\n featureIds:\n pointFeaturesCount > 65535\n ? new Uint32Array(pointPositionsCount)\n : new Uint16Array(pointPositionsCount),\n numericProps: {},\n properties: Array<any>(),\n fields: Array<any>()\n };\n const lines = {\n // @ts-ignore Typescript doesn't like dynamic constructors\n positions: new PositionDataType(linePositionsCount * coordLength),\n pathIndices:\n linePositionsCount > 65535\n ? new Uint32Array(linePathsCount + 1)\n : new Uint16Array(linePathsCount + 1),\n globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),\n featureIds:\n lineFeaturesCount > 65535\n ? new Uint32Array(linePositionsCount)\n : new Uint16Array(linePositionsCount),\n numericProps: {},\n properties: Array<any>(),\n fields: Array<any>()\n };\n const polygons = {\n // @ts-ignore Typescript doesn't like dynamic constructors\n positions: new PositionDataType(polygonPositionsCount * coordLength),\n polygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonObjectsCount + 1)\n : new Uint16Array(polygonObjectsCount + 1),\n primitivePolygonIndices:\n polygonPositionsCount > 65535\n ? new Uint32Array(polygonRingsCount + 1)\n : new Uint16Array(polygonRingsCount + 1),\n globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),\n featureIds:\n polygonFeaturesCount > 65535\n ? new Uint32Array(polygonPositionsCount)\n : new Uint16Array(polygonPositionsCount),\n numericProps: {},\n properties: Array<any>(),\n fields: Array<any>()\n };\n\n // Instantiate numeric properties arrays; one value per vertex\n for (const object of [points, lines, polygons]) {\n for (const propName of numericPropKeys || []) {\n // If property has been numeric in all previous features in which the property existed, check\n // if numeric in this feature\n const TypedArray = propArrayTypes[propName];\n object.numericProps[propName] = new TypedArray(object.positions.length / coordLength);\n }\n }\n\n // Set last element of path/polygon indices as positions length\n lines.pathIndices[linePathsCount] = linePositionsCount;\n polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;\n polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;\n\n const indexMap = {\n pointPosition: 0,\n pointFeature: 0,\n linePosition: 0,\n linePath: 0,\n lineFeature: 0,\n polygonPosition: 0,\n polygonObject: 0,\n polygonRing: 0,\n polygonFeature: 0,\n feature: 0\n };\n\n for (const feature of features) {\n const geometry = feature.geometry;\n const properties: GeoJsonProperties = feature.properties || {};\n\n switch (geometry.type) {\n case 'Point':\n handlePoint(geometry.coordinates, points, indexMap, coordLength, properties);\n points.properties.push(keepStringProperties(properties, numericPropKeys));\n indexMap.pointFeature++;\n break;\n case 'MultiPoint':\n handleMultiPoint(geometry.coordinates, points, indexMap, coordLength, properties);\n points.properties.push(keepStringProperties(properties, numericPropKeys));\n indexMap.pointFeature++;\n break;\n case 'LineString':\n handleLineString(geometry.coordinates, lines, indexMap, coordLength, properties);\n lines.properties.push(keepStringProperties(properties, numericPropKeys));\n indexMap.lineFeature++;\n break;\n case 'MultiLineString':\n handleMultiLineString(geometry.coordinates, lines, indexMap, coordLength, properties);\n lines.properties.push(keepStringProperties(properties, numericPropKeys));\n indexMap.lineFeature++;\n break;\n case 'Polygon':\n handlePolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);\n polygons.properties.push(keepStringProperties(properties, numericPropKeys));\n indexMap.polygonFeature++;\n break;\n case 'MultiPolygon':\n handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);\n polygons.properties.push(keepStringProperties(properties, numericPropKeys));\n indexMap.polygonFeature++;\n break;\n default:\n throw new Error('Invalid geometry type');\n }\n\n indexMap.feature++;\n }\n\n // Wrap each array in an accessor object with value and size keys\n return makeAccessorObjects(points, lines, polygons, coordLength);\n}\n\n/** Fills Point coordinates into points object of arrays */\nfunction handlePoint(coords, points, indexMap, coordLength, properties) {\n points.positions.set(coords, indexMap.pointPosition * coordLength);\n points.globalFeatureIds[indexMap.pointPosition] = indexMap.feature;\n points.featureIds[indexMap.pointPosition] = indexMap.pointFeature;\n\n fillNumericProperties(points, properties, indexMap.pointPosition, 1);\n indexMap.pointPosition++;\n}\n\n/** Fills MultiPoint coordinates into points object of arrays */\nfunction handleMultiPoint(coords, points, indexMap, coordLength, properties) {\n for (const point of coords) {\n handlePoint(point, points, indexMap, coordLength, properties);\n }\n}\n\n/** Fills LineString coordinates into lines object of arrays */\nfunction handleLineString(coords, lines, indexMap, coordLength, properties) {\n lines.pathIndices[indexMap.linePath] = indexMap.linePosition;\n indexMap.linePath++;\n\n fillCoords(lines.positions, coords, indexMap.linePosition, coordLength);\n\n const nPositions = coords.length;\n fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);\n\n lines.globalFeatureIds.set(\n new Uint32Array(nPositions).fill(indexMap.feature),\n indexMap.linePosition\n );\n lines.featureIds.set(\n new Uint32Array(nPositions).fill(indexMap.lineFeature),\n indexMap.linePosition\n );\n indexMap.linePosition += nPositions;\n}\n\n/** Fills MultiLineString coordinates into lines object of arrays */\nfunction handleMultiLineString(coords, lines, indexMap, coordLength, properties) {\n for (const line of coords) {\n handleLineString(line, lines, indexMap, coordLength, properties);\n }\n}\n\n/** Fills Polygon coordinates into polygons object of arrays */\nfunction handlePolygon(coords, polygons, indexMap, coordLength, properties) {\n polygons.polygonIndices[indexMap.polygonObject] = indexMap.polygonPosition;\n indexMap.polygonObject++;\n\n for (const ring of coords) {\n polygons.primitivePolygonIndices[indexMap.polygonRing] = indexMap.polygonPosition;\n indexMap.polygonRing++;\n\n fillCoords(polygons.positions, ring, indexMap.polygonPosition, coordLength);\n\n const nPositions = ring.length;\n fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);\n\n polygons.globalFeatureIds.set(\n new Uint32Array(nPositions).fill(indexMap.feature),\n indexMap.polygonPosition\n );\n polygons.featureIds.set(\n new Uint32Array(nPositions).fill(indexMap.polygonFeature),\n indexMap.polygonPosition\n );\n indexMap.polygonPosition += nPositions;\n }\n}\n\n/** Fills MultiPolygon coordinates into polygons object of arrays */\nfunction handleMultiPolygon(coords, polygons, indexMap, coordLength, properties) {\n for (const polygon of coords) {\n handlePolygon(polygon, polygons, indexMap, coordLength, properties);\n }\n}\n\n/** Wrap each array in an accessor object with value and size keys */\nfunction makeAccessorObjects(points, lines, polygons, coordLength): BinaryFeatures {\n const returnObj = {\n points: {\n ...points,\n positions: {value: points.positions, size: coordLength},\n globalFeatureIds: {value: points.globalFeatureIds, size: 1},\n featureIds: {value: points.featureIds, size: 1},\n type: 'Point'\n },\n lines: {\n ...lines,\n pathIndices: {value: lines.pathIndices, size: 1},\n positions: {value: lines.positions, size: coordLength},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1},\n type: 'LineString'\n },\n polygons: {\n ...polygons,\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n positions: {value: polygons.positions, size: coordLength},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1},\n type: 'Polygon'\n }\n };\n\n for (const geomType in returnObj) {\n for (const numericProp in returnObj[geomType].numericProps) {\n returnObj[geomType].numericProps[numericProp] = {\n value: returnObj[geomType].numericProps[numericProp],\n size: 1\n };\n }\n }\n\n return returnObj as unknown as BinaryFeatures;\n}\n\n/** Add numeric properties to object */\nfunction fillNumericProperties(object, properties, index, length) {\n for (const numericPropName in object.numericProps) {\n if (numericPropName in properties) {\n object.numericProps[numericPropName].set(\n new Array(length).fill(properties[numericPropName]),\n index\n );\n }\n }\n}\n\n/** Keep string properties in object */\nfunction keepStringProperties(properties, numericKeys: string[]): GeoJsonProperties {\n const props = {};\n for (const key in properties) {\n if (!numericKeys.includes(key)) {\n props[key] = properties[key];\n }\n }\n return props;\n}\n\n/** @param coords is expected to be a list of arrays, each with length 2-3 */\nfunction fillCoords(array, coords, startVertex, coordLength): void {\n let index = startVertex * coordLength;\n for (const coord of coords) {\n array.set(coord, index);\n index += coordLength;\n }\n}\n\n// TODO - how does this work? Different `coordinates` have different nesting\nfunction flatten(arrays): number[][] {\n return [].concat(...arrays);\n}\n\nfunction deduceArrayType(x: any, constructor: PropArrayConstructor): PropArrayConstructor {\n if (constructor === Array || !Number.isFinite(x)) {\n return Array;\n }\n\n // If this or previous value required 64bits use Float64Array\n return constructor === Float64Array || Math.fround(x) !== x ? Float64Array : Float32Array;\n}\n"],"file":"geojson-to-binary.js"}
1
+ {"version":3,"sources":["../../../src/lib/geojson-to-binary.ts"],"names":["geojsonToBinary","features","options","fixRingWinding","geometryInfo","coordLength","flatFeatures","numericPropKeys","PositionDataType","Float32Array"],"mappings":";;;;;;;AAGA;;AACA;;AACA;;AAkBO,SAASA,eAAT,CACLC,QADK,EAGW;AAAA,MADhBC,OACgB,uEADkB;AAACC,IAAAA,cAAc,EAAE;AAAjB,GAClB;AAChB,MAAMC,YAAY,GAAG,8CAAoBH,QAApB,CAArB;AACA,MAAMI,WAAW,GAAGD,YAAY,CAACC,WAAjC;AACA,MAAOF,cAAP,GAAyBD,OAAzB,CAAOC,cAAP;AACA,MAAMG,YAAY,GAAG,gDAAqBL,QAArB,EAA+B;AAACI,IAAAA,WAAW,EAAXA,WAAD;AAAcF,IAAAA,cAAc,EAAdA;AAAd,GAA/B,CAArB;AACA,SAAO,8CAAoBG,YAApB,EAAkCF,YAAlC,EAAgD;AACrDG,IAAAA,eAAe,EAAEL,OAAO,CAACK,eAD4B;AAErDC,IAAAA,gBAAgB,EAAEN,OAAO,CAACM,gBAAR,IAA4BC;AAFO,GAAhD,CAAP;AAID","sourcesContent":["import type {Feature} from '@loaders.gl/schema';\nimport type {BinaryFeatures} from '@loaders.gl/schema';\n\nimport {extractGeometryInfo} from './extract-geometry-info';\nimport {geojsonToFlatGeojson} from './geojson-to-flat-geojson';\nimport {flatGeojsonToBinary} from './flat-geojson-to-binary';\n\n/**\n * Options for `geojsonToBinary`\n */\nexport type GeojsonToBinaryOptions = {\n fixRingWinding: boolean;\n numericPropKeys?: string[];\n PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;\n};\n\n/**\n * Convert GeoJSON features to flat binary arrays\n *\n * @param features\n * @param options\n * @returns features in binary format, grouped by geometry type\n */\nexport function geojsonToBinary(\n features: Feature[],\n options: GeojsonToBinaryOptions = {fixRingWinding: true}\n): BinaryFeatures {\n const geometryInfo = extractGeometryInfo(features);\n const coordLength = geometryInfo.coordLength;\n const {fixRingWinding} = options;\n const flatFeatures = geojsonToFlatGeojson(features, {coordLength, fixRingWinding});\n return flatGeojsonToBinary(flatFeatures, geometryInfo, {\n numericPropKeys: options.numericPropKeys,\n PositionDataType: options.PositionDataType || Float32Array\n });\n}\n"],"file":"geojson-to-binary.js"}
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.geojsonToFlatGeojson = geojsonToFlatGeojson;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
+
14
+ var _polygon = require("@math.gl/polygon");
15
+
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
17
+
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
+
20
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
21
+
22
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
23
+
24
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
25
+
26
+ function geojsonToFlatGeojson(features) {
27
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
28
+ coordLength: 2,
29
+ fixRingWinding: true
30
+ };
31
+ return features.map(function (feature) {
32
+ return flattenFeature(feature, options);
33
+ });
34
+ }
35
+
36
+ function flattenPoint(coordinates, data, indices, options) {
37
+ indices.push(data.length);
38
+ data.push.apply(data, (0, _toConsumableArray2.default)(coordinates));
39
+
40
+ for (var i = coordinates.length; i < options.coordLength; i++) {
41
+ data.push(0);
42
+ }
43
+ }
44
+
45
+ function flattenLineString(coordinates, data, indices, options) {
46
+ indices.push(data.length);
47
+
48
+ var _iterator = _createForOfIteratorHelper(coordinates),
49
+ _step;
50
+
51
+ try {
52
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
53
+ var c = _step.value;
54
+ data.push.apply(data, (0, _toConsumableArray2.default)(c));
55
+
56
+ for (var i = c.length; i < options.coordLength; i++) {
57
+ data.push(0);
58
+ }
59
+ }
60
+ } catch (err) {
61
+ _iterator.e(err);
62
+ } finally {
63
+ _iterator.f();
64
+ }
65
+ }
66
+
67
+ function flattenPolygon(coordinates, data, indices, areas, options) {
68
+ var count = 0;
69
+ var ringAreas = [];
70
+ var polygons = [];
71
+
72
+ var _iterator2 = _createForOfIteratorHelper(coordinates),
73
+ _step2;
74
+
75
+ try {
76
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
77
+ var lineString = _step2.value;
78
+ var lineString2d = lineString.map(function (p) {
79
+ return p.slice(0, 2);
80
+ });
81
+ var area = (0, _polygon.getPolygonSignedArea)(lineString2d.flat());
82
+ var ccw = area < 0;
83
+
84
+ if (options.fixRingWinding && (count === 0 && !ccw || count > 0 && ccw)) {
85
+ lineString.reverse();
86
+ area = -area;
87
+ }
88
+
89
+ ringAreas.push(area);
90
+ flattenLineString(lineString, data, polygons, options);
91
+ count++;
92
+ }
93
+ } catch (err) {
94
+ _iterator2.e(err);
95
+ } finally {
96
+ _iterator2.f();
97
+ }
98
+
99
+ if (count > 0) {
100
+ areas.push(ringAreas);
101
+ indices.push(polygons);
102
+ }
103
+ }
104
+
105
+ function flattenFeature(feature, options) {
106
+ var geometry = feature.geometry;
107
+
108
+ if (geometry.type === 'GeometryCollection') {
109
+ throw new Error('GeometryCollection type not supported');
110
+ }
111
+
112
+ var data = [];
113
+ var indices = [];
114
+ var areas;
115
+ var type;
116
+
117
+ switch (geometry.type) {
118
+ case 'Point':
119
+ type = 'Point';
120
+ flattenPoint(geometry.coordinates, data, indices, options);
121
+ break;
122
+
123
+ case 'MultiPoint':
124
+ type = 'Point';
125
+ geometry.coordinates.map(function (c) {
126
+ return flattenPoint(c, data, indices, options);
127
+ });
128
+ break;
129
+
130
+ case 'LineString':
131
+ type = 'LineString';
132
+ flattenLineString(geometry.coordinates, data, indices, options);
133
+ break;
134
+
135
+ case 'MultiLineString':
136
+ type = 'LineString';
137
+ geometry.coordinates.map(function (c) {
138
+ return flattenLineString(c, data, indices, options);
139
+ });
140
+ break;
141
+
142
+ case 'Polygon':
143
+ type = 'Polygon';
144
+ areas = [];
145
+ flattenPolygon(geometry.coordinates, data, indices, areas, options);
146
+ break;
147
+
148
+ case 'MultiPolygon':
149
+ type = 'Polygon';
150
+ areas = [];
151
+ geometry.coordinates.map(function (c) {
152
+ return flattenPolygon(c, data, indices, areas, options);
153
+ });
154
+ break;
155
+
156
+ default:
157
+ throw new Error("Unknown type: ".concat(type));
158
+ }
159
+
160
+ return _objectSpread(_objectSpread({}, feature), {}, {
161
+ geometry: {
162
+ type: type,
163
+ indices: indices,
164
+ data: data,
165
+ areas: areas
166
+ }
167
+ });
168
+ }
169
+ //# sourceMappingURL=geojson-to-flat-geojson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/geojson-to-flat-geojson.ts"],"names":["geojsonToFlatGeojson","features","options","coordLength","fixRingWinding","map","feature","flattenFeature","flattenPoint","coordinates","data","indices","push","length","i","flattenLineString","c","flattenPolygon","areas","count","ringAreas","polygons","lineString","lineString2d","p","slice","area","flat","ccw","reverse","geometry","type","Error"],"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;;;AA0BO,SAASA,oBAAT,CACLC,QADK,EAGU;AAAA,MADfC,OACe,uEADwB;AAACC,IAAAA,WAAW,EAAE,CAAd;AAAiBC,IAAAA,cAAc,EAAE;AAAjC,GACxB;AACf,SAAOH,QAAQ,CAACI,GAAT,CAAa,UAACC,OAAD;AAAA,WAAaC,cAAc,CAACD,OAAD,EAAUJ,OAAV,CAA3B;AAAA,GAAb,CAAP;AACD;;AAUD,SAASM,YAAT,CACEC,WADF,EAEEC,IAFF,EAGEC,OAHF,EAIET,OAJF,EAKE;AACAS,EAAAA,OAAO,CAACC,IAAR,CAAaF,IAAI,CAACG,MAAlB;AACAH,EAAAA,IAAI,CAACE,IAAL,OAAAF,IAAI,mCAASD,WAAT,EAAJ;;AAGA,OAAK,IAAIK,CAAC,GAAGL,WAAW,CAACI,MAAzB,EAAiCC,CAAC,GAAGZ,OAAO,CAACC,WAA7C,EAA0DW,CAAC,EAA3D,EAA+D;AAC7DJ,IAAAA,IAAI,CAACE,IAAL,CAAU,CAAV;AACD;AACF;;AAUD,SAASG,iBAAT,CACEN,WADF,EAEEC,IAFF,EAGEC,OAHF,EAIET,OAJF,EAKE;AACAS,EAAAA,OAAO,CAACC,IAAR,CAAaF,IAAI,CAACG,MAAlB;;AADA,6CAEgBJ,WAFhB;AAAA;;AAAA;AAEA,wDAA6B;AAAA,UAAlBO,CAAkB;AAC3BN,MAAAA,IAAI,CAACE,IAAL,OAAAF,IAAI,mCAASM,CAAT,EAAJ;;AAGA,WAAK,IAAIF,CAAC,GAAGE,CAAC,CAACH,MAAf,EAAuBC,CAAC,GAAGZ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,EAAsCO,KAAtC,EAA6ChB,OAA7C,CAAd;AACA;;AACF,SAAK,cAAL;AACE6B,MAAAA,IAAI,GAAG,SAAP;AACAb,MAAAA,KAAK,GAAG,EAAR;AACAY,MAAAA,QAAQ,CAACrB,WAAT,CAAqBJ,GAArB,CAAyB,UAACW,CAAD;AAAA,eAAOC,cAAc,CAACD,CAAD,EAAIN,IAAJ,EAAUC,OAAV,EAAmBO,KAAnB,EAA0BhB,OAA1B,CAArB;AAAA,OAAzB;AACA;;AACF;AACE,YAAM,IAAI8B,KAAJ,yBAA2BD,IAA3B,EAAN;AA5BJ;;AA+BA,yCAAWzB,OAAX;AAAoBwB,IAAAA,QAAQ,EAAE;AAACC,MAAAA,IAAI,EAAJA,IAAD;AAAOpB,MAAAA,OAAO,EAAPA,OAAP;AAAgBD,MAAAA,IAAI,EAAJA,IAAhB;AAAsBQ,MAAAA,KAAK,EAALA;AAAtB;AAA9B;AACD","sourcesContent":["import {getPolygonSignedArea} from '@math.gl/polygon';\n\nimport {Feature, Position, FlatFeature} from '@loaders.gl/schema';\n\n/**\n * Options for `geojsonToFlatGeojson`\n */\nexport type GeojsonToFlatGeojsonOptions = {\n coordLength: number;\n fixRingWinding: boolean;\n};\n\n// Coordinates defining a Point\ntype PointCoordinates = Position;\n// Coordinates defining a LineString\ntype LineStringCoordinates = Position[];\n// Coordinates defining a Polygon\ntype PolygonCoordinates = Position[][];\n\n/**\n * Convert GeoJSON features to Flat GeoJSON features\n *\n * @param features\n * @param options\n * @returns an Array of Flat GeoJSON features\n */\nexport function geojsonToFlatGeojson(\n features: Feature[],\n options: GeojsonToFlatGeojsonOptions = {coordLength: 2, fixRingWinding: true}\n): FlatFeature[] {\n return features.map((feature) => flattenFeature(feature, options));\n}\n\n/**\n * Helper function to copy Point values from `coordinates` into `data` & `indices`\n *\n * @param coordinates\n * @param data\n * @param indices\n * @param options\n */\nfunction flattenPoint(\n coordinates: PointCoordinates,\n data: number[],\n indices: number[],\n options: GeojsonToFlatGeojsonOptions\n) {\n indices.push(data.length);\n data.push(...coordinates);\n\n // Pad up to coordLength\n for (let i = coordinates.length; i < options.coordLength; i++) {\n data.push(0);\n }\n}\n\n/**\n * Helper function to copy LineString values from `coordinates` into `data` & `indices`\n *\n * @param coordinates\n * @param data\n * @param indices\n * @param options\n */\nfunction flattenLineString(\n coordinates: LineStringCoordinates,\n data: number[],\n indices: number[],\n options: GeojsonToFlatGeojsonOptions\n) {\n indices.push(data.length);\n for (const c of coordinates) {\n data.push(...c);\n\n // Pad up to coordLength\n for (let i = c.length; i < options.coordLength; i++) {\n data.push(0);\n }\n }\n}\n\n/**\n * Helper function to copy Polygon values from `coordinates` into `data` & `indices` & `areas`\n *\n * @param coordinates\n * @param data\n * @param indices\n * @param areas\n * @param options\n */\nfunction flattenPolygon(\n coordinates: PolygonCoordinates,\n data: number[],\n indices: number[][],\n areas: number[][],\n options: GeojsonToFlatGeojsonOptions\n) {\n let count = 0;\n const ringAreas: number[] = [];\n const polygons: number[] = [];\n for (const lineString of coordinates) {\n const lineString2d = lineString.map((p) => p.slice(0, 2));\n let area = getPolygonSignedArea(lineString2d.flat());\n const ccw = area < 0;\n\n // Exterior ring must be CCW and interior rings CW\n if (options.fixRingWinding && ((count === 0 && !ccw) || (count > 0 && ccw))) {\n lineString.reverse();\n area = -area;\n }\n ringAreas.push(area);\n flattenLineString(lineString, data, polygons, options);\n count++;\n }\n\n if (count > 0) {\n areas.push(ringAreas);\n indices.push(polygons);\n }\n}\n\n/**\n * Flatten single GeoJSON feature into Flat GeoJSON\n *\n * @param feature\n * @param options\n * @returns A Flat GeoJSON feature\n */\nfunction flattenFeature(feature: Feature, options: GeojsonToFlatGeojsonOptions): FlatFeature {\n const {geometry} = feature;\n if (geometry.type === 'GeometryCollection') {\n throw new Error('GeometryCollection type not supported');\n }\n const data = [];\n const indices = [];\n let areas;\n let type;\n\n switch (geometry.type) {\n case 'Point':\n type = 'Point';\n flattenPoint(geometry.coordinates, data, indices, options);\n break;\n case 'MultiPoint':\n type = 'Point';\n geometry.coordinates.map((c) => flattenPoint(c, data, indices, options));\n break;\n case 'LineString':\n type = 'LineString';\n flattenLineString(geometry.coordinates, data, indices, options);\n break;\n case 'MultiLineString':\n type = 'LineString';\n geometry.coordinates.map((c) => flattenLineString(c, data, indices, options));\n break;\n case 'Polygon':\n type = 'Polygon';\n areas = [];\n flattenPolygon(geometry.coordinates, data, indices, areas, options);\n break;\n case 'MultiPolygon':\n type = 'Polygon';\n areas = [];\n geometry.coordinates.map((c) => flattenPolygon(c, data, indices, areas, options));\n break;\n default:\n throw new Error(`Unknown type: ${type}`);\n }\n\n return {...feature, geometry: {type, indices, data, areas}};\n}\n"],"file":"geojson-to-flat-geojson.js"}
package/dist/esm/index.js CHANGED
@@ -1,4 +1,6 @@
1
+ export { flatGeojsonToBinary } from './lib/flat-geojson-to-binary';
1
2
  export { geojsonToBinary } from './lib/geojson-to-binary';
3
+ export { geojsonToFlatGeojson } from './lib/geojson-to-flat-geojson';
2
4
  export { binaryToGeojson, binaryToGeoJson, binaryToGeometry } from './lib/binary-to-geojson';
3
5
  export { transformBinaryCoords, transformGeoJsonCoords } from './lib/transform';
4
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"names":["geojsonToBinary","binaryToGeojson","binaryToGeoJson","binaryToGeometry","transformBinaryCoords","transformGeoJsonCoords"],"mappings":"AAGA,SAAQA,eAAR,QAA8B,yBAA9B;AACA,SAAQC,eAAR,EAAyBC,eAAzB,EAA0CC,gBAA1C,QAAiE,yBAAjE;AACA,SAAQC,qBAAR,EAA+BC,sBAA/B,QAA4D,iBAA5D","sourcesContent":["// Types from `@loaders.gl/schema`\n\n// Functions\nexport {geojsonToBinary} from './lib/geojson-to-binary';\nexport {binaryToGeojson, binaryToGeoJson, binaryToGeometry} from './lib/binary-to-geojson';\nexport {transformBinaryCoords, transformGeoJsonCoords} from './lib/transform';\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":["flatGeojsonToBinary","geojsonToBinary","geojsonToFlatGeojson","binaryToGeojson","binaryToGeoJson","binaryToGeometry","transformBinaryCoords","transformGeoJsonCoords"],"mappings":"AAGA,SAAQA,mBAAR,QAAkC,8BAAlC;AACA,SAAQC,eAAR,QAA8B,yBAA9B;AACA,SAAQC,oBAAR,QAAmC,+BAAnC;AACA,SAAQC,eAAR,EAAyBC,eAAzB,EAA0CC,gBAA1C,QAAiE,yBAAjE;AACA,SAAQC,qBAAR,EAA+BC,sBAA/B,QAA4D,iBAA5D","sourcesContent":["// Types from `@loaders.gl/schema`\n\n// Functions\nexport {flatGeojsonToBinary} from './lib/flat-geojson-to-binary';\nexport {geojsonToBinary} from './lib/geojson-to-binary';\nexport {geojsonToFlatGeojson} from './lib/geojson-to-flat-geojson';\nexport {binaryToGeojson, binaryToGeoJson, binaryToGeometry} from './lib/binary-to-geojson';\nexport {transformBinaryCoords, transformGeoJsonCoords} from './lib/transform';\n"],"file":"index.js"}
@@ -0,0 +1,105 @@
1
+ export function extractGeometryInfo(features) {
2
+ let pointPositionsCount = 0;
3
+ let pointFeaturesCount = 0;
4
+ let linePositionsCount = 0;
5
+ let linePathsCount = 0;
6
+ let lineFeaturesCount = 0;
7
+ let polygonPositionsCount = 0;
8
+ let polygonObjectsCount = 0;
9
+ let polygonRingsCount = 0;
10
+ let polygonFeaturesCount = 0;
11
+ const coordLengths = new Set();
12
+
13
+ for (const feature of features) {
14
+ const geometry = feature.geometry;
15
+
16
+ switch (geometry.type) {
17
+ case 'Point':
18
+ pointFeaturesCount++;
19
+ pointPositionsCount++;
20
+ coordLengths.add(geometry.coordinates.length);
21
+ break;
22
+
23
+ case 'MultiPoint':
24
+ pointFeaturesCount++;
25
+ pointPositionsCount += geometry.coordinates.length;
26
+
27
+ for (const point of geometry.coordinates) {
28
+ coordLengths.add(point.length);
29
+ }
30
+
31
+ break;
32
+
33
+ case 'LineString':
34
+ lineFeaturesCount++;
35
+ linePositionsCount += geometry.coordinates.length;
36
+ linePathsCount++;
37
+
38
+ for (const coord of geometry.coordinates) {
39
+ coordLengths.add(coord.length);
40
+ }
41
+
42
+ break;
43
+
44
+ case 'MultiLineString':
45
+ lineFeaturesCount++;
46
+
47
+ for (const line of geometry.coordinates) {
48
+ linePositionsCount += line.length;
49
+ linePathsCount++;
50
+
51
+ for (const coord of line) {
52
+ coordLengths.add(coord.length);
53
+ }
54
+ }
55
+
56
+ break;
57
+
58
+ case 'Polygon':
59
+ polygonFeaturesCount++;
60
+ polygonObjectsCount++;
61
+ polygonRingsCount += geometry.coordinates.length;
62
+ const flattened = geometry.coordinates.flat();
63
+ polygonPositionsCount += flattened.length;
64
+
65
+ for (const coord of flattened) {
66
+ coordLengths.add(coord.length);
67
+ }
68
+
69
+ break;
70
+
71
+ case 'MultiPolygon':
72
+ polygonFeaturesCount++;
73
+
74
+ for (const polygon of geometry.coordinates) {
75
+ polygonObjectsCount++;
76
+ polygonRingsCount += polygon.length;
77
+ const flattened = polygon.flat();
78
+ polygonPositionsCount += flattened.length;
79
+
80
+ for (const coord of flattened) {
81
+ coordLengths.add(coord.length);
82
+ }
83
+ }
84
+
85
+ break;
86
+
87
+ default:
88
+ throw new Error("Unsupported geometry type: ".concat(geometry.type));
89
+ }
90
+ }
91
+
92
+ return {
93
+ coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
94
+ pointPositionsCount,
95
+ pointFeaturesCount,
96
+ linePositionsCount,
97
+ linePathsCount,
98
+ lineFeaturesCount,
99
+ polygonPositionsCount,
100
+ polygonObjectsCount,
101
+ polygonRingsCount,
102
+ polygonFeaturesCount
103
+ };
104
+ }
105
+ //# sourceMappingURL=extract-geometry-info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/extract-geometry-info.ts"],"names":["extractGeometryInfo","features","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","coordLengths","Set","feature","geometry","type","add","coordinates","length","point","coord","line","flattened","flat","polygon","Error","coordLength","size","Math","max"],"mappings":"AAQA,OAAO,SAASA,mBAAT,CAA6BC,QAA7B,EAAuE;AAE5E,MAAIC,mBAAmB,GAAG,CAA1B;AACA,MAAIC,kBAAkB,GAAG,CAAzB;AACA,MAAIC,kBAAkB,GAAG,CAAzB;AACA,MAAIC,cAAc,GAAG,CAArB;AACA,MAAIC,iBAAiB,GAAG,CAAxB;AACA,MAAIC,qBAAqB,GAAG,CAA5B;AACA,MAAIC,mBAAmB,GAAG,CAA1B;AACA,MAAIC,iBAAiB,GAAG,CAAxB;AACA,MAAIC,oBAAoB,GAAG,CAA3B;AACA,QAAMC,YAAY,GAAG,IAAIC,GAAJ,EAArB;;AAEA,OAAK,MAAMC,OAAX,IAAsBZ,QAAtB,EAAgC;AAC9B,UAAMa,QAAQ,GAAGD,OAAO,CAACC,QAAzB;;AACA,YAAQA,QAAQ,CAACC,IAAjB;AACE,WAAK,OAAL;AACEZ,QAAAA,kBAAkB;AAClBD,QAAAA,mBAAmB;AACnBS,QAAAA,YAAY,CAACK,GAAb,CAAiBF,QAAQ,CAACG,WAAT,CAAqBC,MAAtC;AACA;;AACF,WAAK,YAAL;AACEf,QAAAA,kBAAkB;AAClBD,QAAAA,mBAAmB,IAAIY,QAAQ,CAACG,WAAT,CAAqBC,MAA5C;;AACA,aAAK,MAAMC,KAAX,IAAoBL,QAAQ,CAACG,WAA7B,EAA0C;AACxCN,UAAAA,YAAY,CAACK,GAAb,CAAiBG,KAAK,CAACD,MAAvB;AACD;;AACD;;AACF,WAAK,YAAL;AACEZ,QAAAA,iBAAiB;AACjBF,QAAAA,kBAAkB,IAAIU,QAAQ,CAACG,WAAT,CAAqBC,MAA3C;AACAb,QAAAA,cAAc;;AAEd,aAAK,MAAMe,KAAX,IAAoBN,QAAQ,CAACG,WAA7B,EAA0C;AACxCN,UAAAA,YAAY,CAACK,GAAb,CAAiBI,KAAK,CAACF,MAA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AwBC,IAAI,CAACC,GAAL,CAAS,GAAGlB,YAAZ,CAAxB,GAAoD,CAD5D;AAGLT,IAAAA,mBAHK;AAILC,IAAAA,kBAJK;AAKLC,IAAAA,kBALK;AAMLC,IAAAA,cANK;AAOLC,IAAAA,iBAPK;AAQLC,IAAAA,qBARK;AASLC,IAAAA,mBATK;AAULC,IAAAA,iBAVK;AAWLC,IAAAA;AAXK,GAAP;AAaD","sourcesContent":["import {Feature, GeojsonGeometryInfo} from '@loaders.gl/schema';\n\n/**\n * Initial scan over GeoJSON features\n * Counts number of coordinates of each geometry type and\n * keeps track of the max coordinate dimensions\n */\n// eslint-disable-next-line complexity, max-statements\nexport function extractGeometryInfo(features: Feature[]): GeojsonGeometryInfo {\n // Counts the number of _positions_, so [x, y, z] counts as one\n let pointPositionsCount = 0;\n let pointFeaturesCount = 0;\n let linePositionsCount = 0;\n let linePathsCount = 0;\n let lineFeaturesCount = 0;\n let polygonPositionsCount = 0;\n let polygonObjectsCount = 0;\n let polygonRingsCount = 0;\n let polygonFeaturesCount = 0;\n const coordLengths = new Set<number>();\n\n for (const feature of features) {\n const geometry = feature.geometry;\n switch (geometry.type) {\n case 'Point':\n pointFeaturesCount++;\n pointPositionsCount++;\n coordLengths.add(geometry.coordinates.length);\n break;\n case 'MultiPoint':\n pointFeaturesCount++;\n pointPositionsCount += geometry.coordinates.length;\n for (const point of geometry.coordinates) {\n coordLengths.add(point.length);\n }\n break;\n case 'LineString':\n lineFeaturesCount++;\n linePositionsCount += geometry.coordinates.length;\n linePathsCount++;\n\n for (const coord of geometry.coordinates) {\n coordLengths.add(coord.length);\n }\n break;\n case 'MultiLineString':\n lineFeaturesCount++;\n for (const line of geometry.coordinates) {\n linePositionsCount += line.length;\n linePathsCount++;\n\n // eslint-disable-next-line max-depth\n for (const coord of line) {\n coordLengths.add(coord.length);\n }\n }\n break;\n case 'Polygon':\n polygonFeaturesCount++;\n polygonObjectsCount++;\n polygonRingsCount += geometry.coordinates.length;\n const flattened = geometry.coordinates.flat();\n polygonPositionsCount += flattened.length;\n\n for (const coord of flattened) {\n coordLengths.add(coord.length);\n }\n break;\n case 'MultiPolygon':\n polygonFeaturesCount++;\n for (const polygon of geometry.coordinates) {\n polygonObjectsCount++;\n polygonRingsCount += polygon.length;\n const flattened = polygon.flat();\n polygonPositionsCount += flattened.length;\n\n // eslint-disable-next-line max-depth\n for (const coord of flattened) {\n coordLengths.add(coord.length);\n }\n }\n break;\n default:\n throw new Error(`Unsupported geometry type: ${geometry.type}`);\n }\n }\n\n return {\n coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,\n\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount\n };\n}\n"],"file":"extract-geometry-info.js"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=flat-geojson-to-binary-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"flat-geojson-to-binary-types.js"}