@loaders.gl/gis 4.0.0-alpha.4 → 4.0.0-alpha.5

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 (37) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/index.d.ts +6 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +2 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/lib/binary-to-geojson.d.ts +21 -0
  8. package/dist/lib/binary-to-geojson.d.ts.map +1 -0
  9. package/dist/lib/extract-geometry-info.d.ts +8 -0
  10. package/dist/lib/extract-geometry-info.d.ts.map +1 -0
  11. package/dist/lib/extract-geometry-info.js +105 -0
  12. package/dist/lib/extract-geometry-info.js.map +1 -0
  13. package/dist/lib/flat-geojson-to-binary-types.d.ts +58 -0
  14. package/dist/lib/flat-geojson-to-binary-types.d.ts.map +1 -0
  15. package/dist/lib/flat-geojson-to-binary-types.js +2 -0
  16. package/dist/lib/flat-geojson-to-binary-types.js.map +1 -0
  17. package/dist/lib/flat-geojson-to-binary.d.ts +37 -0
  18. package/dist/lib/flat-geojson-to-binary.d.ts.map +1 -0
  19. package/dist/lib/flat-geojson-to-binary.js +339 -0
  20. package/dist/lib/flat-geojson-to-binary.js.map +1 -0
  21. package/dist/lib/geojson-to-binary.d.ts +19 -0
  22. package/dist/lib/geojson-to-binary.d.ts.map +1 -0
  23. package/dist/lib/geojson-to-binary.js +17 -403
  24. package/dist/lib/geojson-to-binary.js.map +1 -1
  25. package/dist/lib/geojson-to-flat-geojson.d.ts +17 -0
  26. package/dist/lib/geojson-to-flat-geojson.d.ts.map +1 -0
  27. package/dist/lib/geojson-to-flat-geojson.js +116 -0
  28. package/dist/lib/geojson-to-flat-geojson.js.map +1 -0
  29. package/dist/lib/transform.d.ts +19 -0
  30. package/dist/lib/transform.d.ts.map +1 -0
  31. package/package.json +6 -5
  32. package/src/index.ts +2 -0
  33. package/src/lib/extract-geometry-info.ts +101 -0
  34. package/src/lib/flat-geojson-to-binary-types.ts +58 -0
  35. package/src/lib/flat-geojson-to-binary.ts +564 -0
  36. package/src/lib/geojson-to-binary.ts +24 -450
  37. package/src/lib/geojson-to-flat-geojson.ts +171 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/lib/flat-geojson-to-binary.ts"],"names":["earcut","flatGeojsonToBinary","features","geometryInfo","options","propArrayTypes","extractNumericPropTypes","numericPropKeys","Object","keys","filter","k","Array","fillArrays","PositionDataType","Float32Array","TEST_EXPORTS","feature","properties","key","val","deduceArrayType","pointPositionsCount","pointFeaturesCount","linePositionsCount","linePathsCount","lineFeaturesCount","polygonPositionsCount","polygonObjectsCount","polygonRingsCount","polygonFeaturesCount","coordLength","hasGlobalId","GlobalFeatureIdsDataType","length","Uint32Array","Uint16Array","points","type","positions","globalFeatureIds","featureIds","numericProps","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","triangles","object","propName","T","indexMap","pointPosition","pointFeature","linePosition","linePath","lineFeature","polygonPosition","polygonObject","polygonRing","polygonFeature","geometry","handlePoint","push","keepStringProperties","id","handleLineString","handlePolygon","Error","makeAccessorObjects","set","data","nPositions","fillNumericProperties","fill","i","il","indices","start","end","l","ll","startPosition","areas","nextIndices","undefined","endPosition","triangulatePolygon","polygonPositions","subarray","offset","holes","slice","map","n","t","tl","wrapProps","obj","size","returnObj","value","index","numericPropName","numericKeys","props","includes","x","constructor","Number","isFinite","Float64Array","Math","fround"],"mappings":"AACA,SAAQA,MAAR,QAAqB,kBAArB;AA0BA,OAAO,SAASC,mBAAT,CACLC,QADK,EAELC,YAFK,EAGLC,OAHK,EAIL;AACA,QAAMC,cAAc,GAAGC,uBAAuB,CAACJ,QAAD,CAA9C;AACA,QAAMK,eAAe,GAAGC,MAAM,CAACC,IAAP,CAAYJ,cAAZ,EAA4BK,MAA5B,CAAoCC,CAAD,IAAON,cAAc,CAACM,CAAD,CAAd,KAAsBC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AW,CAACE,QAAZ,CAAqBzF,GAArB,CAAL,EAAgC;AAC9BwF,MAAAA,KAAK,CAACxF,GAAD,CAAL,GAAaD,UAAU,CAACC,GAAD,CAAvB;AACD;AACF;;AACD,SAAOwF,KAAP;AACD;;AAUD,SAAStF,eAAT,CAAyBwF,CAAzB,EAAiCC,WAAjC,EAA0F;AACxF,MAAIA,WAAW,KAAKlG,KAAhB,IAAyB,CAACmG,MAAM,CAACC,QAAP,CAAgBH,CAAhB,CAA9B,EAAkD;AAChD,WAAOjG,KAAP;AACD;;AAGD,SAAOkG,WAAW,KAAKG,YAAhB,IAAgCC,IAAI,CAACC,MAAL,CAAYN,CAAZ,MAAmBA,CAAnD,GAAuDI,YAAvD,GAAsElG,YAA7E;AACD","sourcesContent":["/* eslint-disable indent */\nimport {earcut} from '@math.gl/polygon';\nimport type {\n BinaryAttribute,\n BinaryFeatures,\n FlatFeature,\n FlatPoint,\n FlatLineString,\n FlatPolygon,\n GeojsonGeometryInfo,\n TypedArray\n} from '@loaders.gl/schema';\nimport {PropArrayConstructor, Lines, Points, Polygons} from './flat-geojson-to-binary-types';\n\n/**\n * Convert binary features to flat binary arrays. Similar to\n * `geojsonToBinary` helper function, except that it expects\n * a binary representation of the feature data, which enables\n * 2X-3X speed increase in parse speed, compared to using\n * geoJSON. See `binary-vector-tile/VectorTileFeature` for\n * data format detais\n *\n * @param features\n * @param geometryInfo\n * @param options\n * @returns filled arrays\n */\nexport function flatGeojsonToBinary(\n features: FlatFeature[],\n geometryInfo: GeojsonGeometryInfo,\n options?: FlatGeojsonToBinaryOptions\n) {\n const propArrayTypes = extractNumericPropTypes(features);\n const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);\n return fillArrays(\n features,\n {\n propArrayTypes,\n ...geometryInfo\n },\n {\n numericPropKeys: (options && options.numericPropKeys) || numericPropKeys,\n PositionDataType: options ? options.PositionDataType : Float32Array\n }\n );\n}\n\n/**\n * Options for `flatGeojsonToBinary`\n */\nexport type FlatGeojsonToBinaryOptions = {\n numericPropKeys?: string[];\n PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;\n};\n\nexport const TEST_EXPORTS = {\n extractNumericPropTypes\n};\n\n/**\n * Extracts properties that are always numeric\n *\n * @param features\n * @returns object with numeric types\n */\nfunction extractNumericPropTypes(features: FlatFeature[]): {\n [key: string]: PropArrayConstructor;\n} {\n const propArrayTypes = {};\n for (const feature of features) {\n if (feature.properties) {\n for (const key in feature.properties) {\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 const val = feature.properties[key];\n propArrayTypes[key] = deduceArrayType(val, propArrayTypes[key]);\n }\n }\n }\n\n return propArrayTypes;\n}\n\n/**\n * Fills coordinates into pre-allocated typed arrays\n *\n * @param features\n * @param geometryInfo\n * @param options\n * @returns an accessor object with value and size keys\n */\n// eslint-disable-next-line complexity\nfunction fillArrays(\n features: FlatFeature[],\n geometryInfo: GeojsonGeometryInfo & {\n propArrayTypes: {[key: string]: PropArrayConstructor};\n },\n options: FlatGeojsonToBinaryOptions\n) {\n const {\n pointPositionsCount,\n pointFeaturesCount,\n linePositionsCount,\n linePathsCount,\n lineFeaturesCount,\n polygonPositionsCount,\n polygonObjectsCount,\n polygonRingsCount,\n polygonFeaturesCount,\n propArrayTypes,\n coordLength\n } = geometryInfo;\n const {numericPropKeys = [], PositionDataType = Float32Array} = options;\n const hasGlobalId = features[0] && 'id' in features[0];\n const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;\n const points: Points = {\n type: 'Point',\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: [],\n fields: []\n };\n const lines: Lines = {\n type: 'LineString',\n pathIndices:\n linePositionsCount > 65535\n ? new Uint32Array(linePathsCount + 1)\n : new Uint16Array(linePathsCount + 1),\n positions: new PositionDataType(linePositionsCount * coordLength),\n globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),\n featureIds:\n lineFeaturesCount > 65535\n ? new Uint32Array(linePositionsCount)\n : new Uint16Array(linePositionsCount),\n numericProps: {},\n properties: [],\n fields: []\n };\n const polygons: Polygons = {\n type: 'Polygon',\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 positions: new PositionDataType(polygonPositionsCount * coordLength),\n triangles: [],\n globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),\n featureIds:\n polygonFeaturesCount > 65535\n ? new Uint32Array(polygonPositionsCount)\n : new Uint16Array(polygonPositionsCount),\n numericProps: {},\n properties: [],\n fields: []\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 T = propArrayTypes[propName];\n object.numericProps[propName] = new T(object.positions.length / coordLength) as TypedArray;\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 = feature.properties || {};\n\n switch (geometry.type) {\n case 'Point':\n handlePoint(geometry, points, indexMap, coordLength, properties);\n points.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n points.fields.push({id: feature.id});\n }\n indexMap.pointFeature++;\n break;\n case 'LineString':\n handleLineString(geometry, lines, indexMap, coordLength, properties);\n lines.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n lines.fields.push({id: feature.id});\n }\n indexMap.lineFeature++;\n break;\n case 'Polygon':\n handlePolygon(geometry, polygons, indexMap, coordLength, properties);\n polygons.properties.push(keepStringProperties(properties, numericPropKeys));\n if (hasGlobalId) {\n polygons.fields.push({id: feature.id});\n }\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/**\n * Fills (Multi)Point coordinates into points object of arrays\n *\n * @param geometry\n * @param points\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePoint(\n geometry: FlatPoint,\n points: Points,\n indexMap: {\n pointPosition: number;\n pointFeature: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n points.positions.set(geometry.data, indexMap.pointPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);\n points.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n points.featureIds.fill(\n indexMap.pointFeature,\n indexMap.pointPosition,\n indexMap.pointPosition + nPositions\n );\n\n indexMap.pointPosition += nPositions;\n}\n\n/**\n * Fills (Multi)LineString coordinates into lines object of arrays\n *\n * @param geometry\n * @param lines\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handleLineString(\n geometry: FlatLineString,\n lines: Lines,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition: number;\n linePath: number;\n lineFeature: number;\n polygonPosition?: number;\n polygonObject?: number;\n polygonRing?: number;\n polygonFeature?: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n lines.positions.set(geometry.data, indexMap.linePosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);\n\n lines.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n lines.featureIds.fill(\n indexMap.lineFeature,\n indexMap.linePosition,\n indexMap.linePosition + nPositions\n );\n\n for (let i = 0, il = geometry.indices.length; i < il; ++i) {\n // Extract range of data we are working with, defined by start\n // and end indices (these index into the geometry.data array)\n const start = geometry.indices[i];\n const end =\n i === il - 1\n ? geometry.data.length // last line, so read to end of data\n : geometry.indices[i + 1]; // start index for next line\n\n lines.pathIndices[indexMap.linePath++] = indexMap.linePosition;\n indexMap.linePosition += (end - start) / coordLength;\n }\n}\n\n/**\n * Fills (Multi)Polygon coordinates into polygons object of arrays\n *\n * @param geometry\n * @param polygons\n * @param indexMap\n * @param coordLength\n * @param properties\n */\nfunction handlePolygon(\n geometry: FlatPolygon,\n polygons: Polygons,\n indexMap: {\n pointPosition?: number;\n pointFeature?: number;\n linePosition?: number;\n linePath?: number;\n lineFeature?: number;\n polygonPosition: number;\n polygonObject: number;\n polygonRing: number;\n polygonFeature: number;\n feature: number;\n },\n coordLength: number,\n properties: {[x: string]: string | number | boolean | null}\n): void {\n polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);\n\n const nPositions = geometry.data.length / coordLength;\n fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);\n polygons.globalFeatureIds.fill(\n indexMap.feature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n polygons.featureIds.fill(\n indexMap.polygonFeature,\n indexMap.polygonPosition,\n indexMap.polygonPosition + nPositions\n );\n\n // Unlike Point & LineString geometry.indices is a 2D array\n for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {\n const startPosition = indexMap.polygonPosition;\n polygons.polygonIndices[indexMap.polygonObject++] = startPosition;\n\n const areas = geometry.areas[l];\n const indices = geometry.indices[l];\n const nextIndices = geometry.indices[l + 1];\n\n for (let i = 0, il = indices.length; i < il; ++i) {\n const start = indices[i];\n const end =\n i === il - 1\n ? // last line, so either read to:\n nextIndices === undefined\n ? geometry.data.length // end of data (no next indices)\n : nextIndices[0] // start of first line in nextIndices\n : indices[i + 1]; // start index for next line\n\n polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;\n indexMap.polygonPosition += (end - start) / coordLength;\n }\n\n const endPosition = indexMap.polygonPosition;\n triangulatePolygon(polygons, areas, indices, {startPosition, endPosition, coordLength});\n }\n}\n\n/**\n * Triangulate polygon using earcut\n *\n * @param polygons\n * @param areas\n * @param indices\n * @param param3\n */\nfunction triangulatePolygon(\n polygons: Polygons,\n areas: number[],\n indices: number[],\n {\n startPosition,\n endPosition,\n coordLength\n }: {startPosition: number; endPosition: number; coordLength: number}\n): void {\n const start = startPosition * coordLength;\n const end = endPosition * coordLength;\n\n // Extract positions and holes for just this polygon\n const polygonPositions = polygons.positions.subarray(start, end);\n\n // Holes are referenced relative to outer polygon\n const offset = indices[0];\n const holes = indices.slice(1).map((n: number) => (n - offset) / coordLength);\n\n // Compute triangulation\n const triangles = earcut(polygonPositions, holes, coordLength, areas);\n\n // Indices returned by triangulation are relative to start\n // of polygon, so we need to offset\n for (let t = 0, tl = triangles.length; t < tl; ++t) {\n polygons.triangles.push(startPosition + triangles[t]);\n }\n}\n\n/**\n * Wraps an object containing array into accessors\n *\n * @param obj\n * @param size\n */\nfunction wrapProps(\n obj: {[key: string]: TypedArray},\n size: number\n): {[key: string]: BinaryAttribute} {\n const returnObj = {};\n for (const key in obj) {\n returnObj[key] = {value: obj[key], size};\n }\n return returnObj;\n}\n\n/**\n * Wrap each array in an accessor object with value and size keys\n *\n * @param points\n * @param lines\n * @param polygons\n * @param coordLength\n * @returns object\n */\nfunction makeAccessorObjects(\n points: Points,\n lines: Lines,\n polygons: Polygons,\n coordLength: number\n): BinaryFeatures {\n return {\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 numericProps: wrapProps(points.numericProps, 1)\n },\n lines: {\n ...lines,\n positions: {value: lines.positions, size: coordLength},\n pathIndices: {value: lines.pathIndices, size: 1},\n globalFeatureIds: {value: lines.globalFeatureIds, size: 1},\n featureIds: {value: lines.featureIds, size: 1},\n numericProps: wrapProps(lines.numericProps, 1)\n },\n polygons: {\n ...polygons,\n positions: {value: polygons.positions, size: coordLength},\n polygonIndices: {value: polygons.polygonIndices, size: 1},\n primitivePolygonIndices: {value: polygons.primitivePolygonIndices, size: 1},\n triangles: {value: new Uint32Array(polygons.triangles), size: 1},\n globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1},\n numericProps: wrapProps(polygons.numericProps, 1)\n }\n };\n}\n\n/**\n * Add numeric properties to object\n *\n * @param object\n * @param properties\n * @param index\n * @param length\n */\nfunction fillNumericProperties(\n object: Points | Lines | Polygons,\n properties: {[x: string]: string | number | boolean | null},\n index: number,\n length: number\n): void {\n for (const numericPropName in object.numericProps) {\n if (numericPropName in properties) {\n const value = properties[numericPropName] as number;\n object.numericProps[numericPropName].fill(value, index, index + length);\n }\n }\n}\n\n/**\n * Keep string properties in object\n *\n * @param properties\n * @param numericKeys\n * @returns object\n */\nfunction keepStringProperties(\n properties: {[x: string]: string | number | boolean | null},\n numericKeys: string[]\n) {\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/**\n *\n * Deduce correct array constructor to use for a given value\n *\n * @param x value to test\n * @param constructor previous constructor deduced\n * @returns PropArrayConstructor\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":"flat-geojson-to-binary.js"}
