@loaders.gl/gis
Advanced tools
Comparing version 4.0.0-alpha.23 to 4.0.0-alpha.24
@@ -6,8 +6,2 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "binaryToGeoJson", { | ||
enumerable: true, | ||
get: function get() { | ||
return _binaryToGeojson.binaryToGeoJson; | ||
} | ||
}); | ||
Object.defineProperty(exports, "binaryToGeojson", { | ||
@@ -14,0 +8,0 @@ enumerable: true, |
@@ -7,3 +7,2 @@ "use strict"; | ||
}); | ||
exports.binaryToGeoJson = binaryToGeoJson; | ||
exports.binaryToGeojson = binaryToGeojson; | ||
@@ -24,41 +23,22 @@ exports.binaryToGeometry = binaryToGeometry; | ||
} | ||
function binaryToGeoJson(data, type) { | ||
var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'feature'; | ||
switch (format) { | ||
case 'feature': | ||
return parseFeatures(data, type); | ||
case 'geometry': | ||
return binaryToGeometry(data); | ||
default: | ||
throw new Error(format); | ||
} | ||
} | ||
function getSingleFeature(data, globalFeatureId) { | ||
var dataArray = normalizeInput(data); | ||
var _iterator = _createForOfIteratorHelper(dataArray), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var _data = _step.value; | ||
var lastIndex = 0; | ||
var lastValue = _data.featureIds.value[0]; | ||
for (var i = 0; i < _data.featureIds.value.length; i++) { | ||
var currValue = _data.featureIds.value[i]; | ||
if (currValue === lastValue) { | ||
continue; | ||
} | ||
if (globalFeatureId === _data.globalFeatureIds.value[lastIndex]) { | ||
return parseFeature(_data, lastIndex, i); | ||
} | ||
lastIndex = i; | ||
lastValue = currValue; | ||
for (var _i = 0, _dataArray = dataArray; _i < _dataArray.length; _i++) { | ||
var _data = _dataArray[_i]; | ||
var lastIndex = 0; | ||
var lastValue = _data.featureIds.value[0]; | ||
for (var i = 0; i < _data.featureIds.value.length; i++) { | ||
var currValue = _data.featureIds.value[i]; | ||
if (currValue === lastValue) { | ||
continue; | ||
} | ||
if (globalFeatureId === _data.globalFeatureIds.value[lastIndex]) { | ||
return parseFeature(_data, lastIndex, _data.featureIds.value.length); | ||
return parseFeature(_data, lastIndex, i); | ||
} | ||
lastIndex = i; | ||
lastValue = currValue; | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
if (globalFeatureId === _data.globalFeatureIds.value[lastIndex]) { | ||
return parseFeature(_data, lastIndex, _data.featureIds.value.length); | ||
} | ||
} | ||
@@ -85,7 +65,2 @@ throw new Error("featureId:".concat(globalFeatureId, " not found")); | ||
function normalizeInput(data, type) { | ||
var isHeterogeneousType = Boolean(data.points || data.lines || data.polygons); | ||
if (!isHeterogeneousType) { | ||
data.type = type || parseType(data); | ||
return [data]; | ||
} | ||
var features = []; | ||
@@ -108,7 +83,7 @@ if (data.points) { | ||
var features = []; | ||
var _iterator2 = _createForOfIteratorHelper(dataArray), | ||
_step2; | ||
var _iterator = _createForOfIteratorHelper(dataArray), | ||
_step; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var data = _step2.value; | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var data = _step.value; | ||
if (data.featureIds.value.length === 0) { | ||
@@ -131,5 +106,5 @@ continue; | ||
} catch (err) { | ||
_iterator2.e(err); | ||
_iterator.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
_iterator.f(); | ||
} | ||
@@ -187,5 +162,5 @@ return features; | ||
var coordinates = []; | ||
for (var _i = 0; _i < polygonIndices.length - 1; _i++) { | ||
var startPolygonIndex = polygonIndices[_i]; | ||
var endPolygonIndex = polygonIndices[_i + 1]; | ||
for (var _i2 = 0; _i2 < polygonIndices.length - 1; _i2++) { | ||
var startPolygonIndex = polygonIndices[_i2]; | ||
var endPolygonIndex = polygonIndices[_i2 + 1]; | ||
var polygonCoordinates = polygonToGeoJson(data, startPolygonIndex, endPolygonIndex).coordinates; | ||
@@ -252,11 +227,2 @@ coordinates.push(polygonCoordinates); | ||
} | ||
function parseType(data) { | ||
if (data.pathIndices) { | ||
return 'LineString'; | ||
} | ||
if (data.polygonIndices) { | ||
return 'Polygon'; | ||
} | ||
return 'Point'; | ||
} | ||
//# sourceMappingURL=binary-to-geojson.js.map |
@@ -324,3 +324,3 @@ "use strict"; | ||
}; | ||
if (polygons.triangles) { | ||
if (binaryFeatures.polygons && polygons.triangles) { | ||
binaryFeatures.polygons.triangles = { | ||
@@ -327,0 +327,0 @@ value: new Uint32Array(polygons.triangles), |
export { flatGeojsonToBinary } from './lib/flat-geojson-to-binary'; | ||
export { geojsonToBinary } from './lib/geojson-to-binary'; | ||
export { geojsonToFlatGeojson } from './lib/geojson-to-flat-geojson'; | ||
export { binaryToGeojson, binaryToGeoJson, binaryToGeometry } from './lib/binary-to-geojson'; | ||
export { binaryToGeojson, binaryToGeometry } from './lib/binary-to-geojson'; | ||
export { transformBinaryCoords, transformGeoJsonCoords } from './lib/transform'; | ||
//# sourceMappingURL=index.js.map |
@@ -8,13 +8,2 @@ export function binaryToGeojson(data, options) { | ||
} | ||
export function binaryToGeoJson(data, type) { | ||
let format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'feature'; | ||
switch (format) { | ||
case 'feature': | ||
return parseFeatures(data, type); | ||
case 'geometry': | ||
return binaryToGeometry(data); | ||
default: | ||
throw new Error(format); | ||
} | ||
} | ||
function getSingleFeature(data, globalFeatureId) { | ||
@@ -60,7 +49,2 @@ const dataArray = normalizeInput(data); | ||
function normalizeInput(data, type) { | ||
const isHeterogeneousType = Boolean(data.points || data.lines || data.polygons); | ||
if (!isHeterogeneousType) { | ||
data.type = type || parseType(data); | ||
return [data]; | ||
} | ||
const features = []; | ||
@@ -216,11 +200,2 @@ if (data.points) { | ||
} | ||
function parseType(data) { | ||
if (data.pathIndices) { | ||
return 'LineString'; | ||
} | ||
if (data.polygonIndices) { | ||
return 'Polygon'; | ||
} | ||
return 'Point'; | ||
} | ||
//# sourceMappingURL=binary-to-geojson.js.map |
@@ -284,3 +284,3 @@ import { earcut } from '@math.gl/polygon'; | ||
}; | ||
if (polygons.triangles) { | ||
if (binaryFeatures.polygons && polygons.triangles) { | ||
binaryFeatures.polygons.triangles = { | ||
@@ -287,0 +287,0 @@ value: new Uint32Array(polygons.triangles), |
export { flatGeojsonToBinary } from './lib/flat-geojson-to-binary'; | ||
export { geojsonToBinary } from './lib/geojson-to-binary'; | ||
export { geojsonToFlatGeojson } from './lib/geojson-to-flat-geojson'; | ||
export { binaryToGeojson, binaryToGeoJson, binaryToGeometry } from './lib/binary-to-geojson'; | ||
export { binaryToGeojson, binaryToGeometry } from './lib/binary-to-geojson'; | ||
export { transformBinaryCoords, transformGeoJsonCoords } from './lib/transform'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import type { BinaryGeometry, BinaryFeatures, BinaryGeometryType } from '@loaders.gl/schema'; | ||
import type { BinaryGeometry, BinaryGeometryType, BinaryFeatureCollection } from '@loaders.gl/schema'; | ||
import type { Feature, Geometry } from '@loaders.gl/schema'; | ||
@@ -15,5 +15,3 @@ type BinaryToGeoJsonOptions = { | ||
*/ | ||
export declare function binaryToGeojson(data: BinaryFeatures, options?: BinaryToGeoJsonOptions): Feature[] | Feature; | ||
/** @deprecated use `binaryToGeojson` or `binaryToGeometry` instead */ | ||
export declare function binaryToGeoJson(data: BinaryGeometry | BinaryFeatures, type?: BinaryGeometryType, format?: 'feature' | 'geometry'): Geometry | Feature[]; | ||
export declare function binaryToGeojson(data: BinaryFeatureCollection, options?: BinaryToGeoJsonOptions): Feature[] | Feature; | ||
/** Parse input binary data and return a valid GeoJSON geometry object */ | ||
@@ -20,0 +18,0 @@ export declare function binaryToGeometry(data: BinaryGeometry, startIndex?: number, endIndex?: number): Geometry; |
@@ -1,2 +0,2 @@ | ||
import type { BinaryFeatures, FlatFeature, GeojsonGeometryInfo } from '@loaders.gl/schema'; | ||
import type { BinaryFeatureCollection, FlatFeature, GeojsonGeometryInfo } from '@loaders.gl/schema'; | ||
import { PropArrayConstructor } from './flat-geojson-to-binary-types'; | ||
@@ -16,3 +16,3 @@ /** | ||
*/ | ||
export declare function flatGeojsonToBinary(features: FlatFeature[], geometryInfo: GeojsonGeometryInfo, options?: FlatGeojsonToBinaryOptions): BinaryFeatures; | ||
export declare function flatGeojsonToBinary(features: FlatFeature[], geometryInfo: GeojsonGeometryInfo, options?: FlatGeojsonToBinaryOptions): BinaryFeatureCollection; | ||
/** | ||
@@ -19,0 +19,0 @@ * Options for `flatGeojsonToBinary` |
import type { Feature } from '@loaders.gl/schema'; | ||
import type { BinaryFeatures } from '@loaders.gl/schema'; | ||
import type { BinaryFeatureCollection } from '@loaders.gl/schema'; | ||
/** | ||
@@ -19,3 +19,3 @@ * Options for `geojsonToBinary` | ||
*/ | ||
export declare function geojsonToBinary(features: Feature[], options?: GeojsonToBinaryOptions): BinaryFeatures; | ||
export declare function geojsonToBinary(features: Feature[], options?: GeojsonToBinaryOptions): BinaryFeatureCollection; | ||
//# sourceMappingURL=geojson-to-binary.d.ts.map |
@@ -1,2 +0,2 @@ | ||
import type { BinaryFeatures, Feature } from '@loaders.gl/schema'; | ||
import type { BinaryFeatureCollection, Feature } from '@loaders.gl/schema'; | ||
type TransformCoordinate = (coord: number[]) => number[]; | ||
@@ -9,3 +9,3 @@ /** | ||
*/ | ||
export declare function transformBinaryCoords(binaryFeatures: BinaryFeatures, transformCoordinate: TransformCoordinate): BinaryFeatures; | ||
export declare function transformBinaryCoords(binaryFeatures: BinaryFeatureCollection, transformCoordinate: TransformCoordinate): BinaryFeatureCollection; | ||
/** | ||
@@ -12,0 +12,0 @@ * Apply transformation to every coordinate of GeoJSON features |
{ | ||
"name": "@loaders.gl/gis", | ||
"description": "Helpers for GIS category data", | ||
"version": "4.0.0-alpha.23", | ||
"version": "4.0.0-alpha.24", | ||
"license": "MIT", | ||
@@ -27,4 +27,4 @@ "publishConfig": { | ||
"dependencies": { | ||
"@loaders.gl/loader-utils": "4.0.0-alpha.23", | ||
"@loaders.gl/schema": "4.0.0-alpha.23", | ||
"@loaders.gl/loader-utils": "4.0.0-alpha.24", | ||
"@loaders.gl/schema": "4.0.0-alpha.24", | ||
"@mapbox/vector-tile": "^1.3.1", | ||
@@ -37,3 +37,3 @@ "@math.gl/polygon": "^3.5.1", | ||
}, | ||
"gitHead": "e212f2a0c0e342f7cb65ce84fa2ff39f64b7d94b" | ||
"gitHead": "97a8990595c132fb14e3445a8768d9f4cb98ff05" | ||
} |
@@ -7,3 +7,3 @@ // Types from `@loaders.gl/schema` | ||
export {geojsonToFlatGeojson} from './lib/geojson-to-flat-geojson'; | ||
export {binaryToGeojson, binaryToGeoJson, binaryToGeometry} from './lib/binary-to-geojson'; | ||
export {binaryToGeojson, binaryToGeometry} from './lib/binary-to-geojson'; | ||
export {transformBinaryCoords, transformGeoJsonCoords} from './lib/transform'; |
@@ -0,8 +1,14 @@ | ||
// loaders.gl, MIT license | ||
import type { | ||
BinaryGeometry, | ||
BinaryFeatures, | ||
BinaryGeometryType, | ||
BinaryPointFeatures, | ||
BinaryLineFeatures, | ||
BinaryPolygonFeatures, | ||
BinaryPointGeometry, | ||
BinaryLineGeometry, | ||
BinaryPolygonGeometry, | ||
BinaryFeatureCollection, | ||
BinaryFeature, | ||
// BinaryPointFeature, | ||
// BinaryLineFeature, | ||
// BinaryPolygonFeature, | ||
BinaryAttribute | ||
@@ -37,3 +43,3 @@ } from '@loaders.gl/schema'; | ||
export function binaryToGeojson( | ||
data: BinaryFeatures, | ||
data: BinaryFeatureCollection, | ||
options?: BinaryToGeoJsonOptions | ||
@@ -48,5 +54,5 @@ ): Feature[] | Feature { | ||
/** @deprecated use `binaryToGeojson` or `binaryToGeometry` instead */ | ||
/** @deprecated use `binaryToGeojson` or `binaryToGeometry` instead * | ||
export function binaryToGeoJson( | ||
data: BinaryGeometry | BinaryFeatures, | ||
data: BinaryGeometry | BinaryFeatureCollection, | ||
type?: BinaryGeometryType, | ||
@@ -57,5 +63,5 @@ format: 'feature' | 'geometry' = 'feature' | ||
case 'feature': | ||
return parseFeatures(data as BinaryFeatures, type); | ||
return parseFeatures(data as BinaryFeatureCollection, type); | ||
case 'geometry': | ||
return binaryToGeometry(data as BinaryGeometry); | ||
return binaryToGeometry(data as any); | ||
default: | ||
@@ -65,2 +71,3 @@ throw new Error(format); | ||
} | ||
*/ | ||
@@ -72,3 +79,3 @@ /** | ||
*/ | ||
function getSingleFeature(data: BinaryFeatures, globalFeatureId: number): Feature { | ||
function getSingleFeature(data: BinaryFeatureCollection, globalFeatureId: number): Feature { | ||
const dataArray = normalizeInput(data); | ||
@@ -101,3 +108,3 @@ for (const data of dataArray) { | ||
function parseFeatures(data: BinaryFeatures, type?: BinaryGeometryType): Feature[] { | ||
function parseFeatures(data: BinaryFeatureCollection, type?: BinaryGeometryType): Feature[] { | ||
const dataArray = normalizeInput(data, type); | ||
@@ -126,18 +133,6 @@ return parseFeatureCollection(dataArray); | ||
type BinaryFeature = BinaryPointFeatures | BinaryLineFeatures | BinaryPolygonFeatures; | ||
type BinaryFeaturesArray = BinaryFeature[]; | ||
// Normalize features | ||
// Return an array of data objects, each of which have a type key | ||
function normalizeInput(data: BinaryFeatures, type?: BinaryGeometryType): BinaryFeaturesArray { | ||
const isHeterogeneousType = Boolean(data.points || data.lines || data.polygons); | ||
if (!isHeterogeneousType) { | ||
// @ts-expect-error This is a legacy check which allowed `data` to be an instance of the values | ||
// here. Aka the new data.points, data.lines, or data.polygons. | ||
data.type = type || parseType(data); | ||
return [data] as BinaryFeaturesArray; | ||
} | ||
const features: BinaryFeaturesArray = []; | ||
function normalizeInput(data: BinaryFeatureCollection, type?: BinaryGeometryType): BinaryFeature[] { | ||
const features: BinaryFeature[] = []; | ||
if (data.points) { | ||
@@ -160,3 +155,3 @@ data.points.type = 'Point'; | ||
/** Parse input binary data and return an array of GeoJSON Features */ | ||
function parseFeatureCollection(dataArray): Feature[] { | ||
function parseFeatureCollection(dataArray: BinaryFeature[]): Feature[] { | ||
const features: Feature[] = []; | ||
@@ -191,3 +186,3 @@ for (const data of dataArray) { | ||
/** Parse input binary data and return a single GeoJSON Feature */ | ||
function parseFeature(data, startIndex?: number, endIndex?: number): Feature { | ||
function parseFeature(data: BinaryFeature, startIndex?: number, endIndex?: number): Feature { | ||
const geometry = binaryToGeometry(data, startIndex, endIndex); | ||
@@ -215,3 +210,3 @@ const properties = parseProperties(data, startIndex, endIndex); | ||
function polygonToGeoJson( | ||
data, | ||
data: BinaryPolygonGeometry, | ||
startIndex: number = -Infinity, | ||
@@ -258,3 +253,3 @@ endIndex: number = Infinity | ||
function lineStringToGeoJson( | ||
data, | ||
data: BinaryLineGeometry, | ||
startIndex: number = -Infinity, | ||
@@ -282,3 +277,3 @@ endIndex: number = Infinity | ||
/** Parse binary data of type Point */ | ||
function pointToGeoJson(data, startIndex, endIndex): Point | MultiPoint { | ||
function pointToGeoJson(data: BinaryPointGeometry, startIndex, endIndex): Point | MultiPoint { | ||
const {positions} = data; | ||
@@ -321,14 +316,1 @@ const coordinates = ringToGeoJson(positions, startIndex, endIndex); | ||
} | ||
// Deduce geometry type of data object | ||
function parseType(data) { | ||
if (data.pathIndices) { | ||
return 'LineString'; | ||
} | ||
if (data.polygonIndices) { | ||
return 'Polygon'; | ||
} | ||
return 'Point'; | ||
} |
@@ -5,4 +5,4 @@ /* eslint-disable indent */ | ||
BinaryAttribute, | ||
BinaryFeatures, | ||
BinaryPolygonFeatures, | ||
BinaryFeatureCollection, | ||
BinaryPolygonFeature, | ||
FlatFeature, | ||
@@ -489,4 +489,4 @@ FlatPoint, | ||
coordLength: number | ||
): BinaryFeatures { | ||
const binaryFeatures = { | ||
): BinaryFeatureCollection { | ||
const binaryFeatures: BinaryFeatureCollection = { | ||
points: { | ||
@@ -515,6 +515,6 @@ ...points, | ||
numericProps: wrapProps(polygons.numericProps, 1) | ||
} as BinaryPolygonFeatures | ||
} as BinaryPolygonFeature // triangles not expected | ||
}; | ||
if (polygons.triangles) { | ||
if (binaryFeatures.polygons && polygons.triangles) { | ||
binaryFeatures.polygons.triangles = {value: new Uint32Array(polygons.triangles), size: 1}; | ||
@@ -521,0 +521,0 @@ } |
import type {Feature} from '@loaders.gl/schema'; | ||
import type {BinaryFeatures} from '@loaders.gl/schema'; | ||
import type {BinaryFeatureCollection} from '@loaders.gl/schema'; | ||
@@ -28,3 +28,3 @@ import {extractGeometryInfo} from './extract-geometry-info'; | ||
options: GeojsonToBinaryOptions = {fixRingWinding: true, triangulate: true} | ||
): BinaryFeatures { | ||
): BinaryFeatureCollection { | ||
const geometryInfo = extractGeometryInfo(features); | ||
@@ -31,0 +31,0 @@ const coordLength = geometryInfo.coordLength; |
@@ -1,2 +0,2 @@ | ||
import type {BinaryFeatures, BinaryGeometry, Feature} from '@loaders.gl/schema'; | ||
import type {BinaryFeatureCollection, BinaryGeometry, Feature} from '@loaders.gl/schema'; | ||
@@ -12,5 +12,5 @@ type TransformCoordinate = (coord: number[]) => number[]; | ||
export function transformBinaryCoords( | ||
binaryFeatures: BinaryFeatures, | ||
binaryFeatures: BinaryFeatureCollection, | ||
transformCoordinate: TransformCoordinate | ||
): BinaryFeatures { | ||
): BinaryFeatureCollection { | ||
if (binaryFeatures.points) { | ||
@@ -17,0 +17,0 @@ transformBinaryGeometryPositions(binaryFeatures.points, transformCoordinate); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
284856
66
3191
+ Added@loaders.gl/loader-utils@4.0.0-alpha.24(transitive)
+ Added@loaders.gl/schema@4.0.0-alpha.24(transitive)
+ Added@loaders.gl/worker-utils@4.0.0-alpha.24(transitive)
- Removed@loaders.gl/loader-utils@4.0.0-alpha.23(transitive)
- Removed@loaders.gl/schema@4.0.0-alpha.23(transitive)
- Removed@loaders.gl/worker-utils@4.0.0-alpha.23(transitive)