@loaders.gl/gis 4.0.0-beta.2 → 4.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +708 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/{esm/lib → lib}/binary-to-geojson.js +2 -2
- package/dist/lib/binary-to-geojson.js.map +1 -0
- package/dist/{esm/lib → lib}/extract-geometry-info.js +1 -1
- package/dist/lib/extract-geometry-info.js.map +1 -0
- package/dist/lib/flat-geojson-to-binary-types.js.map +1 -0
- package/dist/lib/flat-geojson-to-binary.js.map +1 -0
- package/dist/{esm/lib → lib}/geojson-to-binary.js +3 -3
- package/dist/lib/geojson-to-binary.js.map +1 -0
- package/dist/{esm/lib → lib}/geojson-to-flat-geojson.js +1 -1
- package/dist/lib/geojson-to-flat-geojson.js.map +1 -0
- package/dist/lib/transform.js.map +1 -0
- package/package.json +16 -8
- package/src/lib/flat-geojson-to-binary.ts +0 -1
- package/dist/bundle.d.ts +0 -2
- package/dist/bundle.d.ts.map +0 -1
- package/dist/es5/bundle.js +0 -6
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/index.js +0 -53
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/lib/binary-to-geojson.js +0 -221
- package/dist/es5/lib/binary-to-geojson.js.map +0 -1
- package/dist/es5/lib/extract-geometry-info.js +0 -167
- package/dist/es5/lib/extract-geometry-info.js.map +0 -1
- package/dist/es5/lib/flat-geojson-to-binary-types.js +0 -2
- package/dist/es5/lib/flat-geojson-to-binary-types.js.map +0 -1
- package/dist/es5/lib/flat-geojson-to-binary.js +0 -355
- package/dist/es5/lib/flat-geojson-to-binary.js.map +0 -1
- package/dist/es5/lib/geojson-to-binary.js +0 -28
- package/dist/es5/lib/geojson-to-binary.js.map +0 -1
- package/dist/es5/lib/geojson-to-flat-geojson.js +0 -136
- package/dist/es5/lib/geojson-to-flat-geojson.js.map +0 -1
- package/dist/es5/lib/transform.js +0 -57
- package/dist/es5/lib/transform.js.map +0 -1
- package/dist/esm/bundle.js +0 -4
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/index.js +0 -6
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/lib/binary-to-geojson.js.map +0 -1
- package/dist/esm/lib/extract-geometry-info.js.map +0 -1
- package/dist/esm/lib/flat-geojson-to-binary-types.js.map +0 -1
- package/dist/esm/lib/flat-geojson-to-binary.js.map +0 -1
- package/dist/esm/lib/geojson-to-binary.js.map +0 -1
- package/dist/esm/lib/geojson-to-flat-geojson.js.map +0 -1
- package/dist/esm/lib/transform.js.map +0 -1
- package/src/bundle.ts +0 -4
- /package/dist/{esm/lib → lib}/flat-geojson-to-binary-types.js +0 -0
- /package/dist/{esm/lib → lib}/flat-geojson-to-binary.js +0 -0
- /package/dist/{esm/lib → lib}/transform.js +0 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { flatGeojsonToBinary } from "./lib/flat-geojson-to-binary.js";
|
|
2
|
+
export { geojsonToBinary } from "./lib/geojson-to-binary.js";
|
|
3
|
+
export { geojsonToFlatGeojson } from "./lib/geojson-to-flat-geojson.js";
|
|
4
|
+
export { binaryToGeojson, binaryToGeometry } from "./lib/binary-to-geojson.js";
|
|
5
|
+
export { transformBinaryCoords, transformGeoJsonCoords } from "./lib/transform.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["flatGeojsonToBinary","geojsonToBinary","geojsonToFlatGeojson","binaryToGeojson","binaryToGeometry","transformBinaryCoords","transformGeoJsonCoords"],"sources":["../src/index.ts"],"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, binaryToGeometry} from './lib/binary-to-geojson';\nexport {transformBinaryCoords, transformGeoJsonCoords} from './lib/transform';\n"],"mappings":"SAGQA,mBAAmB;AAAA,SACnBC,eAAe;AAAA,SACfC,oBAAoB;AAAA,SACpBC,eAAe,EAAEC,gBAAgB;AAAA,SACjCC,qBAAqB,EAAEC,sBAAsB"}
|
|
@@ -25,7 +25,7 @@ function getSingleFeature(data, globalFeatureId) {
|
|
|
25
25
|
return parseFeature(data, lastIndex, data.featureIds.value.length);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
throw new Error(
|
|
28
|
+
throw new Error(`featureId:${globalFeatureId} not found`);
|
|
29
29
|
}
|
|
30
30
|
function parseFeatures(data, type) {
|
|
31
31
|
const dataArray = normalizeInput(data, type);
|
|
@@ -41,7 +41,7 @@ export function binaryToGeometry(data, startIndex, endIndex) {
|
|
|
41
41
|
return polygonToGeoJson(data, startIndex, endIndex);
|
|
42
42
|
default:
|
|
43
43
|
const unexpectedInput = data;
|
|
44
|
-
throw new Error(
|
|
44
|
+
throw new Error(`Unsupported geometry type: ${unexpectedInput === null || unexpectedInput === void 0 ? void 0 : unexpectedInput.type}`);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
function normalizeInput(data, type) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binary-to-geojson.js","names":["binaryToGeojson","data","options","globalFeatureId","undefined","getSingleFeature","parseFeatures","type","dataArray","normalizeInput","lastIndex","lastValue","featureIds","value","i","length","currValue","globalFeatureIds","parseFeature","Error","parseFeatureCollection","binaryToGeometry","startIndex","endIndex","pointToGeoJson","lineStringToGeoJson","polygonToGeoJson","unexpectedInput","features","points","push","lines","polygons","geometry","properties","parseProperties","fields","parseFields","arguments","Object","assign","key","numericProps","Infinity","positions","polygonIndices","filter","x","primitivePolygonIndices","multi","coordinates","startRingIndex","endRingIndex","ringCoordinates","ringToGeoJson","startPolygonIndex","endPolygonIndex","polygonCoordinates","pathIndices","size","j","coord","Array","k","Number"],"sources":["../../src/lib/binary-to-geojson.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport type {\n BinaryGeometry,\n BinaryGeometryType,\n BinaryPointGeometry,\n BinaryLineGeometry,\n BinaryPolygonGeometry,\n BinaryFeatureCollection,\n BinaryFeature,\n // BinaryPointFeature,\n // BinaryLineFeature,\n // BinaryPolygonFeature,\n BinaryAttribute\n} from '@loaders.gl/schema';\nimport type {Feature, Geometry, Position, GeoJsonProperties} from '@loaders.gl/schema';\nimport type {\n Point,\n MultiPoint,\n LineString,\n MultiLineString,\n Polygon,\n MultiPolygon\n} from '@loaders.gl/schema';\n\n// Note:L We do not handle GeometryCollection, define a limited Geometry type that always has coordinates.\n// type FeatureGeometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon;\n\ntype BinaryToGeoJsonOptions = {\n type?: BinaryGeometryType;\n globalFeatureId?: number;\n};\n\n/**\n * Convert binary geometry representation to GeoJSON\n * @param data geometry data in binary representation\n * @param options\n * @param options.type Input data type: Point, LineString, or Polygon\n * @param options.featureId Global feature id. If specified, only a single feature is extracted\n * @return GeoJSON objects\n */\nexport function binaryToGeojson(\n data: BinaryFeatureCollection,\n options?: BinaryToGeoJsonOptions\n): Feature[] | Feature {\n const globalFeatureId = options?.globalFeatureId;\n if (globalFeatureId !== undefined) {\n return getSingleFeature(data, globalFeatureId);\n }\n return parseFeatures(data, options?.type);\n}\n\n/** @deprecated use `binaryToGeojson` or `binaryToGeometry` instead *\nexport function binaryToGeoJson(\n data: BinaryGeometry | BinaryFeatureCollection,\n type?: BinaryGeometryType,\n format: 'feature' | 'geometry' = 'feature'\n): Geometry | Feature[] {\n switch (format) {\n case 'feature':\n return parseFeatures(data as BinaryFeatureCollection, type);\n case 'geometry':\n return binaryToGeometry(data as any);\n default:\n throw new Error(format);\n }\n}\n*/\n\n/**\n * Return a single feature from a binary geometry representation as GeoJSON\n * @param data geometry data in binary representation\n * @return GeoJSON feature\n */\nfunction getSingleFeature(data: BinaryFeatureCollection, globalFeatureId: number): Feature {\n const dataArray = normalizeInput(data);\n for (const data of dataArray) {\n let lastIndex = 0;\n let lastValue = data.featureIds.value[0];\n\n // Scan through data until we find matching feature\n for (let i = 0; i < data.featureIds.value.length; i++) {\n const currValue = data.featureIds.value[i];\n if (currValue === lastValue) {\n // eslint-disable-next-line no-continue\n continue;\n }\n if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {\n return parseFeature(data, lastIndex, i);\n }\n lastIndex = i;\n lastValue = currValue;\n }\n\n if (globalFeatureId === data.globalFeatureIds.value[lastIndex]) {\n return parseFeature(data, lastIndex, data.featureIds.value.length);\n }\n }\n\n throw new Error(`featureId:${globalFeatureId} not found`);\n}\n\nfunction parseFeatures(data: BinaryFeatureCollection, type?: BinaryGeometryType): Feature[] {\n const dataArray = normalizeInput(data, type);\n return parseFeatureCollection(dataArray);\n}\n\n/** Parse input binary data and return a valid GeoJSON geometry object */\nexport function binaryToGeometry(\n data: BinaryGeometry,\n startIndex?: number,\n endIndex?: number\n): Geometry {\n switch (data.type) {\n case 'Point':\n return pointToGeoJson(data, startIndex, endIndex);\n case 'LineString':\n return lineStringToGeoJson(data, startIndex, endIndex);\n case 'Polygon':\n return polygonToGeoJson(data, startIndex, endIndex);\n default:\n const unexpectedInput: never = data;\n throw new Error(`Unsupported geometry type: ${(unexpectedInput as any)?.type}`);\n }\n}\n\n// Normalize features\n// Return an array of data objects, each of which have a type key\nfunction normalizeInput(data: BinaryFeatureCollection, type?: BinaryGeometryType): BinaryFeature[] {\n const features: BinaryFeature[] = [];\n if (data.points) {\n data.points.type = 'Point';\n features.push(data.points);\n }\n if (data.lines) {\n data.lines.type = 'LineString';\n features.push(data.lines);\n }\n if (data.polygons) {\n data.polygons.type = 'Polygon';\n features.push(data.polygons);\n }\n\n return features;\n}\n\n/** Parse input binary data and return an array of GeoJSON Features */\nfunction parseFeatureCollection(dataArray: BinaryFeature[]): Feature[] {\n const features: Feature[] = [];\n for (const data of dataArray) {\n if (data.featureIds.value.length === 0) {\n // eslint-disable-next-line no-continue\n continue;\n }\n let lastIndex = 0;\n let lastValue = data.featureIds.value[0];\n\n // Need to deduce start, end indices of each feature\n for (let i = 0; i < data.featureIds.value.length; i++) {\n const currValue = data.featureIds.value[i];\n if (currValue === lastValue) {\n // eslint-disable-next-line no-continue\n continue;\n }\n\n features.push(parseFeature(data, lastIndex, i));\n lastIndex = i;\n lastValue = currValue;\n }\n\n // Last feature\n features.push(parseFeature(data, lastIndex, data.featureIds.value.length));\n }\n return features;\n}\n\n/** Parse input binary data and return a single GeoJSON Feature */\nfunction parseFeature(data: BinaryFeature, startIndex?: number, endIndex?: number): Feature {\n const geometry = binaryToGeometry(data, startIndex, endIndex);\n const properties = parseProperties(data, startIndex, endIndex);\n const fields = parseFields(data, startIndex, endIndex);\n return {type: 'Feature', geometry, properties, ...fields};\n}\n\n/** Parse input binary data and return an object of fields */\nfunction parseFields(data, startIndex: number = 0, endIndex?: number): GeoJsonProperties {\n return data.fields && data.fields[data.featureIds.value[startIndex]];\n}\n\n/** Parse input binary data and return an object of properties */\nfunction parseProperties(data, startIndex: number = 0, endIndex?: number): GeoJsonProperties {\n const properties = Object.assign({}, data.properties[data.featureIds.value[startIndex]]);\n for (const key in data.numericProps) {\n properties[key] = data.numericProps[key].value[startIndex];\n }\n return properties;\n}\n\n/** Parse binary data of type Polygon */\nfunction polygonToGeoJson(\n data: BinaryPolygonGeometry,\n startIndex: number = -Infinity,\n endIndex: number = Infinity\n): Polygon | MultiPolygon {\n const {positions} = data;\n const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);\n const primitivePolygonIndices = data.primitivePolygonIndices.value.filter(\n (x) => x >= startIndex && x <= endIndex\n );\n const multi = polygonIndices.length > 2;\n\n // Polygon\n if (!multi) {\n const coordinates: Position[][] = [];\n for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {\n const startRingIndex = primitivePolygonIndices[i];\n const endRingIndex = primitivePolygonIndices[i + 1];\n const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);\n coordinates.push(ringCoordinates);\n }\n\n return {type: 'Polygon', coordinates};\n }\n\n // MultiPolygon\n const coordinates: Position[][][] = [];\n for (let i = 0; i < polygonIndices.length - 1; i++) {\n const startPolygonIndex = polygonIndices[i];\n const endPolygonIndex = polygonIndices[i + 1];\n const polygonCoordinates = polygonToGeoJson(\n data,\n startPolygonIndex,\n endPolygonIndex\n ).coordinates;\n coordinates.push(polygonCoordinates as Position[][]);\n }\n\n return {type: 'MultiPolygon', coordinates};\n}\n\n/** Parse binary data of type LineString */\nfunction lineStringToGeoJson(\n data: BinaryLineGeometry,\n startIndex: number = -Infinity,\n endIndex: number = Infinity\n): LineString | MultiLineString {\n const {positions} = data;\n const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);\n const multi = pathIndices.length > 2;\n\n if (!multi) {\n const coordinates = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);\n return {type: 'LineString', coordinates};\n }\n\n const coordinates: Position[][] = [];\n for (let i = 0; i < pathIndices.length - 1; i++) {\n const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);\n coordinates.push(ringCoordinates);\n }\n\n return {type: 'MultiLineString', coordinates};\n}\n\n/** Parse binary data of type Point */\nfunction pointToGeoJson(data: BinaryPointGeometry, startIndex, endIndex): Point | MultiPoint {\n const {positions} = data;\n const coordinates = ringToGeoJson(positions, startIndex, endIndex);\n const multi = coordinates.length > 1;\n\n if (multi) {\n return {type: 'MultiPoint', coordinates};\n }\n\n return {type: 'Point', coordinates: coordinates[0]};\n}\n\n/**\n * Parse a linear ring of positions to a GeoJSON linear ring\n *\n * @param positions Positions TypedArray\n * @param startIndex Start index to include in ring\n * @param endIndex End index to include in ring\n * @returns GeoJSON ring\n */\nfunction ringToGeoJson(\n positions: BinaryAttribute,\n startIndex?: number,\n endIndex?: number\n): Position[] {\n startIndex = startIndex || 0;\n endIndex = endIndex || positions.value.length / positions.size;\n\n const ringCoordinates: Position[] = [];\n for (let j = startIndex; j < endIndex; j++) {\n const coord = Array<number>();\n for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {\n coord.push(Number(positions.value[k]));\n }\n ringCoordinates.push(coord);\n }\n return ringCoordinates;\n}\n"],"mappings":"AAyCA,OAAO,SAASA,eAAeA,CAC7BC,IAA6B,EAC7BC,OAAgC,EACX;EACrB,MAAMC,eAAe,GAAGD,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEC,eAAe;EAChD,IAAIA,eAAe,KAAKC,SAAS,EAAE;IACjC,OAAOC,gBAAgB,CAACJ,IAAI,EAAEE,eAAe,CAAC;EAChD;EACA,OAAOG,aAAa,CAACL,IAAI,EAAEC,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEK,IAAI,CAAC;AAC3C;AAwBA,SAASF,gBAAgBA,CAACJ,IAA6B,EAAEE,eAAuB,EAAW;EACzF,MAAMK,SAAS,GAAGC,cAAc,CAACR,IAAI,CAAC;EACtC,KAAK,MAAMA,IAAI,IAAIO,SAAS,EAAE;IAC5B,IAAIE,SAAS,GAAG,CAAC;IACjB,IAAIC,SAAS,GAAGV,IAAI,CAACW,UAAU,CAACC,KAAK,CAAC,CAAC,CAAC;IAGxC,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGb,IAAI,CAACW,UAAU,CAACC,KAAK,CAACE,MAAM,EAAED,CAAC,EAAE,EAAE;MACrD,MAAME,SAAS,GAAGf,IAAI,CAACW,UAAU,CAACC,KAAK,CAACC,CAAC,CAAC;MAC1C,IAAIE,SAAS,KAAKL,SAAS,EAAE;QAE3B;MACF;MACA,IAAIR,eAAe,KAAKF,IAAI,CAACgB,gBAAgB,CAACJ,KAAK,CAACH,SAAS,CAAC,EAAE;QAC9D,OAAOQ,YAAY,CAACjB,IAAI,EAAES,SAAS,EAAEI,CAAC,CAAC;MACzC;MACAJ,SAAS,GAAGI,CAAC;MACbH,SAAS,GAAGK,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,EAAE,EAAE;IAC1C,MAAMC,KAAK,GAAGC,KAAK,CAAS,CAAC;IAC7B,KAAK,IAAIC,CAAC,GAAGH,CAAC,GAAGhB,SAAS,CAACe,IAAI,EAAEI,CAAC,GAAG,CAACH,CAAC,GAAG,CAAC,IAAIhB,SAAS,CAACe,IAAI,EAAEI,CAAC,EAAE,EAAE;MAClEF,KAAK,CAAC/B,IAAI,CAACkC,MAAM,CAACpB,SAAS,CAAC/B,KAAK,CAACkD,CAAC,CAAC,CAAC,CAAC;IACxC;IACAV,eAAe,CAACvB,IAAI,CAAC+B,KAAK,CAAC;EAC7B;EACA,OAAOR,eAAe;AACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-geometry-info.js","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"],"sources":["../../src/lib/extract-geometry-info.ts"],"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"],"mappings":"AAQA,OAAO,SAASA,mBAAmBA,CAACC,QAAmB,EAAuB;EAE5E,IAAIC,mBAAmB,GAAG,CAAC;EAC3B,IAAIC,kBAAkB,GAAG,CAAC;EAC1B,IAAIC,kBAAkB,GAAG,CAAC;EAC1B,IAAIC,cAAc,GAAG,CAAC;EACtB,IAAIC,iBAAiB,GAAG,CAAC;EACzB,IAAIC,qBAAqB,GAAG,CAAC;EAC7B,IAAIC,mBAAmB,GAAG,CAAC;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D,MAAMI,SAAS,GAAGR,QAAQ,CAACG,WAAW,CAACM,IAAI,CAAC,CAAC;QAC7ChB,qBAAqB,IAAIe,SAAS,CAACJ,MAAM;QAEzC,KAAK,MAAME,KAAK,IAAIE,SAAS,EAAE;UAC7BX,YAAY,CAACK,GAAG,CAACI,KAAK,CAACF,MAAM,CAAC;QAChC;QACA;MACF,KAAK,cAAc;QACjBR,oBAAoB,EAAE;QACtB,KAAK,MAAMc,OAAO,IAAIV,QAAQ,CAACG,WAAW,EAAE;UAC1CT,mBAAmB,EAAE;UACrBC,iBAAiB,IAAIe,OAAO,CAACN,MAAM;UACnC,MAAMI,SAAS,GAAGE,OAAO,CAACD,IAAI,CAAC,CAAC;UAChChB,qBAAqB,IAAIe,SAAS,CAACJ,MAAM;UAGzC,KAAK,MAAME,KAAK,IAAIE,SAAS,EAAE;YAC7BX,YAAY,CAACK,GAAG,CAACI,KAAK,CAACF,MAAM,CAAC;UAChC;QACF;QACA;MACF;QACE,MAAM,IAAIO,KAAK,CAAE,8BAA6BX,QAAQ,CAACC,IAAK,EAAC,CAAC;IAClE;EACF;EAEA,OAAO;IACLW,WAAW,EAAEf,YAAY,CAACgB,IAAI,GAAG,CAAC,GAAGC,IAAI,CAACC,GAAG,CAAC,GAAGlB,YAAY,CAAC,GAAG,CAAC;IAElET,mBAAmB;IACnBC,kBAAkB;IAClBC,kBAAkB;IAClBC,cAAc;IACdC,iBAAiB;IACjBC,qBAAqB;IACrBC,mBAAmB;IACnBC,iBAAiB;IACjBC;EACF,CAAC;AACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flat-geojson-to-binary-types.js","names":[],"sources":["../../src/lib/flat-geojson-to-binary-types.ts"],"sourcesContent":["import type {TypedArray} from '@loaders.gl/schema';\n\n/**\n * Permissable constructor for numeric props\n */\nexport type PropArrayConstructor =\n | Float32ArrayConstructor\n | Float64ArrayConstructor\n | ArrayConstructor;\n\n/**\n * Collection type for holding intermediate binary data before conversion to `BinaryPointGeometry`\n */\nexport type Points = {\n type: 'Point';\n positions: Float32Array | Float64Array;\n globalFeatureIds: Uint16Array | Uint32Array;\n featureIds: Uint16Array | Uint32Array;\n numericProps: {[key: string]: TypedArray};\n properties: {}[];\n fields: {\n id?: string | number;\n }[];\n};\n\n/**\n * Collection type for holding intermediate binary data before conversion to `BinaryLineStringGeometry`\n */\nexport type Lines = {\n type: 'LineString';\n positions: Float32Array | Float64Array;\n pathIndices: Uint16Array | Uint32Array;\n globalFeatureIds: Uint16Array | Uint32Array;\n featureIds: Uint16Array | Uint32Array;\n numericProps: {[key: string]: TypedArray};\n properties: {}[];\n fields: {\n id?: string | number;\n }[];\n};\n\n/**\n * Collection type for holding intermediate binary data before conversion to `BinaryPolygonGeometry`\n */\nexport type Polygons = {\n type: 'Polygon';\n positions: Float32Array | Float64Array;\n polygonIndices: Uint16Array | Uint32Array;\n primitivePolygonIndices: Uint16Array | Uint32Array;\n triangles?: number[];\n globalFeatureIds: Uint16Array | Uint32Array;\n featureIds: Uint16Array | Uint32Array;\n numericProps: {[key: string]: TypedArray};\n properties: {}[];\n fields: {\n id?: string | number;\n }[];\n};\n"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flat-geojson-to-binary.js","names":["earcut","flatGeojsonToBinary","features","geometryInfo","options","propArrayTypes","extractNumericPropTypes","numericPropKeys","Object","keys","filter","k","Array","fillArrays","PositionDataType","Float32Array","triangulate","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","_ref","polygonPositions","subarray","offset","holes","slice","map","n","t","tl","wrapProps","obj","size","returnObj","value","binaryFeatures","index","numericPropName","numericKeys","props","includes","x","constructor","Number","isFinite","Float64Array","Math","fround"],"sources":["../../src/lib/flat-geojson-to-binary.ts"],"sourcesContent":["/* eslint-disable indent */\nimport {earcut} from '@math.gl/polygon';\nimport type {\n BinaryAttribute,\n BinaryFeatureCollection,\n BinaryPolygonFeature,\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 triangulate: options ? options.triangulate : true\n }\n );\n}\n\n/**\n * Options for `flatGeojsonToBinary`\n */\nexport type FlatGeojsonToBinaryOptions = {\n numericPropKeys?: string[];\n PositionDataType?: Float32ArrayConstructor | Float64ArrayConstructor;\n triangulate?: boolean;\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, max-statements\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, triangulate = true} = 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 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 if (triangulate) {\n polygons.triangles = [];\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 if (!polygons.triangles) {\n return;\n }\n\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): BinaryFeatureCollection {\n const binaryFeatures: BinaryFeatureCollection = {\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 globalFeatureIds: {value: polygons.globalFeatureIds, size: 1},\n featureIds: {value: polygons.featureIds, size: 1},\n numericProps: wrapProps(polygons.numericProps, 1)\n } as BinaryPolygonFeature // triangles not expected\n };\n\n if (binaryFeatures.polygons && polygons.triangles) {\n binaryFeatures.polygons.triangles = {value: new Uint32Array(polygons.triangles), size: 1};\n }\n\n return binaryFeatures;\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"],"mappings":"AACA,SAAQA,MAAM,QAAO,kBAAkB;AA2BvC,OAAO,SAASC,mBAAmBA,CACjCC,QAAuB,EACvBC,YAAiC,EACjCC,OAAoC,EACpC;EACA,MAAMC,cAAc,GAAGC,uBAAuB,CAACJ,QAAQ,CAAC;EACxD,MAAMK,eAAe,GAAGC,MAAM,CAACC,IAAI,CAACJ,cAAc,CAAC,CAACK,MAAM,CAAEC,CAAC,IAAKN,cAAc,CAACM,CAAC,CAAC,KAAKC,KAAK,CAAC;EAC9F,OAAOC,UAAU,CACfX,QAAQ,EACR;IACEG,cAAc;IACd,GAAGF;EACL,CAAC,EACD;IACEI,eAAe,EAAGH,OAAO,IAAIA,OAAO,CAACG,eAAe,IAAKA,eAAe;IACxEO,gBAAgB,EAAEV,OAAO,GAAGA,OAAO,CAACU,gBAAgB,GAAGC,YAAY;IACnEC,WAAW,EAAEZ,OAAO,GAAGA,OAAO,CAACY,WAAW,GAAG;EAC/C,CACF,CAAC;AACH;AAWA,OAAO,MAAMC,YAAY,GAAG;EAC1BX;AACF,CAAC;AAQD,SAASA,uBAAuBA,CAACJ,QAAuB,EAEtD;EACA,MAAMG,cAAc,GAAG,CAAC,CAAC;EACzB,KAAK,MAAMa,OAAO,IAAIhB,QAAQ,EAAE;IAC9B,IAAIgB,OAAO,CAACC,UAAU,EAAE;MACtB,KAAK,MAAMC,GAAG,IAAIF,OAAO,CAACC,UAAU,EAAE;QAKpC,MAAME,GAAG,GAAGH,OAAO,CAACC,UAAU,CAACC,GAAG,CAAC;QACnCf,cAAc,CAACe,GAAG,CAAC,GAAGE,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,CAACH,CAAC,CAAC,EAAE;IAChD,OAAOpG,KAAK;EACd;EAGA,OAAOqG,WAAW,KAAKG,YAAY,IAAIC,IAAI,CAACC,MAAM,CAACN,CAAC,CAAC,KAAKA,CAAC,GAAGI,YAAY,GAAGrG,YAAY;AAC3F"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { extractGeometryInfo } from
|
|
2
|
-
import { geojsonToFlatGeojson } from
|
|
3
|
-
import { flatGeojsonToBinary } from
|
|
1
|
+
import { extractGeometryInfo } from "./extract-geometry-info.js";
|
|
2
|
+
import { geojsonToFlatGeojson } from "./geojson-to-flat-geojson.js";
|
|
3
|
+
import { flatGeojsonToBinary } from "./flat-geojson-to-binary.js";
|
|
4
4
|
export function geojsonToBinary(features) {
|
|
5
5
|
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
6
6
|
fixRingWinding: true,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geojson-to-binary.js","names":["extractGeometryInfo","geojsonToFlatGeojson","flatGeojsonToBinary","geojsonToBinary","features","options","arguments","length","undefined","fixRingWinding","triangulate","geometryInfo","coordLength","flatFeatures","numericPropKeys","PositionDataType","Float32Array"],"sources":["../../src/lib/geojson-to-binary.ts"],"sourcesContent":["import type {Feature} from '@loaders.gl/schema';\nimport type {BinaryFeatureCollection} 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 triangulate?: boolean;\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, triangulate: true}\n): BinaryFeatureCollection {\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 triangulate: options.triangulate\n });\n}\n"],"mappings":"SAGQA,mBAAmB;AAAA,SACnBC,oBAAoB;AAAA,SACpBC,mBAAmB;AAmB3B,OAAO,SAASC,eAAeA,CAC7BC,QAAmB,EAEM;EAAA,IADzBC,OAA+B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IAACG,cAAc,EAAE,IAAI;IAAEC,WAAW,EAAE;EAAI,CAAC;EAE3E,MAAMC,YAAY,GAAGX,mBAAmB,CAACI,QAAQ,CAAC;EAClD,MAAMQ,WAAW,GAAGD,YAAY,CAACC,WAAW;EAC5C,MAAM;IAACH;EAAc,CAAC,GAAGJ,OAAO;EAChC,MAAMQ,YAAY,GAAGZ,oBAAoB,CAACG,QAAQ,EAAE;IAACQ,WAAW;IAAEH;EAAc,CAAC,CAAC;EAClF,OAAOP,mBAAmB,CAACW,YAAY,EAAEF,YAAY,EAAE;IACrDG,eAAe,EAAET,OAAO,CAACS,eAAe;IACxCC,gBAAgB,EAAEV,OAAO,CAACU,gBAAgB,IAAIC,YAAY;IAC1DN,WAAW,EAAEL,OAAO,CAACK;EACvB,CAAC,CAAC;AACJ"}
|
|
@@ -82,7 +82,7 @@ function flattenFeature(feature, options) {
|
|
|
82
82
|
geometry.coordinates.map(c => flattenPolygon(c, data, indices, areas, options));
|
|
83
83
|
break;
|
|
84
84
|
default:
|
|
85
|
-
throw new Error(
|
|
85
|
+
throw new Error(`Unknown type: ${type}`);
|
|
86
86
|
}
|
|
87
87
|
return {
|
|
88
88
|
...feature,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geojson-to-flat-geojson.js","names":["getPolygonSignedArea","geojsonToFlatGeojson","features","options","arguments","length","undefined","coordLength","fixRingWinding","map","feature","flattenFeature","flattenPoint","coordinates","data","indices","push","i","flattenLineString","c","flattenPolygon","areas","count","ringAreas","polygons","lineString","lineString2d","p","slice","area","flat","ccw","reverse","geometry","type","Error"],"sources":["../../src/lib/geojson-to-flat-geojson.ts"],"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"],"mappings":"AAAA,SAAQA,oBAAoB,QAAO,kBAAkB;AA0BrD,OAAO,SAASC,oBAAoBA,CAClCC,QAAmB,EAEJ;EAAA,IADfC,OAAoC,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG;IAACG,WAAW,EAAE,CAAC;IAAEC,cAAc,EAAE;EAAI,CAAC;EAE7E,OAAON,QAAQ,CAACO,GAAG,CAAEC,OAAO,IAAKC,cAAc,CAACD,OAAO,EAAEP,OAAO,CAAC,CAAC;AACpE;AAUA,SAASS,YAAYA,CACnBC,WAA6B,EAC7BC,IAAc,EACdC,OAAiB,EACjBZ,OAAoC,EACpC;EACAY,OAAO,CAACC,IAAI,CAACF,IAAI,CAACT,MAAM,CAAC;EACzBS,IAAI,CAACE,IAAI,CAAC,GAAGH,WAAW,CAAC;EAGzB,KAAK,IAAII,CAAC,GAAGJ,WAAW,CAACR,MAAM,EAAEY,CAAC,GAAGd,OAAO,CAACI,WAAW,EAAEU,CAAC,EAAE,EAAE;IAC7DH,IAAI,CAACE,IAAI,CAAC,CAAC,CAAC;EACd;AACF;AAUA,SAASE,iBAAiBA,CACxBL,WAAkC,EAClCC,IAAc,EACdC,OAAiB,EACjBZ,OAAoC,EACpC;EACAY,OAAO,CAACC,IAAI,CAACF,IAAI,CAACT,MAAM,CAAC;EACzB,KAAK,MAAMc,CAAC,IAAIN,WAAW,EAAE;IAC3BC,IAAI,CAACE,IAAI,CAAC,GAAGG,CAAC,CAAC;IAGf,KAAK,IAAIF,CAAC,GAAGE,CAAC,CAACd,MAAM,EAAEY,CAAC,GAAGd,OAAO,CAACI,WAAW,EAAEU,CAAC,EAAE,EAAE;MACnDH,IAAI,CAACE,IAAI,CAAC,CAAC,CAAC;IACd;EACF;A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AAE;MAACC,IAAI;MAAEnB,OAAO;MAAED,IAAI;MAAEO;IAAK;EAAC,CAAC;AAC7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.js","names":["transformBinaryCoords","binaryFeatures","transformCoordinate","points","transformBinaryGeometryPositions","lines","polygons","binaryGeometry","fn","positions","i","value","length","size","coord","Array","from","subarray","transformedCoord","set","transformGeoJsonCoords","features","feature","geometry","coordinates","coordMap","array","isCoord","map","item","isArray","Number","isFinite"],"sources":["../../src/lib/transform.ts"],"sourcesContent":["import type {BinaryFeatureCollection, BinaryGeometry, Feature} from '@loaders.gl/schema';\n\ntype TransformCoordinate = (coord: number[]) => number[];\n\n/**\n * Apply transformation to every coordinate of binary features\n * @param binaryFeatures binary features\n * @param transformCoordinate Function to call on each coordinate\n * @return Transformed binary features\n */\nexport function transformBinaryCoords(\n binaryFeatures: BinaryFeatureCollection,\n transformCoordinate: TransformCoordinate\n): BinaryFeatureCollection {\n if (binaryFeatures.points) {\n transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate);\n }\n if (binaryFeatures.lines) {\n transformBinaryGeometryPositions(binaryFeatures.lines, transformCoordinate);\n }\n if (binaryFeatures.polygons) {\n transformBinaryGeometryPositions(binaryFeatures.polygons, transformCoordinate);\n }\n return binaryFeatures;\n}\n\n/** Transform one binary geometry */\nfunction transformBinaryGeometryPositions(binaryGeometry: BinaryGeometry, fn: TransformCoordinate) {\n const {positions} = binaryGeometry;\n for (let i = 0; i < positions.value.length; i += positions.size) {\n // @ts-ignore inclusion of bigint causes problems\n const coord: Array<number> = Array.from(positions.value.subarray(i, i + positions.size));\n const transformedCoord = fn(coord);\n // @ts-ignore typescript typing for .set seems to require bigint?\n positions.value.set(transformedCoord, i);\n }\n}\n\n/**\n * Apply transformation to every coordinate of GeoJSON features\n *\n * @param features Array of GeoJSON features\n * @param fn Function to call on each coordinate\n * @return Transformed GeoJSON features\n */\nexport function transformGeoJsonCoords(\n features: Feature[],\n fn: (coord: number[]) => number[]\n): Feature[] {\n for (const feature of features) {\n // @ts-ignore\n feature.geometry.coordinates = coordMap(feature.geometry.coordinates, fn);\n }\n return features;\n}\n\nfunction coordMap(array: unknown, fn: (coord: number[]) => number[]): unknown[] {\n if (isCoord(array)) {\n return fn(array as number[]);\n }\n\n return (array as unknown[]).map((item) => {\n return coordMap(item, fn);\n });\n}\n\nfunction isCoord(array: unknown) {\n return Array.isArray(array) && Number.isFinite(array[0]) && Number.isFinite(array[1]);\n}\n"],"mappings":"AAUA,OAAO,SAASA,qBAAqBA,CACnCC,cAAuC,EACvCC,mBAAwC,EACf;EACzB,IAAID,cAAc,CAACE,MAAM,EAAE;IACzBC,gCAAgC,CAACH,cAAc,CAACE,MAAM,EAAED,mBAAmB,CAAC;EAC9E;EACA,IAAID,cAAc,CAACI,KAAK,EAAE;IACxBD,gCAAgC,CAACH,cAAc,CAACI,KAAK,EAAEH,mBAAmB,CAAC;EAC7E;EACA,IAAID,cAAc,CAACK,QAAQ,EAAE;IAC3BF,gCAAgC,CAACH,cAAc,CAACK,QAAQ,EAAEJ,mBAAmB,CAAC;EAChF;EACA,OAAOD,cAAc;AACvB;AAGA,SAASG,gCAAgCA,CAACG,cAA8B,EAAEC,EAAuB,EAAE;EACjG,MAAM;IAACC;EAAS,CAAC,GAAGF,cAAc;EAClC,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGD,SAAS,CAACE,KAAK,CAACC,MAAM,EAAEF,CAAC,IAAID,SAAS,CAACI,IAAI,EAAE;IAE/D,MAAMC,KAAoB,GAAGC,KAAK,CAACC,IAAI,CAACP,SAAS,CAACE,KAAK,CAACM,QAAQ,CAACP,CAAC,EAAEA,CAAC,GAAGD,SAAS,CAACI,IAAI,CAAC,CAAC;IACxF,MAAMK,gBAAgB,GAAGV,EAAE,CAACM,KAAK,CAAC;IAElCL,SAAS,CAACE,KAAK,CAACQ,GAAG,CAACD,gBAAgB,EAAER,CAAC,CAAC;EAC1C;AACF;AASA,OAAO,SAASU,sBAAsBA,CACpCC,QAAmB,EACnBb,EAAiC,EACtB;EACX,KAAK,MAAMc,OAAO,IAAID,QAAQ,EAAE;IAE9BC,OAAO,CAACC,QAAQ,CAACC,WAAW,GAAGC,QAAQ,CAACH,OAAO,CAACC,QAAQ,CAACC,WAAW,EAAEhB,EAAE,CAAC;EAC3E;EACA,OAAOa,QAAQ;AACjB;AAEA,SAASI,QAAQA,CAACC,KAAc,EAAElB,EAAiC,EAAa;EAC9E,IAAImB,OAAO,CAACD,KAAK,CAAC,EAAE;IAClB,OAAOlB,EAAE,CAACkB,KAAiB,CAAC;EAC9B;EAEA,OAAQA,KAAK,CAAeE,GAAG,CAAEC,IAAI,IAAK;IACxC,OAAOJ,QAAQ,CAACI,IAAI,EAAErB,EAAE,CAAC;EAC3B,CAAC,CAAC;AACJ;AAEA,SAASmB,OAAOA,CAACD,KAAc,EAAE;EAC/B,OAAOX,KAAK,CAACe,OAAO,CAACJ,KAAK,CAAC,IAAIK,MAAM,CAACC,QAAQ,CAACN,KAAK,CAAC,CAAC,CAAC,CAAC,IAAIK,MAAM,CAACC,QAAQ,CAACN,KAAK,CAAC,CAAC,CAAC,CAAC;AACvF"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/gis",
|
|
3
3
|
"description": "Helpers for GIS category data",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.3",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"publishConfig": {
|
|
7
8
|
"access": "public"
|
|
8
9
|
},
|
|
@@ -15,8 +16,15 @@
|
|
|
15
16
|
"GeoJSON"
|
|
16
17
|
],
|
|
17
18
|
"types": "dist/index.d.ts",
|
|
18
|
-
"main": "dist/
|
|
19
|
-
"module": "dist/
|
|
19
|
+
"main": "dist/index.cjs",
|
|
20
|
+
"module": "dist/index.js",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": "./dist/index.js",
|
|
24
|
+
"require": "./dist/index.cjs",
|
|
25
|
+
"types": "./dist/index.d.ts"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
20
28
|
"sideEffects": false,
|
|
21
29
|
"files": [
|
|
22
30
|
"src",
|
|
@@ -24,14 +32,14 @@
|
|
|
24
32
|
"README.md"
|
|
25
33
|
],
|
|
26
34
|
"dependencies": {
|
|
27
|
-
"@loaders.gl/loader-utils": "4.0.0-beta.
|
|
28
|
-
"@loaders.gl/schema": "4.0.0-beta.
|
|
35
|
+
"@loaders.gl/loader-utils": "4.0.0-beta.3",
|
|
36
|
+
"@loaders.gl/schema": "4.0.0-beta.3",
|
|
29
37
|
"@mapbox/vector-tile": "^1.3.1",
|
|
30
|
-
"@math.gl/polygon": "^
|
|
38
|
+
"@math.gl/polygon": "^4.0.0",
|
|
31
39
|
"pbf": "^3.2.1"
|
|
32
40
|
},
|
|
33
41
|
"devDependencies": {
|
|
34
|
-
"@math.gl/proj4": "^
|
|
42
|
+
"@math.gl/proj4": "^4.0.0"
|
|
35
43
|
},
|
|
36
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "7ba9621cc51c7a26c407086ac86171f35b8712af"
|
|
37
45
|
}
|
|
@@ -444,7 +444,6 @@ function triangulatePolygon(
|
|
|
444
444
|
const holes = indices.slice(1).map((n: number) => (n - offset) / coordLength);
|
|
445
445
|
|
|
446
446
|
// Compute triangulation
|
|
447
|
-
// @ts-expect-error TODO can earcut handle binary arrays? Add tests?
|
|
448
447
|
const triangles = earcut(polygonPositions, holes, coordLength, areas);
|
|
449
448
|
|
|
450
449
|
// Indices returned by triangulation are relative to start
|
package/dist/bundle.d.ts
DELETED
package/dist/bundle.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,aAAa,KAAqB,CAAC"}
|
package/dist/es5/bundle.js
DELETED
package/dist/es5/bundle.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.js","names":["moduleExports","require","globalThis","loaders","module","exports","Object","assign"],"sources":["../../src/bundle.ts"],"sourcesContent":["// @ts-nocheck\nconst moduleExports = require('./index');\nglobalThis.loaders = globalThis.loaders || {};\nmodule.exports = Object.assign(globalThis.loaders, moduleExports);\n"],"mappings":";;AACA,IAAMA,aAAa,GAAGC,OAAO,CAAC,SAAS,CAAC;AACxCC,UAAU,CAACC,OAAO,GAAGD,UAAU,CAACC,OAAO,IAAI,CAAC,CAAC;AAC7CC,MAAM,CAACC,OAAO,GAAGC,MAAM,CAACC,MAAM,CAACL,UAAU,CAACC,OAAO,EAAEH,aAAa,CAAC"}
|
package/dist/es5/index.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "binaryToGeojson", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function get() {
|
|
9
|
-
return _binaryToGeojson.binaryToGeojson;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "binaryToGeometry", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function get() {
|
|
15
|
-
return _binaryToGeojson.binaryToGeometry;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "flatGeojsonToBinary", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function get() {
|
|
21
|
-
return _flatGeojsonToBinary.flatGeojsonToBinary;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "geojsonToBinary", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function get() {
|
|
27
|
-
return _geojsonToBinary.geojsonToBinary;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(exports, "geojsonToFlatGeojson", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function get() {
|
|
33
|
-
return _geojsonToFlatGeojson.geojsonToFlatGeojson;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(exports, "transformBinaryCoords", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function get() {
|
|
39
|
-
return _transform.transformBinaryCoords;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(exports, "transformGeoJsonCoords", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
get: function get() {
|
|
45
|
-
return _transform.transformGeoJsonCoords;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
var _flatGeojsonToBinary = require("./lib/flat-geojson-to-binary");
|
|
49
|
-
var _geojsonToBinary = require("./lib/geojson-to-binary");
|
|
50
|
-
var _geojsonToFlatGeojson = require("./lib/geojson-to-flat-geojson");
|
|
51
|
-
var _binaryToGeojson = require("./lib/binary-to-geojson");
|
|
52
|
-
var _transform = require("./lib/transform");
|
|
53
|
-
//# sourceMappingURL=index.js.map
|
package/dist/es5/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_flatGeojsonToBinary","require","_geojsonToBinary","_geojsonToFlatGeojson","_binaryToGeojson","_transform"],"sources":["../../src/index.ts"],"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, binaryToGeometry} from './lib/binary-to-geojson';\nexport {transformBinaryCoords, transformGeoJsonCoords} from './lib/transform';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,IAAAA,oBAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,qBAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA"}
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.binaryToGeojson = binaryToGeojson;
|
|
8
|
-
exports.binaryToGeometry = binaryToGeometry;
|
|
9
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
11
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
12
|
-
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; } } }; }
|
|
13
|
-
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); }
|
|
14
|
-
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; }
|
|
15
|
-
function binaryToGeojson(data, options) {
|
|
16
|
-
var globalFeatureId = options === null || options === void 0 ? void 0 : options.globalFeatureId;
|
|
17
|
-
if (globalFeatureId !== undefined) {
|
|
18
|
-
return getSingleFeature(data, globalFeatureId);
|
|
19
|
-
}
|
|
20
|
-
return parseFeatures(data, options === null || options === void 0 ? void 0 : options.type);
|
|
21
|
-
}
|
|
22
|
-
function getSingleFeature(data, globalFeatureId) {
|
|
23
|
-
var dataArray = normalizeInput(data);
|
|
24
|
-
for (var _i = 0, _dataArray = dataArray; _i < _dataArray.length; _i++) {
|
|
25
|
-
var _data = _dataArray[_i];
|
|
26
|
-
var lastIndex = 0;
|
|
27
|
-
var lastValue = _data.featureIds.value[0];
|
|
28
|
-
for (var i = 0; i < _data.featureIds.value.length; i++) {
|
|
29
|
-
var currValue = _data.featureIds.value[i];
|
|
30
|
-
if (currValue === lastValue) {
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (globalFeatureId === _data.globalFeatureIds.value[lastIndex]) {
|
|
34
|
-
return parseFeature(_data, lastIndex, i);
|
|
35
|
-
}
|
|
36
|
-
lastIndex = i;
|
|
37
|
-
lastValue = currValue;
|
|
38
|
-
}
|
|
39
|
-
if (globalFeatureId === _data.globalFeatureIds.value[lastIndex]) {
|
|
40
|
-
return parseFeature(_data, lastIndex, _data.featureIds.value.length);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
throw new Error("featureId:".concat(globalFeatureId, " not found"));
|
|
44
|
-
}
|
|
45
|
-
function parseFeatures(data, type) {
|
|
46
|
-
var dataArray = normalizeInput(data, type);
|
|
47
|
-
return parseFeatureCollection(dataArray);
|
|
48
|
-
}
|
|
49
|
-
function binaryToGeometry(data, startIndex, endIndex) {
|
|
50
|
-
switch (data.type) {
|
|
51
|
-
case 'Point':
|
|
52
|
-
return pointToGeoJson(data, startIndex, endIndex);
|
|
53
|
-
case 'LineString':
|
|
54
|
-
return lineStringToGeoJson(data, startIndex, endIndex);
|
|
55
|
-
case 'Polygon':
|
|
56
|
-
return polygonToGeoJson(data, startIndex, endIndex);
|
|
57
|
-
default:
|
|
58
|
-
var unexpectedInput = data;
|
|
59
|
-
throw new Error("Unsupported geometry type: ".concat(unexpectedInput === null || unexpectedInput === void 0 ? void 0 : unexpectedInput.type));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function normalizeInput(data, type) {
|
|
63
|
-
var features = [];
|
|
64
|
-
if (data.points) {
|
|
65
|
-
data.points.type = 'Point';
|
|
66
|
-
features.push(data.points);
|
|
67
|
-
}
|
|
68
|
-
if (data.lines) {
|
|
69
|
-
data.lines.type = 'LineString';
|
|
70
|
-
features.push(data.lines);
|
|
71
|
-
}
|
|
72
|
-
if (data.polygons) {
|
|
73
|
-
data.polygons.type = 'Polygon';
|
|
74
|
-
features.push(data.polygons);
|
|
75
|
-
}
|
|
76
|
-
return features;
|
|
77
|
-
}
|
|
78
|
-
function parseFeatureCollection(dataArray) {
|
|
79
|
-
var features = [];
|
|
80
|
-
var _iterator = _createForOfIteratorHelper(dataArray),
|
|
81
|
-
_step;
|
|
82
|
-
try {
|
|
83
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
84
|
-
var data = _step.value;
|
|
85
|
-
if (data.featureIds.value.length === 0) {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
var lastIndex = 0;
|
|
89
|
-
var lastValue = data.featureIds.value[0];
|
|
90
|
-
for (var i = 0; i < data.featureIds.value.length; i++) {
|
|
91
|
-
var currValue = data.featureIds.value[i];
|
|
92
|
-
if (currValue === lastValue) {
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
features.push(parseFeature(data, lastIndex, i));
|
|
96
|
-
lastIndex = i;
|
|
97
|
-
lastValue = currValue;
|
|
98
|
-
}
|
|
99
|
-
features.push(parseFeature(data, lastIndex, data.featureIds.value.length));
|
|
100
|
-
}
|
|
101
|
-
} catch (err) {
|
|
102
|
-
_iterator.e(err);
|
|
103
|
-
} finally {
|
|
104
|
-
_iterator.f();
|
|
105
|
-
}
|
|
106
|
-
return features;
|
|
107
|
-
}
|
|
108
|
-
function parseFeature(data, startIndex, endIndex) {
|
|
109
|
-
var geometry = binaryToGeometry(data, startIndex, endIndex);
|
|
110
|
-
var properties = parseProperties(data, startIndex, endIndex);
|
|
111
|
-
var fields = parseFields(data, startIndex, endIndex);
|
|
112
|
-
return _objectSpread({
|
|
113
|
-
type: 'Feature',
|
|
114
|
-
geometry: geometry,
|
|
115
|
-
properties: properties
|
|
116
|
-
}, fields);
|
|
117
|
-
}
|
|
118
|
-
function parseFields(data) {
|
|
119
|
-
var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
120
|
-
var endIndex = arguments.length > 2 ? arguments[2] : undefined;
|
|
121
|
-
return data.fields && data.fields[data.featureIds.value[startIndex]];
|
|
122
|
-
}
|
|
123
|
-
function parseProperties(data) {
|
|
124
|
-
var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
125
|
-
var endIndex = arguments.length > 2 ? arguments[2] : undefined;
|
|
126
|
-
var properties = Object.assign({}, data.properties[data.featureIds.value[startIndex]]);
|
|
127
|
-
for (var key in data.numericProps) {
|
|
128
|
-
properties[key] = data.numericProps[key].value[startIndex];
|
|
129
|
-
}
|
|
130
|
-
return properties;
|
|
131
|
-
}
|
|
132
|
-
function polygonToGeoJson(data) {
|
|
133
|
-
var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -Infinity;
|
|
134
|
-
var endIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity;
|
|
135
|
-
var positions = data.positions;
|
|
136
|
-
var polygonIndices = data.polygonIndices.value.filter(function (x) {
|
|
137
|
-
return x >= startIndex && x <= endIndex;
|
|
138
|
-
});
|
|
139
|
-
var primitivePolygonIndices = data.primitivePolygonIndices.value.filter(function (x) {
|
|
140
|
-
return x >= startIndex && x <= endIndex;
|
|
141
|
-
});
|
|
142
|
-
var multi = polygonIndices.length > 2;
|
|
143
|
-
if (!multi) {
|
|
144
|
-
var _coordinates = [];
|
|
145
|
-
for (var i = 0; i < primitivePolygonIndices.length - 1; i++) {
|
|
146
|
-
var startRingIndex = primitivePolygonIndices[i];
|
|
147
|
-
var endRingIndex = primitivePolygonIndices[i + 1];
|
|
148
|
-
var ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);
|
|
149
|
-
_coordinates.push(ringCoordinates);
|
|
150
|
-
}
|
|
151
|
-
return {
|
|
152
|
-
type: 'Polygon',
|
|
153
|
-
coordinates: _coordinates
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
var coordinates = [];
|
|
157
|
-
for (var _i2 = 0; _i2 < polygonIndices.length - 1; _i2++) {
|
|
158
|
-
var startPolygonIndex = polygonIndices[_i2];
|
|
159
|
-
var endPolygonIndex = polygonIndices[_i2 + 1];
|
|
160
|
-
var polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates;
|
|
161
|
-
coordinates.push(polygonCoordinates);
|
|
162
|
-
}
|
|
163
|
-
return {
|
|
164
|
-
type: 'MultiPolygon',
|
|
165
|
-
coordinates: coordinates
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
function lineStringToGeoJson(data) {
|
|
169
|
-
var startIndex = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -Infinity;
|
|
170
|
-
var endIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Infinity;
|
|
171
|
-
var positions = data.positions;
|
|
172
|
-
var pathIndices = data.pathIndices.value.filter(function (x) {
|
|
173
|
-
return x >= startIndex && x <= endIndex;
|
|
174
|
-
});
|
|
175
|
-
var multi = pathIndices.length > 2;
|
|
176
|
-
if (!multi) {
|
|
177
|
-
var _coordinates2 = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);
|
|
178
|
-
return {
|
|
179
|
-
type: 'LineString',
|
|
180
|
-
coordinates: _coordinates2
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
var coordinates = [];
|
|
184
|
-
for (var i = 0; i < pathIndices.length - 1; i++) {
|
|
185
|
-
var ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
|
|
186
|
-
coordinates.push(ringCoordinates);
|
|
187
|
-
}
|
|
188
|
-
return {
|
|
189
|
-
type: 'MultiLineString',
|
|
190
|
-
coordinates: coordinates
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
function pointToGeoJson(data, startIndex, endIndex) {
|
|
194
|
-
var positions = data.positions;
|
|
195
|
-
var coordinates = ringToGeoJson(positions, startIndex, endIndex);
|
|
196
|
-
var multi = coordinates.length > 1;
|
|
197
|
-
if (multi) {
|
|
198
|
-
return {
|
|
199
|
-
type: 'MultiPoint',
|
|
200
|
-
coordinates: coordinates
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
return {
|
|
204
|
-
type: 'Point',
|
|
205
|
-
coordinates: coordinates[0]
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
function ringToGeoJson(positions, startIndex, endIndex) {
|
|
209
|
-
startIndex = startIndex || 0;
|
|
210
|
-
endIndex = endIndex || positions.value.length / positions.size;
|
|
211
|
-
var ringCoordinates = [];
|
|
212
|
-
for (var j = startIndex; j < endIndex; j++) {
|
|
213
|
-
var coord = Array();
|
|
214
|
-
for (var k = j * positions.size; k < (j + 1) * positions.size; k++) {
|
|
215
|
-
coord.push(Number(positions.value[k]));
|
|
216
|
-
}
|
|
217
|
-
ringCoordinates.push(coord);
|
|
218
|
-
}
|
|
219
|
-
return ringCoordinates;
|
|
220
|
-
}
|
|
221
|
-
//# sourceMappingURL=binary-to-geojson.js.map
|