@@ -0,0 +1,19 @@
1
+ import type { Feature } from '@loaders.gl/schema';
2
+ import type { BinaryFeatures } from '@loaders.gl/schema';
3
+ /**
4
+ * Options for `geojsonToBinary`
5
+ */
6
+ export declare type GeojsonToBinaryOptions = {
7
+ fixRingWinding: boolean;
8
+ numericPropKeys?: string[];
9
+ PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;
10
+ };
11
+ /**
12
+ * Convert GeoJSON features to flat binary arrays
13
+ *
14
+ * @param features
15
+ * @param options
16
+ * @returns features in binary format, grouped by geometry type
17
+ */
18
+ export declare function geojsonToBinary(features: Feature[], options?: GeojsonToBinaryOptions): BinaryFeatures;
19
+ //# sourceMappingURL=geojson-to-binary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geojson-to-binary.d.ts","sourceRoot":"","sources":["../../src/lib/geojson-to-binary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAMvD;;GAEG;AACH,oBAAY,sBAAsB,GAAG;IACnC,cAAc,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,gBAAgB,CAAC,EAAE,uBAAuB,GAAG,uBAAuB,CAAC;CACtE,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,GAAE,sBAA+C,GACvD,cAAc,CAShB"}
@@ -1,407 +1,21 @@
1
- export function geojsonToBinary(features, options = {}) {
2
- const firstPassData = firstPass(features);
3
- return secondPass(features, firstPassData, {
4
- coordLength: options.coordLength || firstPassData.coordLength,
5
- numericPropKeys: options.numericPropKeys || firstPassData.numericPropKeys,
6
- PositionDataType: options.PositionDataType || Float32Array
7
- });
8
- }
9
- export const TEST_EXPORTS = {
10
- firstPass,
11
- secondPass
12
- };
13
-
14
- function firstPass(features) {
15
- let pointPositionsCount = 0;
16
- let pointFeaturesCount = 0;
17
- let linePositionsCount = 0;
18
- let linePathsCount = 0;
19
- let lineFeaturesCount = 0;
20
- let polygonPositionsCount = 0;
21
- let polygonObjectsCount = 0;
22
- let polygonRingsCount = 0;
23
- let polygonFeaturesCount = 0;
24
- const coordLengths = new Set();
25
- const numericPropKeys = {};
26
-
27
- for (const feature of features) {
28
- const geometry = feature.geometry;
29
-
30
- switch (geometry.type) {
31
- case 'Point':
32
- pointFeaturesCount++;
33
- pointPositionsCount++;
34
- coordLengths.add(geometry.coordinates.length);
35
- break;
36
-
37
- case 'MultiPoint':
38
- pointFeaturesCount++;
39
- pointPositionsCount += geometry.coordinates.length;
40
-
41
- for (const point of geometry.coordinates) {
42
- coordLengths.add(point.length);
43
- }
44
-
45
- break;
46
-
47
- case 'LineString':
48
- lineFeaturesCount++;
49
- linePositionsCount += geometry.coordinates.length;
50
- linePathsCount++;
51
-
52
- for (const coord of geometry.coordinates) {
53
- coordLengths.add(coord.length);
54
- }
55
-
56
- break;
57
-
58
- case 'MultiLineString':
59
- lineFeaturesCount++;
60
-
61
- for (const line of geometry.coordinates) {
62
- linePositionsCount += line.length;
63
- linePathsCount++;
64
-
65
- for (const coord of line) {
66
- coordLengths.add(coord.length);
67
- }
68
- }
69
-
70
- break;
71
-
72
- case 'Polygon':
73
- polygonFeaturesCount++;
74
- polygonObjectsCount++;
75
- polygonRingsCount += geometry.coordinates.length;
76
- polygonPositionsCount += flatten(geometry.coordinates).length;
77
-
78
- for (const coord of flatten(geometry.coordinates)) {
79
- coordLengths.add(coord.length);
80
- }
81
-
82
- break;
83
-
84
- case 'MultiPolygon':
85
- polygonFeaturesCount++;
86
-
87
- for (const polygon of geometry.coordinates) {
88
- polygonObjectsCount++;
89
- polygonRingsCount += polygon.length;
90
- polygonPositionsCount += flatten(polygon).length;
91
-
92
- for (const coord of flatten(polygon)) {
93
- coordLengths.add(coord.length);
94
- }
95
- }
96
-
97
- break;
98
-
99
- default:
100
- throw new Error("Unsupported geometry type: ".concat(geometry.type));
101
- }
102
-
103
- if (feature.properties) {
104
- for (const key in feature.properties) {
105
- const val = feature.properties[key];
106
- numericPropKeys[key] = numericPropKeys[key] || numericPropKeys[key] === undefined ? isNumeric(val) : numericPropKeys[key];
107
- }
108
- }
109
- }
110
-
111
- return {
112
- coordLength: coordLengths.size > 0 ? Math.max(...coordLengths) : 2,
113
- pointPositionsCount,
114
- pointFeaturesCount,
115
- linePositionsCount,
116
- linePathsCount,
117
- lineFeaturesCount,
118
- polygonPositionsCount,
119
- polygonObjectsCount,
120
- polygonRingsCount,
121
- polygonFeaturesCount,
122
- numericPropKeys: Object.keys(numericPropKeys).filter(k => numericPropKeys[k])
123
- };
124
- }
125
-
126
- function secondPass(features, firstPassData, options) {
127
- const {
128
- pointPositionsCount,
129
- pointFeaturesCount,
130
- linePositionsCount,
131
- linePathsCount,
132
- lineFeaturesCount,
133
- polygonPositionsCount,
134
- polygonObjectsCount,
135
- polygonRingsCount,
136
- polygonFeaturesCount
137
- } = firstPassData;
1
+ import { extractGeometryInfo } from './extract-geometry-info';
2
+ import { geojsonToFlatGeojson } from './geojson-to-flat-geojson';
3
+ import { flatGeojsonToBinary } from './flat-geojson-to-binary';
4
+ export function geojsonToBinary(features, options = {
5
+ fixRingWinding: true
6
+ }) {
7
+ const geometryInfo = extractGeometryInfo(features);
8
+ const coordLength = geometryInfo.coordLength;
138
9
  const {
139
- coordLength,
140
- numericPropKeys,
141
- PositionDataType = Float32Array
10
+ fixRingWinding
142
11
  } = options;
143
- const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
144
- const points = {
145
- positions: new PositionDataType(pointPositionsCount * coordLength),
146
- globalFeatureIds: new GlobalFeatureIdsDataType(pointPositionsCount),
147
- featureIds: pointFeaturesCount > 65535 ? new Uint32Array(pointPositionsCount) : new Uint16Array(pointPositionsCount),
148
- numericProps: {},
149
- properties: Array(),
150
- fields: Array()
151
- };
152
- const lines = {
153
- positions: new PositionDataType(linePositionsCount * coordLength),
154
- pathIndices: linePositionsCount > 65535 ? new Uint32Array(linePathsCount + 1) : new Uint16Array(linePathsCount + 1),
155
- globalFeatureIds: new GlobalFeatureIdsDataType(linePositionsCount),
156
- featureIds: lineFeaturesCount > 65535 ? new Uint32Array(linePositionsCount) : new Uint16Array(linePositionsCount),
157
- numericProps: {},
158
- properties: Array(),
159
- fields: Array()
160
- };
161
- const polygons = {
162
- positions: new PositionDataType(polygonPositionsCount * coordLength),
163
- polygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonObjectsCount + 1) : new Uint16Array(polygonObjectsCount + 1),
164
- primitivePolygonIndices: polygonPositionsCount > 65535 ? new Uint32Array(polygonRingsCount + 1) : new Uint16Array(polygonRingsCount + 1),
165
- globalFeatureIds: new GlobalFeatureIdsDataType(polygonPositionsCount),
166
- featureIds: polygonFeaturesCount > 65535 ? new Uint32Array(polygonPositionsCount) : new Uint16Array(polygonPositionsCount),
167
- numericProps: {},
168
- properties: Array(),
169
- fields: Array()
170
- };
171
-
172
- for (const object of [points, lines, polygons]) {
173
- for (const propName of numericPropKeys || []) {
174
- object.numericProps[propName] = new Float32Array(object.positions.length / coordLength);
175
- }
176
- }
177
-
178
- lines.pathIndices[linePathsCount] = linePositionsCount;
179
- polygons.polygonIndices[polygonObjectsCount] = polygonPositionsCount;
180
- polygons.primitivePolygonIndices[polygonRingsCount] = polygonPositionsCount;
181
- const indexMap = {
182
- pointPosition: 0,
183
- pointFeature: 0,
184
- linePosition: 0,
185
- linePath: 0,
186
- lineFeature: 0,
187
- polygonPosition: 0,
188
- polygonObject: 0,
189
- polygonRing: 0,
190
- polygonFeature: 0,
191
- feature: 0
192
- };
193
-
194
- for (const feature of features) {
195
- const geometry = feature.geometry;
196
- const properties = feature.properties || {};
197
-
198
- switch (geometry.type) {
199
- case 'Point':
200
- handlePoint(geometry.coordinates, points, indexMap, coordLength, properties);
201
- points.properties.push(keepStringProperties(properties, numericPropKeys));
202
- indexMap.pointFeature++;
203
- break;
204
-
205
- case 'MultiPoint':
206
- handleMultiPoint(geometry.coordinates, points, indexMap, coordLength, properties);
207
- points.properties.push(keepStringProperties(properties, numericPropKeys));
208
- indexMap.pointFeature++;
209
- break;
210
-
211
- case 'LineString':
212
- handleLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
213
- lines.properties.push(keepStringProperties(properties, numericPropKeys));
214
- indexMap.lineFeature++;
215
- break;
216
-
217
- case 'MultiLineString':
218
- handleMultiLineString(geometry.coordinates, lines, indexMap, coordLength, properties);
219
- lines.properties.push(keepStringProperties(properties, numericPropKeys));
220
- indexMap.lineFeature++;
221
- break;
222
-
223
- case 'Polygon':
224
- handlePolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
225
- polygons.properties.push(keepStringProperties(properties, numericPropKeys));
226
- indexMap.polygonFeature++;
227
- break;
228
-
229
- case 'MultiPolygon':
230
- handleMultiPolygon(geometry.coordinates, polygons, indexMap, coordLength, properties);
231
- polygons.properties.push(keepStringProperties(properties, numericPropKeys));
232
- indexMap.polygonFeature++;
233
- break;
234
-
235
- default:
236
- throw new Error('Invalid geometry type');
237
- }
238
-
239
- indexMap.feature++;
240
- }
241
-
242
- return makeAccessorObjects(points, lines, polygons, coordLength);
243
- }
244
-
245
- function handlePoint(coords, points, indexMap, coordLength, properties) {
246
- points.positions.set(coords, indexMap.pointPosition * coordLength);
247
- points.globalFeatureIds[indexMap.pointPosition] = indexMap.feature;
248
- points.featureIds[indexMap.pointPosition] = indexMap.pointFeature;
249
- fillNumericProperties(points, properties, indexMap.pointPosition, 1);
250
- indexMap.pointPosition++;
251
- }
252
-
253
- function handleMultiPoint(coords, points, indexMap, coordLength, properties) {
254
- for (const point of coords) {
255
- handlePoint(point, points, indexMap, coordLength, properties);
256
- }
257
- }
258
-
259
- function handleLineString(coords, lines, indexMap, coordLength, properties) {
260
- lines.pathIndices[indexMap.linePath] = indexMap.linePosition;
261
- indexMap.linePath++;
262
- fillCoords(lines.positions, coords, indexMap.linePosition, coordLength);
263
- const nPositions = coords.length;
264
- fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
265
- lines.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.linePosition);
266
- lines.featureIds.set(new Uint32Array(nPositions).fill(indexMap.lineFeature), indexMap.linePosition);
267
- indexMap.linePosition += nPositions;
268
- }
269
-
270
- function handleMultiLineString(coords, lines, indexMap, coordLength, properties) {
271
- for (const line of coords) {
272
- handleLineString(line, lines, indexMap, coordLength, properties);
273
- }
274
- }
275
-
276
- function handlePolygon(coords, polygons, indexMap, coordLength, properties) {
277
- polygons.polygonIndices[indexMap.polygonObject] = indexMap.polygonPosition;
278
- indexMap.polygonObject++;
279
-
280
- for (const ring of coords) {
281
- polygons.primitivePolygonIndices[indexMap.polygonRing] = indexMap.polygonPosition;
282
- indexMap.polygonRing++;
283
- fillCoords(polygons.positions, ring, indexMap.polygonPosition, coordLength);
284
- const nPositions = ring.length;
285
- fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
286
- polygons.globalFeatureIds.set(new Uint32Array(nPositions).fill(indexMap.feature), indexMap.polygonPosition);
287
- polygons.featureIds.set(new Uint32Array(nPositions).fill(indexMap.polygonFeature), indexMap.polygonPosition);
288
- indexMap.polygonPosition += nPositions;
289
- }
290
- }
291
-
292
- function handleMultiPolygon(coords, polygons, indexMap, coordLength, properties) {
293
- for (const polygon of coords) {
294
- handlePolygon(polygon, polygons, indexMap, coordLength, properties);
295
- }
296
- }
297
-
298
- function makeAccessorObjects(points, lines, polygons, coordLength) {
299
- const returnObj = {
300
- points: { ...points,
301
- positions: {
302
- value: points.positions,
303
- size: coordLength
304
- },
305
- globalFeatureIds: {
306
- value: points.globalFeatureIds,
307
- size: 1
308
- },
309
- featureIds: {
310
- value: points.featureIds,
311
- size: 1
312
- },
313
- type: 'Point'
314
- },
315
- lines: { ...lines,
316
- pathIndices: {
317
- value: lines.pathIndices,
318
- size: 1
319
- },
320
- positions: {
321
- value: lines.positions,
322
- size: coordLength
323
- },
324
- globalFeatureIds: {
325
- value: lines.globalFeatureIds,
326
- size: 1
327
- },
328
- featureIds: {
329
- value: lines.featureIds,
330
- size: 1
331
- },
332
- type: 'LineString'
333
- },
334
- polygons: { ...polygons,
335
- polygonIndices: {
336
- value: polygons.polygonIndices,
337
- size: 1
338
- },
339
- primitivePolygonIndices: {
340
- value: polygons.primitivePolygonIndices,
341
- size: 1
342
- },
343
- positions: {
344
- value: polygons.positions,
345
- size: coordLength
346
- },
347
- globalFeatureIds: {
348
- value: polygons.globalFeatureIds,
349
- size: 1
350
- },
351
- featureIds: {
352
- value: polygons.featureIds,
353
- size: 1
354
- },
355
- type: 'Polygon'
356
- }
357
- };
358
-
359
- for (const geomType in returnObj) {
360
- for (const numericProp in returnObj[geomType].numericProps) {
361
- returnObj[geomType].numericProps[numericProp] = {
362
- value: returnObj[geomType].numericProps[numericProp],
363
- size: 1
364
- };
365
- }
366
- }
367
-
368
- return returnObj;
369
- }
370
-
371
- function fillNumericProperties(object, properties, index, length) {
372
- for (const numericPropName in object.numericProps) {
373
- if (numericPropName in properties) {
374
- object.numericProps[numericPropName].set(new Array(length).fill(properties[numericPropName]), index);
375
- }
376
- }
377
- }
378
-
379
- function keepStringProperties(properties, numericKeys) {
380
- const props = {};
381
-
382
- for (const key in properties) {
383
- if (!numericKeys.includes(key)) {
384
- props[key] = properties[key];
385
- }
386
- }
387
-
388
- return props;
389
- }
390
-
391
- function fillCoords(array, coords, startVertex, coordLength) {
392
- let index = startVertex * coordLength;
393
-
394
- for (const coord of coords) {
395
- array.set(coord, index);
396
- index += coordLength;
397
- }
398
- }
399
-
400
- function flatten(arrays) {
401
- return [].concat(...arrays);
402
- }
403
-
404
- function isNumeric(x) {
405
- return Number.isFinite(x);
12
+ const flatFeatures = geojsonToFlatGeojson(features, {
13
+ coordLength,
14
+ fixRingWinding
15
+ });
16
+ return flatGeojsonToBinary(flatFeatures, geometryInfo, {
17
+ numericPropKeys: options.numericPropKeys,
18
+ PositionDataType: options.PositionDataType || Float32Array
19
+ });
406
20
  }
407
21
  //# sourceMappingURL=geojson-to-binary.js.map
@@ -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","feature","geometry","type","add","coordinates","length","point","coord","line","flatten","polygon","Error","properties","key","val","undefined","isNumeric","size","Math","max","Object","keys","filter","k","GlobalFeatureIdsDataType","Uint32Array","Uint16Array","points","positions","globalFeatureIds","featureIds","numericProps","Array","fields","lines","pathIndices","polygons","polygonIndices","primitivePolygonIndices","object","propName","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","Number","isFinite"],"mappings":"AAUA,OAAO,SAASA,eAAT,CACLC,QADK,EAELC,OAA+B,GAAG,EAF7B,EAGW;AAChB,QAAMC,aAAa,GAAGC,SAAS,CAACH,QAAD,CAA/B;AACA,SAAOI,UAAU,CAACJ,QAAD,EAAWE,aAAX,EAA0B;AACzCG,IAAAA,WAAW,EAAEJ,OAAO,CAACI,WAAR,IAAuBH,aAAa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AAU,CAACC,GAAD,CAAvB;AACD;AACF;;AACD,SAAO6D,KAAP;AACD;;AAGD,SAASX,UAAT,CAAoBa,KAApB,EAA2BhB,MAA3B,EAAmCiB,WAAnC,EAAgD7F,WAAhD,EAAmE;AACjE,MAAIuF,KAAK,GAAGM,WAAW,GAAG7F,WAA1B;;AACA,OAAK,MAAMuB,KAAX,IAAoBqD,MAApB,EAA4B;AAC1BgB,IAAAA,KAAK,CAACf,GAAN,CAAUtD,KAAV,EAAiBgE,KAAjB;AACAA,IAAAA,KAAK,IAAIvF,WAAT;AACD;AACF;;AAGD,SAASyB,OAAT,CAAiBqE,MAAjB,EAAqC;AACnC,SAAO,GAAGC,MAAH,CAAU,GAAGD,MAAb,CAAP;AACD;;AAED,SAAS9D,SAAT,CAAmBgE,CAAnB,EAAoC;AAClC,SAAOC,MAAM,CAACC,QAAP,CAAgBF,CAAhB,CAAP;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 FirstPassData = {\n coordLength: number;\n numericPropKeys: string[];\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 numericPropKeys = {};\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, false is stored to prevent rechecking in the future\n numericPropKeys[key] =\n numericPropKeys[key] || numericPropKeys[key] === undefined\n ? isNumeric(val)\n : numericPropKeys[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(numericPropKeys).filter((k) => numericPropKeys[k])\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 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 object.numericProps[propName] = new Float32Array(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 isNumeric(x: any): boolean {\n return Number.isFinite(x);\n}\n"],"file":"geojson-to-binary.js"}
1
+ {"version":3,"sources":["../../src/lib/geojson-to-binary.ts"],"names":["extractGeometryInfo","geojsonToFlatGeojson","flatGeojsonToBinary","geojsonToBinary","features","options","fixRingWinding","geometryInfo","coordLength","flatFeatures","numericPropKeys","PositionDataType","Float32Array"],"mappings":"AAGA,SAAQA,mBAAR,QAAkC,yBAAlC;AACA,SAAQC,oBAAR,QAAmC,2BAAnC;AACA,SAAQC,mBAAR,QAAkC,0BAAlC;AAkBA,OAAO,SAASC,eAAT,CACLC,QADK,EAELC,OAA+B,GAAG;AAACC,EAAAA,cAAc,EAAE;AAAjB,CAF7B,EAGW;AAChB,QAAMC,YAAY,GAAGP,mBAAmB,CAACI,QAAD,CAAxC;AACA,QAAMI,WAAW,GAAGD,YAAY,CAACC,WAAjC;AACA,QAAM;AAACF,IAAAA;AAAD,MAAmBD,OAAzB;AACA,QAAMI,YAAY,GAAGR,oBAAoB,CAACG,QAAD,EAAW;AAACI,IAAAA,WAAD;AAAcF,IAAAA;AAAd,GAAX,CAAzC;AACA,SAAOJ,mBAAmB,CAACO,YAAD,EAAeF,YAAf,EAA6B;AACrDG,IAAAA,eAAe,EAAEL,OAAO,CAACK,eAD4B;AAErDC,IAAAA,gBAAgB,EAAEN,OAAO,CAACM,gBAAR,IAA4BC;AAFO,GAA7B,CAA1B;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,17 @@
1
+ import { Feature, FlatFeature } from '@loaders.gl/schema';
2
+ /**
3
+ * Options for `geojsonToFlatGeojson`
4
+ */
5
+ export declare type GeojsonToFlatGeojsonOptions = {
6
+ coordLength: number;
7
+ fixRingWinding: boolean;
8
+ };
9
+ /**
10
+ * Convert GeoJSON features to Flat GeoJSON features
11
+ *
12
+ * @param features
13
+ * @param options
14
+ * @returns an Array of Flat GeoJSON features
15
+ */
16
+ export declare function geojsonToFlatGeojson(features: Feature[], options?: GeojsonToFlatGeojsonOptions): FlatFeature[];
17
+ //# sourceMappingURL=geojson-to-flat-geojson.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geojson-to-flat-geojson.d.ts","sourceRoot":"","sources":["../../src/lib/geojson-to-flat-geojson.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,OAAO,EAAY,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAElE;;GAEG;AACH,oBAAY,2BAA2B,GAAG;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AASF;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,GAAE,2BAAoE,GAC5E,WAAW,EAAE,CAEf"}