@math.gl/geospatial 5.0.0-beta.3 → 5.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +192 -2
- package/THIRD-PARTY-NOTICES.md +192 -20
- package/dist/expressions.d.ts +1 -1
- package/dist/expressions.d.ts.map +1 -1
- package/dist/index.cjs +456 -4614
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +9 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -4
- package/dist/index.js.map +1 -1
- package/dist/projection/experimental/common/adjust_lat.js +1 -1
- package/dist/projection/experimental/common/adjust_lat.js.map +1 -1
- package/dist/projection/experimental/common/adjust_lon.js +1 -1
- package/dist/projection/experimental/common/adjust_lon.js.map +1 -1
- package/dist/projection/experimental/common/asinhy.js +1 -1
- package/dist/projection/experimental/common/asinhy.js.map +1 -1
- package/dist/projection/experimental/common/asinz.js +1 -1
- package/dist/projection/experimental/common/asinz.js.map +1 -1
- package/dist/projection/experimental/common/authlat.js +1 -1
- package/dist/projection/experimental/common/authlat.js.map +1 -1
- package/dist/projection/experimental/common/authset.js +1 -1
- package/dist/projection/experimental/common/authset.js.map +1 -1
- package/dist/projection/experimental/common/clens.js +1 -1
- package/dist/projection/experimental/common/clens.js.map +1 -1
- package/dist/projection/experimental/common/clens_cmplx.js +1 -1
- package/dist/projection/experimental/common/clens_cmplx.js.map +1 -1
- package/dist/projection/experimental/common/constants.js +1 -1
- package/dist/projection/experimental/common/constants.js.map +1 -1
- package/dist/projection/experimental/common/cosh.js +1 -1
- package/dist/projection/experimental/common/cosh.js.map +1 -1
- package/dist/projection/experimental/common/e0fn.js +1 -1
- package/dist/projection/experimental/common/e0fn.js.map +1 -1
- package/dist/projection/experimental/common/e1fn.js +1 -1
- package/dist/projection/experimental/common/e1fn.js.map +1 -1
- package/dist/projection/experimental/common/e2fn.js +1 -1
- package/dist/projection/experimental/common/e2fn.js.map +1 -1
- package/dist/projection/experimental/common/e3fn.js +1 -1
- package/dist/projection/experimental/common/e3fn.js.map +1 -1
- package/dist/projection/experimental/common/fL.js +1 -1
- package/dist/projection/experimental/common/fL.js.map +1 -1
- package/dist/projection/experimental/common/gN.js +1 -1
- package/dist/projection/experimental/common/gN.js.map +1 -1
- package/dist/projection/experimental/common/gatg.js +1 -1
- package/dist/projection/experimental/common/gatg.js.map +1 -1
- package/dist/projection/experimental/common/hypot.js +1 -1
- package/dist/projection/experimental/common/hypot.js.map +1 -1
- package/dist/projection/experimental/common/imlfn.js +1 -1
- package/dist/projection/experimental/common/imlfn.js.map +1 -1
- package/dist/projection/experimental/common/invlatiso.js +1 -1
- package/dist/projection/experimental/common/invlatiso.js.map +1 -1
- package/dist/projection/experimental/common/iqsfnz.js +1 -1
- package/dist/projection/experimental/common/iqsfnz.js.map +1 -1
- package/dist/projection/experimental/common/latiso.js +1 -1
- package/dist/projection/experimental/common/latiso.js.map +1 -1
- package/dist/projection/experimental/common/log1py.js +1 -1
- package/dist/projection/experimental/common/log1py.js.map +1 -1
- package/dist/projection/experimental/common/mlfn.js +1 -1
- package/dist/projection/experimental/common/mlfn.js.map +1 -1
- package/dist/projection/experimental/common/msfnz.js +1 -1
- package/dist/projection/experimental/common/msfnz.js.map +1 -1
- package/dist/projection/experimental/common/phi2z.js +1 -1
- package/dist/projection/experimental/common/phi2z.js.map +1 -1
- package/dist/projection/experimental/common/pj_enfn.js +1 -1
- package/dist/projection/experimental/common/pj_enfn.js.map +1 -1
- package/dist/projection/experimental/common/pj_inv_mlfn.js +1 -1
- package/dist/projection/experimental/common/pj_inv_mlfn.js.map +1 -1
- package/dist/projection/experimental/common/pj_mlfn.js +1 -1
- package/dist/projection/experimental/common/pj_mlfn.js.map +1 -1
- package/dist/projection/experimental/common/qsfnz.js +1 -1
- package/dist/projection/experimental/common/qsfnz.js.map +1 -1
- package/dist/projection/experimental/common/sign.js +1 -1
- package/dist/projection/experimental/common/sign.js.map +1 -1
- package/dist/projection/experimental/common/sinh.js +1 -1
- package/dist/projection/experimental/common/sinh.js.map +1 -1
- package/dist/projection/experimental/common/srat.js +1 -1
- package/dist/projection/experimental/common/srat.js.map +1 -1
- package/dist/projection/experimental/common/tsfnz.js +1 -1
- package/dist/projection/experimental/common/tsfnz.js.map +1 -1
- package/dist/projection/experimental/common/vincenty.js +1 -1
- package/dist/projection/experimental/common/vincenty.js.map +1 -1
- package/dist/projection/experimental/core.cjs +100 -2
- package/dist/projection/experimental/core.cjs.map +2 -2
- package/dist/projection/experimental/core.d.ts +1 -0
- package/dist/projection/experimental/core.d.ts.map +1 -1
- package/dist/projection/experimental/crs/datum-table.js +1 -1
- package/dist/projection/experimental/crs/datum-table.js.map +1 -1
- package/dist/projection/experimental/crs/ellipsoid-table.js +1 -1
- package/dist/projection/experimental/crs/ellipsoid-table.js.map +1 -1
- package/dist/projection/experimental/crs/primemeridian-table.js +1 -1
- package/dist/projection/experimental/crs/primemeridian-table.js.map +1 -1
- package/dist/projection/experimental/crs/structured.js +1 -1
- package/dist/projection/experimental/crs/structured.js.map +1 -1
- package/dist/projection/experimental/crs/wkt.js +1 -1
- package/dist/projection/experimental/crs/wkt.js.map +1 -1
- package/dist/projection/experimental/datum.js +1 -1
- package/dist/projection/experimental/datum.js.map +1 -1
- package/dist/projection/experimental/ellipsoidal-gnomonic.js +1 -1
- package/dist/projection/experimental/ellipsoidal-gnomonic.js.map +1 -1
- package/dist/projection/experimental/entries/projections/eqc.cjs +1 -0
- package/dist/projection/experimental/entries/projections/eqc.cjs.map +1 -1
- package/dist/projection/experimental/entries/projections/merc.cjs +1 -0
- package/dist/projection/experimental/entries/projections/merc.cjs.map +1 -1
- package/dist/projection/experimental/grids/geotiff.js +1 -1
- package/dist/projection/experimental/grids/geotiff.js.map +1 -1
- package/dist/projection/experimental/grids/ntv2.js +1 -1
- package/dist/projection/experimental/grids/ntv2.js.map +1 -1
- package/dist/projection/experimental/index.cjs +102 -2
- package/dist/projection/experimental/index.cjs.map +3 -3
- package/dist/projection/experimental/kernels/aea.js +1 -1
- package/dist/projection/experimental/kernels/aea.js.map +1 -1
- package/dist/projection/experimental/kernels/aeqd.js +1 -1
- package/dist/projection/experimental/kernels/aeqd.js.map +1 -1
- package/dist/projection/experimental/kernels/bonne.js +1 -1
- package/dist/projection/experimental/kernels/bonne.js.map +1 -1
- package/dist/projection/experimental/kernels/cass.js +1 -1
- package/dist/projection/experimental/kernels/cass.js.map +1 -1
- package/dist/projection/experimental/kernels/cea.js +1 -1
- package/dist/projection/experimental/kernels/cea.js.map +1 -1
- package/dist/projection/experimental/kernels/eck6.js +1 -1
- package/dist/projection/experimental/kernels/eck6.js.map +1 -1
- package/dist/projection/experimental/kernels/eqdc.js +1 -1
- package/dist/projection/experimental/kernels/eqdc.js.map +1 -1
- package/dist/projection/experimental/kernels/eqearth.js +1 -1
- package/dist/projection/experimental/kernels/eqearth.js.map +1 -1
- package/dist/projection/experimental/kernels/equi.js +1 -1
- package/dist/projection/experimental/kernels/equi.js.map +1 -1
- package/dist/projection/experimental/kernels/etmerc.js +1 -1
- package/dist/projection/experimental/kernels/etmerc.js.map +1 -1
- package/dist/projection/experimental/kernels/gauss.js +1 -1
- package/dist/projection/experimental/kernels/gauss.js.map +1 -1
- package/dist/projection/experimental/kernels/geos.js +1 -1
- package/dist/projection/experimental/kernels/geos.js.map +1 -1
- package/dist/projection/experimental/kernels/gnom.js +1 -1
- package/dist/projection/experimental/kernels/gnom.js.map +1 -1
- package/dist/projection/experimental/kernels/gstmerc.js +1 -1
- package/dist/projection/experimental/kernels/gstmerc.js.map +1 -1
- package/dist/projection/experimental/kernels/krovak.js +1 -1
- package/dist/projection/experimental/kernels/krovak.js.map +1 -1
- package/dist/projection/experimental/kernels/laea.js +1 -1
- package/dist/projection/experimental/kernels/laea.js.map +1 -1
- package/dist/projection/experimental/kernels/lcc.js +1 -1
- package/dist/projection/experimental/kernels/lcc.js.map +1 -1
- package/dist/projection/experimental/kernels/mill.js +1 -1
- package/dist/projection/experimental/kernels/mill.js.map +1 -1
- package/dist/projection/experimental/kernels/moll.js +1 -1
- package/dist/projection/experimental/kernels/moll.js.map +1 -1
- package/dist/projection/experimental/kernels/nzmg.js +1 -1
- package/dist/projection/experimental/kernels/nzmg.js.map +1 -1
- package/dist/projection/experimental/kernels/omerc.js +1 -1
- package/dist/projection/experimental/kernels/omerc.js.map +1 -1
- package/dist/projection/experimental/kernels/poly.js +1 -1
- package/dist/projection/experimental/kernels/poly.js.map +1 -1
- package/dist/projection/experimental/kernels/qsc.js +1 -1
- package/dist/projection/experimental/kernels/qsc.js.map +1 -1
- package/dist/projection/experimental/kernels/robin.js +1 -1
- package/dist/projection/experimental/kernels/robin.js.map +1 -1
- package/dist/projection/experimental/kernels/sinu.js +1 -1
- package/dist/projection/experimental/kernels/sinu.js.map +1 -1
- package/dist/projection/experimental/kernels/somerc.js +1 -1
- package/dist/projection/experimental/kernels/somerc.js.map +1 -1
- package/dist/projection/experimental/kernels/stere.js +1 -1
- package/dist/projection/experimental/kernels/stere.js.map +1 -1
- package/dist/projection/experimental/kernels/sterea.js +1 -1
- package/dist/projection/experimental/kernels/sterea.js.map +1 -1
- package/dist/projection/experimental/kernels/tmerc.js +1 -1
- package/dist/projection/experimental/kernels/tmerc.js.map +1 -1
- package/dist/projection/experimental/kernels/tpers.js +1 -1
- package/dist/projection/experimental/kernels/tpers.js.map +1 -1
- package/dist/projection/experimental/kernels/vandg.js +1 -1
- package/dist/projection/experimental/kernels/vandg.js.map +1 -1
- package/dist/projection/experimental/kinematic-helmert.js +1 -1
- package/dist/projection/experimental/kinematic-helmert.js.map +1 -1
- package/dist/projection/experimental/lazy-projections/index.cjs +100 -2
- package/dist/projection/experimental/lazy-projections/index.cjs.map +2 -2
- package/dist/projection/experimental/projections/equidistant-cylindrical.d.ts.map +1 -1
- package/dist/projection/experimental/projections/equidistant-cylindrical.js +1 -0
- package/dist/projection/experimental/projections/equidistant-cylindrical.js.map +1 -1
- package/dist/projection/experimental/projections/mercator.d.ts.map +1 -1
- package/dist/projection/experimental/projections/mercator.js +1 -0
- package/dist/projection/experimental/projections/mercator.js.map +1 -1
- package/dist/projection/experimental/transform-description.d.ts +8 -0
- package/dist/projection/experimental/transform-description.d.ts.map +1 -0
- package/dist/projection/experimental/transform-description.js +57 -0
- package/dist/projection/experimental/transform-description.js.map +1 -0
- package/dist/projection/experimental/types.d.ts +5 -0
- package/dist/projection/experimental/types.d.ts.map +1 -1
- package/dist/projection/experimental/typescript-projection.d.ts +4 -0
- package/dist/projection/experimental/typescript-projection.d.ts.map +1 -1
- package/dist/projection/experimental/typescript-projection.js +54 -5
- package/dist/projection/experimental/typescript-projection.js.map +1 -1
- package/dist/projection/index.cjs +102 -2
- package/dist/projection/index.cjs.map +3 -3
- package/dist/projection/transform-analysis.cjs +100 -2
- package/dist/projection/transform-analysis.cjs.map +2 -2
- package/dist/projection/transform-description.d.ts +44 -0
- package/dist/projection/transform-description.d.ts.map +1 -0
- package/dist/projection/transform-description.js +5 -0
- package/dist/projection/transform-description.js.map +1 -0
- package/dist/projection/types.d.ts +4 -0
- package/dist/projection/types.d.ts.map +1 -1
- package/dist/tasks/definitions.d.ts +3 -3
- package/dist/tasks/index.cjs +107 -2
- package/dist/tasks/index.cjs.map +3 -3
- package/dist/tasks/index.d.ts +1 -1
- package/dist/tasks/index.d.ts.map +1 -1
- package/dist/tasks/map-worker.js +1 -1
- package/dist/tasks/map-worker.js.map +1 -1
- package/dist/tasks/operations.d.ts +1 -1
- package/dist/tasks/operations.d.ts.map +1 -1
- package/dist/tasks/projection-worker.js +1 -1
- package/dist/tasks/projection-worker.js.map +1 -1
- package/dist/terrain/contour-boundary-diagnostics.d.ts +23 -0
- package/dist/terrain/contour-boundary-diagnostics.d.ts.map +1 -0
- package/dist/terrain/contour-boundary-diagnostics.js +62 -0
- package/dist/terrain/contour-boundary-diagnostics.js.map +1 -0
- package/dist/terrain/contour-mixed-weld.d.ts +25 -0
- package/dist/terrain/contour-mixed-weld.d.ts.map +1 -0
- package/dist/terrain/contour-mixed-weld.js +194 -0
- package/dist/terrain/contour-mixed-weld.js.map +1 -0
- package/dist/terrain/contour-tile-paths.d.ts +7 -0
- package/dist/terrain/contour-tile-paths.d.ts.map +1 -0
- package/dist/terrain/contour-tile-paths.js +12 -0
- package/dist/terrain/contour-tile-paths.js.map +1 -0
- package/dist/terrain/contour-tile-weld.d.ts +24 -0
- package/dist/terrain/contour-tile-weld.d.ts.map +1 -0
- package/dist/terrain/contour-tile-weld.js +147 -0
- package/dist/terrain/contour-tile-weld.js.map +1 -0
- package/dist/terrain/gradient-pyramid.d.ts +29 -0
- package/dist/terrain/gradient-pyramid.d.ts.map +1 -0
- package/dist/terrain/gradient-pyramid.js +94 -0
- package/dist/terrain/gradient-pyramid.js.map +1 -0
- package/dist/terrain/height-field.d.ts.map +1 -1
- package/dist/terrain/height-field.js +48 -5
- package/dist/terrain/height-field.js.map +1 -1
- package/dist/terrain/index.cjs +448 -4
- package/dist/terrain/index.cjs.map +3 -3
- package/dist/terrain/index.d.ts +9 -0
- package/dist/terrain/index.d.ts.map +1 -1
- package/dist/terrain/index.js +5 -0
- package/dist/terrain/index.js.map +1 -1
- package/dist/terrain/tiled.d.ts +10 -2
- package/dist/terrain/tiled.d.ts.map +1 -1
- package/dist/terrain/tiled.js +5 -1
- package/dist/terrain/tiled.js.map +1 -1
- package/dist/terrain/types.d.ts +6 -0
- package/dist/terrain/types.d.ts.map +1 -1
- package/dist/turf.cjs +25 -671
- package/dist/turf.cjs.map +3 -3
- package/dist/turf.d.ts +1 -1
- package/dist/turf.d.ts.map +1 -1
- package/dist/turf.js +2 -2
- package/dist/turf.js.map +1 -1
- package/package.json +15 -19
- package/src/expressions.ts +1 -1
- package/src/index.ts +15 -123
- package/src/projection/experimental/common/adjust_lat.ts +1 -1
- package/src/projection/experimental/common/adjust_lon.ts +1 -1
- package/src/projection/experimental/common/asinhy.ts +1 -1
- package/src/projection/experimental/common/asinz.ts +1 -1
- package/src/projection/experimental/common/authlat.ts +1 -1
- package/src/projection/experimental/common/authset.ts +1 -1
- package/src/projection/experimental/common/clens.ts +1 -1
- package/src/projection/experimental/common/clens_cmplx.ts +1 -1
- package/src/projection/experimental/common/constants.ts +1 -1
- package/src/projection/experimental/common/cosh.ts +1 -1
- package/src/projection/experimental/common/e0fn.ts +1 -1
- package/src/projection/experimental/common/e1fn.ts +1 -1
- package/src/projection/experimental/common/e2fn.ts +1 -1
- package/src/projection/experimental/common/e3fn.ts +1 -1
- package/src/projection/experimental/common/fL.ts +1 -1
- package/src/projection/experimental/common/gN.ts +1 -1
- package/src/projection/experimental/common/gatg.ts +1 -1
- package/src/projection/experimental/common/hypot.ts +1 -1
- package/src/projection/experimental/common/imlfn.ts +1 -1
- package/src/projection/experimental/common/invlatiso.ts +1 -1
- package/src/projection/experimental/common/iqsfnz.ts +1 -1
- package/src/projection/experimental/common/latiso.ts +1 -1
- package/src/projection/experimental/common/log1py.ts +1 -1
- package/src/projection/experimental/common/mlfn.ts +1 -1
- package/src/projection/experimental/common/msfnz.ts +1 -1
- package/src/projection/experimental/common/phi2z.ts +1 -1
- package/src/projection/experimental/common/pj_enfn.ts +1 -1
- package/src/projection/experimental/common/pj_inv_mlfn.ts +1 -1
- package/src/projection/experimental/common/pj_mlfn.ts +1 -1
- package/src/projection/experimental/common/qsfnz.ts +1 -1
- package/src/projection/experimental/common/sign.ts +1 -1
- package/src/projection/experimental/common/sinh.ts +1 -1
- package/src/projection/experimental/common/srat.ts +1 -1
- package/src/projection/experimental/common/tsfnz.ts +1 -1
- package/src/projection/experimental/common/vincenty.ts +1 -1
- package/src/projection/experimental/core.ts +8 -0
- package/src/projection/experimental/crs/datum-table.ts +1 -1
- package/src/projection/experimental/crs/ellipsoid-table.ts +1 -1
- package/src/projection/experimental/crs/primemeridian-table.ts +1 -1
- package/src/projection/experimental/crs/structured.ts +1 -1
- package/src/projection/experimental/crs/wkt.ts +1 -1
- package/src/projection/experimental/datum.ts +1 -1
- package/src/projection/experimental/ellipsoidal-gnomonic.ts +1 -1
- package/src/projection/experimental/exact-helmert.ts +1 -1
- package/src/projection/experimental/grids/geotiff.ts +1 -1
- package/src/projection/experimental/grids/grid.ts +1 -1
- package/src/projection/experimental/grids/ntv2.ts +1 -1
- package/src/projection/experimental/helmert-flat.ts +1 -1
- package/src/projection/experimental/kernels/aea.ts +1 -1
- package/src/projection/experimental/kernels/aeqd.ts +1 -1
- package/src/projection/experimental/kernels/bonne.ts +1 -1
- package/src/projection/experimental/kernels/cass.ts +1 -1
- package/src/projection/experimental/kernels/cea.ts +1 -1
- package/src/projection/experimental/kernels/eck6.ts +1 -1
- package/src/projection/experimental/kernels/eqdc.ts +1 -1
- package/src/projection/experimental/kernels/eqearth.ts +1 -1
- package/src/projection/experimental/kernels/equi.ts +1 -1
- package/src/projection/experimental/kernels/etmerc.ts +1 -1
- package/src/projection/experimental/kernels/gauss.ts +1 -1
- package/src/projection/experimental/kernels/geos.ts +1 -1
- package/src/projection/experimental/kernels/gnom.ts +1 -1
- package/src/projection/experimental/kernels/gstmerc.ts +1 -1
- package/src/projection/experimental/kernels/krovak.ts +1 -1
- package/src/projection/experimental/kernels/laea.ts +1 -1
- package/src/projection/experimental/kernels/lcc.ts +1 -1
- package/src/projection/experimental/kernels/mill.ts +1 -1
- package/src/projection/experimental/kernels/moll.ts +1 -1
- package/src/projection/experimental/kernels/nzmg.ts +1 -1
- package/src/projection/experimental/kernels/omerc.ts +1 -1
- package/src/projection/experimental/kernels/ortho.ts +1 -1
- package/src/projection/experimental/kernels/poly.ts +1 -1
- package/src/projection/experimental/kernels/qsc.ts +1 -1
- package/src/projection/experimental/kernels/robin.ts +1 -1
- package/src/projection/experimental/kernels/sinu.ts +1 -1
- package/src/projection/experimental/kernels/somerc.ts +1 -1
- package/src/projection/experimental/kernels/stere.ts +1 -1
- package/src/projection/experimental/kernels/sterea.ts +1 -1
- package/src/projection/experimental/kernels/tmerc.ts +1 -1
- package/src/projection/experimental/kernels/tpers.ts +1 -1
- package/src/projection/experimental/kernels/vandg.ts +1 -1
- package/src/projection/experimental/kinematic-helmert-flat.ts +1 -1
- package/src/projection/experimental/kinematic-helmert.ts +1 -1
- package/src/projection/experimental/projection-pipeline.ts +1 -1
- package/src/projection/experimental/projections/equidistant-cylindrical.ts +1 -0
- package/src/projection/experimental/projections/mercator.ts +1 -0
- package/src/projection/experimental/projections/ob-tran.ts +1 -1
- package/src/projection/experimental/transform-description.ts +82 -0
- package/src/projection/experimental/types.ts +5 -0
- package/src/projection/experimental/typescript-projection.ts +54 -6
- package/src/projection/transform-description.ts +69 -0
- package/src/projection/types.ts +11 -0
- package/src/tasks/definitions.ts +1 -1
- package/src/tasks/index.ts +1 -1
- package/src/tasks/map-worker.ts +1 -1
- package/src/tasks/operations.ts +1 -1
- package/src/tasks/projection-worker.ts +1 -1
- package/src/terrain/contour-boundary-diagnostics.ts +90 -0
- package/src/terrain/contour-mixed-weld.ts +254 -0
- package/src/terrain/contour-tile-paths.ts +20 -0
- package/src/terrain/contour-tile-weld.ts +182 -0
- package/src/terrain/gradient-pyramid.ts +129 -0
- package/src/terrain/height-field.ts +45 -5
- package/src/terrain/index.ts +12 -0
- package/src/terrain/tiled.ts +16 -3
- package/src/terrain/types.ts +9 -1
- package/src/turf.ts +7 -3
- package/crs/README.md +0 -84
- package/crs/schemas/README.md +0 -9
- package/dist/geoarrow/builder-entry.d.ts +0 -4
- package/dist/geoarrow/builder-entry.d.ts.map +0 -1
- package/dist/geoarrow/builder-entry.js +0 -5
- package/dist/geoarrow/builder-entry.js.map +0 -1
- package/dist/geoarrow/builder.d.ts +0 -106
- package/dist/geoarrow/builder.d.ts.map +0 -1
- package/dist/geoarrow/builder.js +0 -668
- package/dist/geoarrow/builder.js.map +0 -1
- package/dist/geoarrow/codecs.d.ts +0 -24
- package/dist/geoarrow/codecs.d.ts.map +0 -1
- package/dist/geoarrow/codecs.js +0 -916
- package/dist/geoarrow/codecs.js.map +0 -1
- package/dist/geoarrow/index.cjs +0 -4352
- package/dist/geoarrow/index.cjs.map +0 -6
- package/dist/geoarrow/index.d.ts +0 -21
- package/dist/geoarrow/index.d.ts.map +0 -1
- package/dist/geoarrow/index.js +0 -15
- package/dist/geoarrow/index.js.map +0 -1
- package/dist/geoarrow/kernels.d.ts +0 -56
- package/dist/geoarrow/kernels.d.ts.map +0 -1
- package/dist/geoarrow/kernels.js +0 -982
- package/dist/geoarrow/kernels.js.map +0 -1
- package/dist/geoarrow/layout.d.ts +0 -66
- package/dist/geoarrow/layout.d.ts.map +0 -1
- package/dist/geoarrow/layout.js +0 -723
- package/dist/geoarrow/layout.js.map +0 -1
- package/dist/geoarrow/stream-tessellate.d.ts +0 -34
- package/dist/geoarrow/stream-tessellate.d.ts.map +0 -1
- package/dist/geoarrow/stream-tessellate.js +0 -171
- package/dist/geoarrow/stream-tessellate.js.map +0 -1
- package/dist/geoarrow/stream.d.ts +0 -29
- package/dist/geoarrow/stream.d.ts.map +0 -1
- package/dist/geoarrow/stream.js +0 -100
- package/dist/geoarrow/stream.js.map +0 -1
- package/dist/geoarrow/tessellate.d.ts +0 -31
- package/dist/geoarrow/tessellate.d.ts.map +0 -1
- package/dist/geoarrow/tessellate.js +0 -102
- package/dist/geoarrow/tessellate.js.map +0 -1
- package/dist/geoarrow/tessellation-entry.d.ts +0 -4
- package/dist/geoarrow/tessellation-entry.d.ts.map +0 -1
- package/dist/geoarrow/tessellation-entry.js +0 -5
- package/dist/geoarrow/tessellation-entry.js.map +0 -1
- package/dist/geoarrow/types.d.ts +0 -155
- package/dist/geoarrow/types.d.ts.map +0 -1
- package/dist/geoarrow/types.js +0 -71
- package/dist/geoarrow/types.js.map +0 -1
- package/dist/geoarrow/views.d.ts +0 -45
- package/dist/geoarrow/views.d.ts.map +0 -1
- package/dist/geoarrow/views.js +0 -114
- package/dist/geoarrow/views.js.map +0 -1
- package/dist/geoarrow/wkb-entry.d.ts +0 -4
- package/dist/geoarrow/wkb-entry.d.ts.map +0 -1
- package/dist/geoarrow/wkb-entry.js +0 -6
- package/dist/geoarrow/wkb-entry.js.map +0 -1
- package/dist/geoarrow/worker.d.ts +0 -11
- package/dist/geoarrow/worker.d.ts.map +0 -1
- package/dist/geoarrow/worker.js +0 -10
- package/dist/geoarrow/worker.js.map +0 -1
- package/dist/wkb/index.d.ts +0 -11
- package/dist/wkb/index.d.ts.map +0 -1
- package/dist/wkb/index.js +0 -9
- package/dist/wkb/index.js.map +0 -1
- package/dist/wkb/types.d.ts +0 -30
- package/dist/wkb/types.d.ts.map +0 -1
- package/dist/wkb/types.js +0 -34
- package/dist/wkb/types.js.map +0 -1
- package/dist/wkb/wkb-builder.d.ts +0 -91
- package/dist/wkb/wkb-builder.d.ts.map +0 -1
- package/dist/wkb/wkb-builder.js +0 -283
- package/dist/wkb/wkb-builder.js.map +0 -1
- package/dist/wkb/wkb-reader.d.ts +0 -74
- package/dist/wkb/wkb-reader.d.ts.map +0 -1
- package/dist/wkb/wkb-reader.js +0 -251
- package/dist/wkb/wkb-reader.js.map +0 -1
- package/dist/wkb/wkb.d.ts +0 -21
- package/dist/wkb/wkb.d.ts.map +0 -1
- package/dist/wkb/wkb.js +0 -204
- package/dist/wkb/wkb.js.map +0 -1
- package/dist/wkb/wkt.d.ts +0 -19
- package/dist/wkb/wkt.d.ts.map +0 -1
- package/dist/wkb/wkt.js +0 -321
- package/dist/wkb/wkt.js.map +0 -1
- package/projection/THIRD-PARTY-NOTICES.md +0 -210
- package/src/discontinuous/elastic/README.md +0 -20
- package/src/discontinuous/spherical-clip/README.md +0 -16
- package/src/discontinuous/world-kernels/README.md +0 -24
- package/src/geoarrow/builder-entry.ts +0 -18
- package/src/geoarrow/builder.ts +0 -860
- package/src/geoarrow/codecs.ts +0 -1268
- package/src/geoarrow/index.ts +0 -111
- package/src/geoarrow/kernels.ts +0 -1290
- package/src/geoarrow/layout.ts +0 -900
- package/src/geoarrow/stream-tessellate.ts +0 -205
- package/src/geoarrow/stream.ts +0 -130
- package/src/geoarrow/tessellate.ts +0 -133
- package/src/geoarrow/tessellation-entry.ts +0 -7
- package/src/geoarrow/types.ts +0 -259
- package/src/geoarrow/views.ts +0 -150
- package/src/geoarrow/wkb-entry.ts +0 -13
- package/src/geoarrow/worker.ts +0 -20
- package/src/terrain/vendor/README.md +0 -20
- package/src/vendor/geographiclib-geodesic/README.md +0 -26
- package/src/wkb/index.ts +0 -38
- package/src/wkb/types.ts +0 -54
- package/src/wkb/wkb-builder.ts +0 -395
- package/src/wkb/wkb-reader.ts +0 -401
- package/src/wkb/wkb.ts +0 -255
- package/src/wkb/wkt.ts +0 -375
- /package/{projection/APACHE-2.0-LICENSE.txt → APACHE-2.0-LICENSE.txt} +0 -0
- /package/{projection/PROJ-LICENSE.txt → PROJ-LICENSE.txt} +0 -0
- /package/{projection/PROJ4-LICENSE.md → PROJ4-LICENSE.md} +0 -0
- /package/{crs/schemas → src/crs}/projjson.schema.json +0 -0
package/src/geoarrow/codecs.ts
DELETED
|
@@ -1,1268 +0,0 @@
|
|
|
1
|
-
// math.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import {formatWKT, inspectWKBHeader, parseWKT, visitWKB} from '../wkb/index';
|
|
6
|
-
import type {WKBHeader, WKBTraversalOptions} from '../wkb/index';
|
|
7
|
-
import {WKBBuilder} from '../wkb/index';
|
|
8
|
-
import type {
|
|
9
|
-
GeoArrowColumn,
|
|
10
|
-
GeoArrowCoordinateLayout,
|
|
11
|
-
GeoArrowDenseUnionChild,
|
|
12
|
-
GeoArrowDimension,
|
|
13
|
-
GeoArrowGeometryValue,
|
|
14
|
-
GeoArrowSerialized
|
|
15
|
-
} from './types';
|
|
16
|
-
import {getGeoArrowDimensionSize, mergeGeoArrowDimensions} from './types';
|
|
17
|
-
import type {GeoArrowBuilderEncoding} from './builder';
|
|
18
|
-
import {GeoArrowBuilder, makeGeoArrowColumnFromGeometryRows} from './builder';
|
|
19
|
-
import {getGeoArrowOffset, isGeoArrowValueValid, materializeGeometryRow} from './layout';
|
|
20
|
-
|
|
21
|
-
const textEncoder = new TextEncoder();
|
|
22
|
-
const textDecoder = new TextDecoder();
|
|
23
|
-
|
|
24
|
-
/** Buffer controls applied while decoding WKB directly to its final native representation. */
|
|
25
|
-
export type DecodeGeoArrowWKBOptions = Readonly<{
|
|
26
|
-
encoding?:
|
|
27
|
-
| GeoArrowBuilderEncoding
|
|
28
|
-
| 'geoarrow.geometry'
|
|
29
|
-
| 'geoarrow.geometrycollection'
|
|
30
|
-
| 'native';
|
|
31
|
-
/** Defaults to `infer`, because serialized Arrow storage has no physical coordinate dimension. */
|
|
32
|
-
dimension?: GeoArrowDimension | 'infer' | 'preserve';
|
|
33
|
-
coordinateLayout?: GeoArrowCoordinateLayout;
|
|
34
|
-
coordinateType?: 'float32' | 'float64';
|
|
35
|
-
offsetType?: 'int32' | 'int64';
|
|
36
|
-
traversal?: WKBTraversalOptions;
|
|
37
|
-
}>;
|
|
38
|
-
|
|
39
|
-
type WKBChunkClassification = {
|
|
40
|
-
families: Uint8Array;
|
|
41
|
-
dimensions: Uint8Array;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
type WKBDecodeBuilderOptions = {
|
|
45
|
-
dimension: GeoArrowDimension;
|
|
46
|
-
coordinateLayout: GeoArrowCoordinateLayout;
|
|
47
|
-
coordinateType: 'float32' | 'float64';
|
|
48
|
-
offsetType: 'int32' | 'int64';
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const NULL_FAMILY = 255;
|
|
52
|
-
|
|
53
|
-
/** Decodes a GeoArrow WKB column into final native physical geometry buffers. */
|
|
54
|
-
export function decodeGeoArrowWKB(
|
|
55
|
-
column: GeoArrowColumn,
|
|
56
|
-
options: DecodeGeoArrowWKBOptions = {}
|
|
57
|
-
): GeoArrowColumn {
|
|
58
|
-
if (column.encoding !== 'geoarrow.wkb') throw new Error('Expected a geoarrow.wkb column');
|
|
59
|
-
const classifications: WKBChunkClassification[] = [];
|
|
60
|
-
const schemaKeys = new Set<number>();
|
|
61
|
-
const collectionSchemas: Array<Set<number>> = [];
|
|
62
|
-
const rootFamilies = new Set<number>();
|
|
63
|
-
let hasNulls = false;
|
|
64
|
-
let inferredDimension: GeoArrowDimension = 'xy';
|
|
65
|
-
for (const chunk of column.chunks) {
|
|
66
|
-
if (chunk.kind !== 'serialized') throw new Error('Serialized column contains native storage');
|
|
67
|
-
const families = new Uint8Array(chunk.length).fill(NULL_FAMILY);
|
|
68
|
-
const dimensions = new Uint8Array(chunk.length);
|
|
69
|
-
for (let rowIndex = 0; rowIndex < chunk.length; rowIndex++) {
|
|
70
|
-
if (!isGeoArrowValueValid(chunk.validity, rowIndex)) {
|
|
71
|
-
hasNulls = true;
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
const bytes = getSerializedBytes(chunk, rowIndex);
|
|
75
|
-
const rootHeader = inspectWKBHeader(bytes);
|
|
76
|
-
const rootFamily = getGeometryFamilyIndex(rootHeader.geometryType);
|
|
77
|
-
let rowDimension: GeoArrowDimension = rootHeader.dimension;
|
|
78
|
-
if (rootHeader.geometryType === 'GeometryCollection') {
|
|
79
|
-
const collectionStack: Array<{depth: number; level: number}> = [];
|
|
80
|
-
let concreteRootDepth = -1;
|
|
81
|
-
visitWKB(
|
|
82
|
-
bytes,
|
|
83
|
-
{
|
|
84
|
-
geometry: (header, _count, depth) => {
|
|
85
|
-
rowDimension = mergeGeoArrowDimensions(rowDimension, header.dimension);
|
|
86
|
-
if (concreteRootDepth >= 0 && depth > concreteRootDepth) return;
|
|
87
|
-
concreteRootDepth = -1;
|
|
88
|
-
while (
|
|
89
|
-
collectionStack.length &&
|
|
90
|
-
depth <= collectionStack[collectionStack.length - 1].depth
|
|
91
|
-
) {
|
|
92
|
-
collectionStack.pop();
|
|
93
|
-
}
|
|
94
|
-
const parent = collectionStack[collectionStack.length - 1];
|
|
95
|
-
if (parent) {
|
|
96
|
-
collectionSchemas[parent.level] ||= new Set<number>();
|
|
97
|
-
collectionSchemas[parent.level].add(
|
|
98
|
-
getGeometryTypeId(header.geometryType, header.dimension)
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
if (header.geometryType === 'GeometryCollection') {
|
|
102
|
-
collectionStack.push({depth, level: parent ? parent.level + 1 : 0});
|
|
103
|
-
} else if (parent) {
|
|
104
|
-
concreteRootDepth = depth;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
options.traversal
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
families[rowIndex] = rootFamily;
|
|
112
|
-
dimensions[rowIndex] = getDimensionIndex(rowDimension);
|
|
113
|
-
rootFamilies.add(rootFamily);
|
|
114
|
-
schemaKeys.add(getGeometryTypeIdFromIndices(rootFamily, dimensions[rowIndex]));
|
|
115
|
-
inferredDimension = mergeGeoArrowDimensions(inferredDimension, rowDimension);
|
|
116
|
-
}
|
|
117
|
-
classifications.push({families, dimensions});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const dimension = resolveDecodeDimension(options.dimension, column.dimension, inferredDimension);
|
|
121
|
-
const forceDimension = Boolean(options.dimension && options.dimension !== 'infer');
|
|
122
|
-
if (forceDimension) {
|
|
123
|
-
schemaKeys.clear();
|
|
124
|
-
for (const classification of classifications) {
|
|
125
|
-
for (let rowIndex = 0; rowIndex < classification.families.length; rowIndex++) {
|
|
126
|
-
const family = classification.families[rowIndex];
|
|
127
|
-
if (family === NULL_FAMILY) continue;
|
|
128
|
-
classification.dimensions[rowIndex] = getDimensionIndex(dimension);
|
|
129
|
-
schemaKeys.add(getGeometryTypeIdFromIndices(family, getDimensionIndex(dimension)));
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
const encoding = resolveDecodeEncoding(options.encoding, rootFamilies);
|
|
134
|
-
validateDecodeEncoding(encoding, rootFamilies);
|
|
135
|
-
const builderOptions = {
|
|
136
|
-
dimension,
|
|
137
|
-
coordinateLayout: options.coordinateLayout || 'interleaved',
|
|
138
|
-
coordinateType: options.coordinateType || 'float64',
|
|
139
|
-
offsetType: options.offsetType || 'int32'
|
|
140
|
-
} as const;
|
|
141
|
-
|
|
142
|
-
if (encoding !== 'geoarrow.geometry' && encoding !== 'geoarrow.geometrycollection') {
|
|
143
|
-
const chunks = column.chunks.map((chunk, chunkIndex) =>
|
|
144
|
-
decodeConcreteWKBChunk(
|
|
145
|
-
chunk as GeoArrowSerialized,
|
|
146
|
-
classifications[chunkIndex],
|
|
147
|
-
encoding,
|
|
148
|
-
builderOptions,
|
|
149
|
-
options.traversal
|
|
150
|
-
)
|
|
151
|
-
);
|
|
152
|
-
return copyMetadata(column, {
|
|
153
|
-
encoding,
|
|
154
|
-
dimension,
|
|
155
|
-
coordinateLayout: builderOptions.coordinateLayout,
|
|
156
|
-
chunks
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (encoding === 'geoarrow.geometrycollection') {
|
|
161
|
-
const stableCollectionSchemas = normalizeCollectionSchemas(
|
|
162
|
-
collectionSchemas,
|
|
163
|
-
dimension,
|
|
164
|
-
forceDimension
|
|
165
|
-
);
|
|
166
|
-
const chunks = column.chunks.map((chunk, chunkIndex) =>
|
|
167
|
-
decodeGeometryCollectionWKBChunk(
|
|
168
|
-
chunk as GeoArrowSerialized,
|
|
169
|
-
classifications[chunkIndex],
|
|
170
|
-
undefined,
|
|
171
|
-
stableCollectionSchemas,
|
|
172
|
-
builderOptions,
|
|
173
|
-
options.traversal,
|
|
174
|
-
forceDimension ? dimension : undefined
|
|
175
|
-
)
|
|
176
|
-
);
|
|
177
|
-
return copyMetadata(column, {
|
|
178
|
-
encoding,
|
|
179
|
-
dimension,
|
|
180
|
-
coordinateLayout: builderOptions.coordinateLayout,
|
|
181
|
-
chunks
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (schemaKeys.size === 0) schemaKeys.add(getGeometryTypeId('Point', dimension));
|
|
186
|
-
if (hasNulls) schemaKeys.add(getGeometryTypeId('Point', dimension));
|
|
187
|
-
const stableSchema = [...schemaKeys].sort((left, right) => left - right);
|
|
188
|
-
const chunks = column.chunks.map((chunk, chunkIndex) =>
|
|
189
|
-
decodeUnionWKBChunk(
|
|
190
|
-
chunk as GeoArrowSerialized,
|
|
191
|
-
classifications[chunkIndex],
|
|
192
|
-
stableSchema,
|
|
193
|
-
normalizeCollectionSchemas(collectionSchemas, dimension, forceDimension),
|
|
194
|
-
builderOptions,
|
|
195
|
-
options.traversal,
|
|
196
|
-
forceDimension ? dimension : undefined
|
|
197
|
-
)
|
|
198
|
-
);
|
|
199
|
-
return copyMetadata(column, {
|
|
200
|
-
encoding: 'geoarrow.geometry',
|
|
201
|
-
dimension,
|
|
202
|
-
coordinateLayout: builderOptions.coordinateLayout,
|
|
203
|
-
chunks
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/** Counts vertices in serialized WKB chunks without decoding ordinates or allocating rows. */
|
|
208
|
-
export function getGeoArrowWKBVertexCount(
|
|
209
|
-
column: GeoArrowColumn,
|
|
210
|
-
traversal?: WKBTraversalOptions
|
|
211
|
-
): number {
|
|
212
|
-
if (column.encoding !== 'geoarrow.wkb') throw new Error('Expected a geoarrow.wkb column');
|
|
213
|
-
let vertexCount = 0;
|
|
214
|
-
for (const chunk of column.chunks) {
|
|
215
|
-
if (chunk.kind !== 'serialized') throw new Error('Serialized column contains native storage');
|
|
216
|
-
for (let rowIndex = 0; rowIndex < chunk.length; rowIndex++) {
|
|
217
|
-
if (!isGeoArrowValueValid(chunk.validity, rowIndex)) continue;
|
|
218
|
-
visitWKB(
|
|
219
|
-
getSerializedBytes(chunk, rowIndex),
|
|
220
|
-
{
|
|
221
|
-
geometry: (header, count) => {
|
|
222
|
-
if (header.geometryType === 'Point') vertexCount++;
|
|
223
|
-
else if (header.geometryType === 'LineString') vertexCount += count || 0;
|
|
224
|
-
},
|
|
225
|
-
ring: pointCount => {
|
|
226
|
-
vertexCount += pointCount;
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
traversal
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return vertexCount;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function decodeConcreteWKBChunk(
|
|
237
|
-
chunk: GeoArrowSerialized,
|
|
238
|
-
classification: WKBChunkClassification,
|
|
239
|
-
encoding: GeoArrowBuilderEncoding,
|
|
240
|
-
options: WKBDecodeBuilderOptions,
|
|
241
|
-
traversal: WKBTraversalOptions | undefined
|
|
242
|
-
): import('./types').GeoArrowArray {
|
|
243
|
-
const measure = new GeoArrowBuilder({...options, encoding, mode: 'measure'});
|
|
244
|
-
replaySerializedChunk(chunk, classification, encoding, measure, traversal);
|
|
245
|
-
const write = new GeoArrowBuilder({
|
|
246
|
-
...options,
|
|
247
|
-
encoding,
|
|
248
|
-
mode: 'write',
|
|
249
|
-
target: measure.allocateTarget()
|
|
250
|
-
});
|
|
251
|
-
replaySerializedChunk(chunk, classification, encoding, write, traversal);
|
|
252
|
-
return write.finish().chunks[0];
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function replaySerializedChunk(
|
|
256
|
-
chunk: GeoArrowSerialized,
|
|
257
|
-
classification: WKBChunkClassification,
|
|
258
|
-
encoding: GeoArrowBuilderEncoding,
|
|
259
|
-
builder: GeoArrowBuilder,
|
|
260
|
-
traversal: WKBTraversalOptions | undefined
|
|
261
|
-
): void {
|
|
262
|
-
const targetType = geometryTypeFromEncoding(encoding);
|
|
263
|
-
for (let rowIndex = 0; rowIndex < chunk.length; rowIndex++) {
|
|
264
|
-
if (classification.families[rowIndex] === NULL_FAMILY) builder.append(null);
|
|
265
|
-
else visitWKBIntoBuilder(getSerializedBytes(chunk, rowIndex), builder, targetType, traversal);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
function decodeUnionWKBChunk(
|
|
270
|
-
chunk: GeoArrowSerialized,
|
|
271
|
-
classification: WKBChunkClassification,
|
|
272
|
-
stableSchema: readonly number[],
|
|
273
|
-
collectionSchemas: readonly (readonly number[])[],
|
|
274
|
-
options: WKBDecodeBuilderOptions,
|
|
275
|
-
traversal: WKBTraversalOptions | undefined,
|
|
276
|
-
childDimensionOverride: GeoArrowDimension | undefined
|
|
277
|
-
): import('./types').GeoArrowDenseUnion {
|
|
278
|
-
const measureBuilders = new Map<number, GeoArrowBuilder>();
|
|
279
|
-
for (const key of stableSchema) {
|
|
280
|
-
const type = getGeometryTypeFromId(key);
|
|
281
|
-
if (type !== 'GeometryCollection') {
|
|
282
|
-
const encoding = encodingFromGeometryType(type);
|
|
283
|
-
measureBuilders.set(
|
|
284
|
-
key,
|
|
285
|
-
new GeoArrowBuilder({
|
|
286
|
-
...options,
|
|
287
|
-
encoding,
|
|
288
|
-
dimension: getDimensionFromId(key),
|
|
289
|
-
mode: 'measure'
|
|
290
|
-
})
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
const typeIds = new Int8Array(chunk.length);
|
|
295
|
-
const valueOffsets = new Int32Array(chunk.length);
|
|
296
|
-
const childCounts = new Map<number, number>();
|
|
297
|
-
const nullKey = stableSchema[0];
|
|
298
|
-
for (let rowIndex = 0; rowIndex < chunk.length; rowIndex++) {
|
|
299
|
-
const family = classification.families[rowIndex];
|
|
300
|
-
const key =
|
|
301
|
-
family === NULL_FAMILY
|
|
302
|
-
? nullKey
|
|
303
|
-
: getGeometryTypeIdFromIndices(family, classification.dimensions[rowIndex]);
|
|
304
|
-
typeIds[rowIndex] = key;
|
|
305
|
-
valueOffsets[rowIndex] = childCounts.get(key) || 0;
|
|
306
|
-
childCounts.set(key, valueOffsets[rowIndex] + 1);
|
|
307
|
-
const builder = measureBuilders.get(key);
|
|
308
|
-
if (builder) {
|
|
309
|
-
if (family === NULL_FAMILY) builder.append(null);
|
|
310
|
-
else
|
|
311
|
-
visitWKBIntoBuilder(
|
|
312
|
-
getSerializedBytes(chunk, rowIndex),
|
|
313
|
-
builder,
|
|
314
|
-
getConcreteGeometryTypeFromId(key),
|
|
315
|
-
traversal
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
const writeBuilders = new Map<number, GeoArrowBuilder>();
|
|
320
|
-
for (const key of stableSchema) {
|
|
321
|
-
if (getGeometryTypeFromId(key) === 'GeometryCollection') continue;
|
|
322
|
-
const measure = measureBuilders.get(key)!;
|
|
323
|
-
writeBuilders.set(
|
|
324
|
-
key,
|
|
325
|
-
new GeoArrowBuilder({
|
|
326
|
-
...options,
|
|
327
|
-
encoding: encodingFromGeometryType(getConcreteGeometryTypeFromId(key)),
|
|
328
|
-
dimension: getDimensionFromId(key),
|
|
329
|
-
mode: 'write',
|
|
330
|
-
target: measure.allocateTarget()
|
|
331
|
-
})
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
for (let rowIndex = 0; rowIndex < chunk.length; rowIndex++) {
|
|
335
|
-
const family = classification.families[rowIndex];
|
|
336
|
-
const key =
|
|
337
|
-
family === NULL_FAMILY
|
|
338
|
-
? nullKey
|
|
339
|
-
: getGeometryTypeIdFromIndices(family, classification.dimensions[rowIndex]);
|
|
340
|
-
const builder = writeBuilders.get(key);
|
|
341
|
-
if (builder) {
|
|
342
|
-
if (family === NULL_FAMILY) builder.append(null);
|
|
343
|
-
else
|
|
344
|
-
visitWKBIntoBuilder(
|
|
345
|
-
getSerializedBytes(chunk, rowIndex),
|
|
346
|
-
builder,
|
|
347
|
-
getConcreteGeometryTypeFromId(key),
|
|
348
|
-
traversal
|
|
349
|
-
);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
const children: GeoArrowDenseUnionChild[] = stableSchema.map(key => {
|
|
353
|
-
const type = getGeometryTypeFromId(key);
|
|
354
|
-
if (type === 'GeometryCollection') {
|
|
355
|
-
return {
|
|
356
|
-
name: type,
|
|
357
|
-
typeId: key,
|
|
358
|
-
encoding: 'geoarrow.geometrycollection',
|
|
359
|
-
dimension: getDimensionFromId(key),
|
|
360
|
-
coordinateLayout: options.coordinateLayout,
|
|
361
|
-
data: decodeGeometryCollectionWKBChunk(
|
|
362
|
-
chunk,
|
|
363
|
-
classification,
|
|
364
|
-
key,
|
|
365
|
-
collectionSchemas,
|
|
366
|
-
{...options, dimension: getDimensionFromId(key)},
|
|
367
|
-
traversal,
|
|
368
|
-
childDimensionOverride
|
|
369
|
-
)
|
|
370
|
-
};
|
|
371
|
-
}
|
|
372
|
-
const built = writeBuilders.get(key)!.finish();
|
|
373
|
-
return {
|
|
374
|
-
name: getGeometryTypeFromId(key),
|
|
375
|
-
typeId: key,
|
|
376
|
-
encoding: built.encoding,
|
|
377
|
-
dimension: built.dimension,
|
|
378
|
-
coordinateLayout: built.coordinateLayout,
|
|
379
|
-
data: built.chunks[0]
|
|
380
|
-
};
|
|
381
|
-
});
|
|
382
|
-
return {kind: 'dense-union', length: chunk.length, typeIds, valueOffsets, children};
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
type CollectionMeasureLevel = {
|
|
386
|
-
schema: readonly number[];
|
|
387
|
-
rowCount: number;
|
|
388
|
-
childCount: number;
|
|
389
|
-
builders: Map<number, GeoArrowBuilder>;
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
type CollectionWriteLevel = {
|
|
393
|
-
schema: readonly number[];
|
|
394
|
-
rowCursor: number;
|
|
395
|
-
childCursor: number;
|
|
396
|
-
offsets: import('./types').GeoArrowOffsets;
|
|
397
|
-
typeIds: Int8Array;
|
|
398
|
-
valueOffsets: Int32Array;
|
|
399
|
-
childCounts: Map<number, number>;
|
|
400
|
-
builders: Map<number, GeoArrowBuilder>;
|
|
401
|
-
};
|
|
402
|
-
|
|
403
|
-
function decodeGeometryCollectionWKBChunk(
|
|
404
|
-
chunk: GeoArrowSerialized,
|
|
405
|
-
classification: WKBChunkClassification,
|
|
406
|
-
selectorKey: number | undefined,
|
|
407
|
-
schemas: readonly (readonly number[])[],
|
|
408
|
-
options: WKBDecodeBuilderOptions,
|
|
409
|
-
traversal: WKBTraversalOptions | undefined,
|
|
410
|
-
childDimensionOverride: GeoArrowDimension | undefined
|
|
411
|
-
): import('./types').GeoArrowList {
|
|
412
|
-
const measureLevels = schemas.map(schema => makeCollectionMeasureLevel(schema, options));
|
|
413
|
-
if (measureLevels.length === 0) measureLevels.push(makeCollectionMeasureLevel([], options));
|
|
414
|
-
forEachSelectedCollectionRow(chunk, classification, selectorKey, (bytes, valid) => {
|
|
415
|
-
if (!valid) {
|
|
416
|
-
measureLevels[0].rowCount++;
|
|
417
|
-
return;
|
|
418
|
-
}
|
|
419
|
-
replayWKBCollection(
|
|
420
|
-
bytes!,
|
|
421
|
-
measureLevels,
|
|
422
|
-
undefined,
|
|
423
|
-
options.dimension,
|
|
424
|
-
traversal,
|
|
425
|
-
childDimensionOverride
|
|
426
|
-
);
|
|
427
|
-
});
|
|
428
|
-
|
|
429
|
-
const writeLevels = measureLevels.map(level => makeCollectionWriteLevel(level, options));
|
|
430
|
-
forEachSelectedCollectionRow(chunk, classification, selectorKey, (bytes, valid) => {
|
|
431
|
-
if (!valid) {
|
|
432
|
-
writeCollectionRow(writeLevels[0], 0);
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
replayWKBCollection(
|
|
436
|
-
bytes!,
|
|
437
|
-
measureLevels,
|
|
438
|
-
writeLevels,
|
|
439
|
-
options.dimension,
|
|
440
|
-
traversal,
|
|
441
|
-
childDimensionOverride
|
|
442
|
-
);
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
const root = makeCollectionLevelArray(0, measureLevels, writeLevels, options);
|
|
446
|
-
if (selectorKey !== undefined) return root;
|
|
447
|
-
const validity = new Uint8Array(Math.ceil(root.length / 8));
|
|
448
|
-
for (let rowIndex = 0; rowIndex < classification.families.length; rowIndex++) {
|
|
449
|
-
if (classification.families[rowIndex] === getGeometryFamilyIndex('GeometryCollection')) {
|
|
450
|
-
validity[rowIndex >> 3] |= 1 << (rowIndex & 7);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
return {...root, validity: {values: validity}};
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
function forEachSelectedCollectionRow(
|
|
457
|
-
chunk: GeoArrowSerialized,
|
|
458
|
-
classification: WKBChunkClassification,
|
|
459
|
-
selectorKey: number | undefined,
|
|
460
|
-
visitor: (bytes: Uint8Array | undefined, valid: boolean) => void
|
|
461
|
-
): void {
|
|
462
|
-
const collectionFamily = getGeometryFamilyIndex('GeometryCollection');
|
|
463
|
-
for (let rowIndex = 0; rowIndex < chunk.length; rowIndex++) {
|
|
464
|
-
const family = classification.families[rowIndex];
|
|
465
|
-
if (selectorKey === undefined) {
|
|
466
|
-
if (family === NULL_FAMILY) visitor(undefined, false);
|
|
467
|
-
else if (family === collectionFamily) visitor(getSerializedBytes(chunk, rowIndex), true);
|
|
468
|
-
else throw new Error('Rows cannot be represented as geoarrow.geometrycollection');
|
|
469
|
-
} else if (
|
|
470
|
-
family === collectionFamily &&
|
|
471
|
-
getGeometryTypeIdFromIndices(family, classification.dimensions[rowIndex]) === selectorKey
|
|
472
|
-
) {
|
|
473
|
-
visitor(getSerializedBytes(chunk, rowIndex), true);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
function makeCollectionMeasureLevel(
|
|
479
|
-
schema: readonly number[],
|
|
480
|
-
options: WKBDecodeBuilderOptions
|
|
481
|
-
): CollectionMeasureLevel {
|
|
482
|
-
const builders = new Map<number, GeoArrowBuilder>();
|
|
483
|
-
for (const key of schema) {
|
|
484
|
-
const type = getGeometryTypeFromId(key);
|
|
485
|
-
if (type !== 'GeometryCollection') {
|
|
486
|
-
builders.set(
|
|
487
|
-
key,
|
|
488
|
-
new GeoArrowBuilder({
|
|
489
|
-
...options,
|
|
490
|
-
encoding: encodingFromGeometryType(type),
|
|
491
|
-
dimension: getDimensionFromId(key),
|
|
492
|
-
mode: 'measure'
|
|
493
|
-
})
|
|
494
|
-
);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
return {schema, rowCount: 0, childCount: 0, builders};
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
function makeCollectionWriteLevel(
|
|
501
|
-
measure: CollectionMeasureLevel,
|
|
502
|
-
options: WKBDecodeBuilderOptions
|
|
503
|
-
): CollectionWriteLevel {
|
|
504
|
-
const OffsetArray = options.offsetType === 'int64' ? BigInt64Array : Int32Array;
|
|
505
|
-
const builders = new Map<number, GeoArrowBuilder>();
|
|
506
|
-
for (const [key, builder] of measure.builders) {
|
|
507
|
-
builders.set(
|
|
508
|
-
key,
|
|
509
|
-
new GeoArrowBuilder({
|
|
510
|
-
...options,
|
|
511
|
-
encoding: encodingFromGeometryType(getConcreteGeometryTypeFromId(key)),
|
|
512
|
-
dimension: getDimensionFromId(key),
|
|
513
|
-
mode: 'write',
|
|
514
|
-
target: builder.allocateTarget()
|
|
515
|
-
})
|
|
516
|
-
);
|
|
517
|
-
}
|
|
518
|
-
return {
|
|
519
|
-
schema: measure.schema,
|
|
520
|
-
rowCursor: 0,
|
|
521
|
-
childCursor: 0,
|
|
522
|
-
offsets: new OffsetArray(measure.rowCount + 1),
|
|
523
|
-
typeIds: new Int8Array(measure.childCount),
|
|
524
|
-
valueOffsets: new Int32Array(measure.childCount),
|
|
525
|
-
childCounts: new Map(),
|
|
526
|
-
builders
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
function replayWKBCollection(
|
|
531
|
-
bytes: Uint8Array,
|
|
532
|
-
measureLevels: CollectionMeasureLevel[],
|
|
533
|
-
writeLevels: CollectionWriteLevel[] | undefined,
|
|
534
|
-
collectionDimension: GeoArrowDimension,
|
|
535
|
-
traversal: WKBTraversalOptions | undefined,
|
|
536
|
-
childDimensionOverride: GeoArrowDimension | undefined
|
|
537
|
-
): void {
|
|
538
|
-
const collectionStack: Array<{depth: number; level: number}> = [];
|
|
539
|
-
let active:
|
|
540
|
-
| {
|
|
541
|
-
builder: GeoArrowBuilder;
|
|
542
|
-
rootDepth: number;
|
|
543
|
-
rootType: Exclude<WKBHeader['geometryType'], 'GeometryCollection'>;
|
|
544
|
-
}
|
|
545
|
-
| undefined;
|
|
546
|
-
const finishActive = (): void => {
|
|
547
|
-
active?.builder.endGeometry();
|
|
548
|
-
active = undefined;
|
|
549
|
-
};
|
|
550
|
-
visitWKB(
|
|
551
|
-
bytes,
|
|
552
|
-
{
|
|
553
|
-
geometry: (header, count, depth) => {
|
|
554
|
-
if (active && depth > active.rootDepth) {
|
|
555
|
-
if (active.rootType === 'MultiLineString' && header.geometryType === 'LineString') {
|
|
556
|
-
active.builder.beginRing(count);
|
|
557
|
-
} else if (active.rootType === 'MultiPolygon' && header.geometryType === 'Polygon') {
|
|
558
|
-
active.builder.beginPolygon();
|
|
559
|
-
}
|
|
560
|
-
return;
|
|
561
|
-
}
|
|
562
|
-
finishActive();
|
|
563
|
-
while (
|
|
564
|
-
collectionStack.length &&
|
|
565
|
-
depth <= collectionStack[collectionStack.length - 1].depth
|
|
566
|
-
) {
|
|
567
|
-
collectionStack.pop();
|
|
568
|
-
}
|
|
569
|
-
const parent = collectionStack[collectionStack.length - 1];
|
|
570
|
-
if (header.geometryType === 'GeometryCollection') {
|
|
571
|
-
if (parent) {
|
|
572
|
-
addCollectionChild(
|
|
573
|
-
measureLevels[parent.level],
|
|
574
|
-
writeLevels?.[parent.level],
|
|
575
|
-
getGeometryTypeId('GeometryCollection', collectionDimension)
|
|
576
|
-
);
|
|
577
|
-
}
|
|
578
|
-
const level = parent ? parent.level + 1 : 0;
|
|
579
|
-
if (!measureLevels[level]) {
|
|
580
|
-
measureLevels[level] = makeCollectionMeasureLevel([], {
|
|
581
|
-
dimension: collectionDimension,
|
|
582
|
-
coordinateLayout: 'interleaved',
|
|
583
|
-
coordinateType: 'float64',
|
|
584
|
-
offsetType: 'int32'
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
if (writeLevels) writeCollectionRow(writeLevels[level], count || 0);
|
|
588
|
-
else measureLevels[level].rowCount++;
|
|
589
|
-
collectionStack.push({depth, level});
|
|
590
|
-
return;
|
|
591
|
-
}
|
|
592
|
-
if (!parent) throw new Error('Expected a GeometryCollection root');
|
|
593
|
-
const key = getGeometryTypeId(
|
|
594
|
-
header.geometryType,
|
|
595
|
-
childDimensionOverride || header.dimension
|
|
596
|
-
);
|
|
597
|
-
addCollectionChild(measureLevels[parent.level], writeLevels?.[parent.level], key);
|
|
598
|
-
const builder = writeLevels
|
|
599
|
-
? writeLevels[parent.level].builders.get(key)
|
|
600
|
-
: measureLevels[parent.level].builders.get(key);
|
|
601
|
-
if (!builder) throw new Error(`Missing GeometryCollection child schema for type ID ${key}`);
|
|
602
|
-
builder.beginGeometry(header.geometryType, header.dimension, count);
|
|
603
|
-
active = {builder, rootDepth: depth, rootType: header.geometryType};
|
|
604
|
-
},
|
|
605
|
-
ring: pointCount => active?.builder.beginRing(pointCount),
|
|
606
|
-
coordinate: (x, y, z, m, dimension) =>
|
|
607
|
-
active?.builder.writeCoordinateFromDimension(x, y, z, m, dimension)
|
|
608
|
-
},
|
|
609
|
-
traversal
|
|
610
|
-
);
|
|
611
|
-
finishActive();
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
function addCollectionChild(
|
|
615
|
-
measure: CollectionMeasureLevel,
|
|
616
|
-
write: CollectionWriteLevel | undefined,
|
|
617
|
-
key: number
|
|
618
|
-
): void {
|
|
619
|
-
if (!write) {
|
|
620
|
-
measure.childCount++;
|
|
621
|
-
return;
|
|
622
|
-
}
|
|
623
|
-
const index = write.childCursor++;
|
|
624
|
-
write.typeIds[index] = key;
|
|
625
|
-
write.valueOffsets[index] = write.childCounts.get(key) || 0;
|
|
626
|
-
write.childCounts.set(key, write.valueOffsets[index] + 1);
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
function writeCollectionRow(level: CollectionWriteLevel, childCount: number): void {
|
|
630
|
-
level.rowCursor++;
|
|
631
|
-
setGeoArrowOffset(level.offsets, level.rowCursor, level.childCursor + childCount);
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
function makeCollectionLevelArray(
|
|
635
|
-
levelIndex: number,
|
|
636
|
-
measureLevels: readonly CollectionMeasureLevel[],
|
|
637
|
-
writeLevels: readonly CollectionWriteLevel[],
|
|
638
|
-
options: WKBDecodeBuilderOptions
|
|
639
|
-
): import('./types').GeoArrowList {
|
|
640
|
-
const measure = measureLevels[levelIndex];
|
|
641
|
-
const write = writeLevels[levelIndex];
|
|
642
|
-
const children: GeoArrowDenseUnionChild[] = measure.schema.map(key => {
|
|
643
|
-
const type = getGeometryTypeFromId(key);
|
|
644
|
-
if (type === 'GeometryCollection') {
|
|
645
|
-
return {
|
|
646
|
-
name: type,
|
|
647
|
-
typeId: key,
|
|
648
|
-
encoding: 'geoarrow.geometrycollection',
|
|
649
|
-
dimension: getDimensionFromId(key),
|
|
650
|
-
coordinateLayout: options.coordinateLayout,
|
|
651
|
-
data: makeCollectionLevelArray(levelIndex + 1, measureLevels, writeLevels, options)
|
|
652
|
-
};
|
|
653
|
-
}
|
|
654
|
-
const built = write.builders.get(key)!.finish();
|
|
655
|
-
return {
|
|
656
|
-
name: type,
|
|
657
|
-
typeId: key,
|
|
658
|
-
encoding: built.encoding,
|
|
659
|
-
dimension: built.dimension,
|
|
660
|
-
coordinateLayout: built.coordinateLayout,
|
|
661
|
-
data: built.chunks[0]
|
|
662
|
-
};
|
|
663
|
-
});
|
|
664
|
-
return {
|
|
665
|
-
kind: 'list',
|
|
666
|
-
length: measure.rowCount,
|
|
667
|
-
offsets: write.offsets,
|
|
668
|
-
child: {
|
|
669
|
-
kind: 'dense-union',
|
|
670
|
-
length: measure.childCount,
|
|
671
|
-
typeIds: write.typeIds,
|
|
672
|
-
valueOffsets: write.valueOffsets,
|
|
673
|
-
children
|
|
674
|
-
}
|
|
675
|
-
};
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
function setGeoArrowOffset(
|
|
679
|
-
offsets: import('./types').GeoArrowOffsets,
|
|
680
|
-
index: number,
|
|
681
|
-
value: number
|
|
682
|
-
): void {
|
|
683
|
-
if (offsets instanceof BigInt64Array) offsets[index] = BigInt(value);
|
|
684
|
-
else offsets[index] = value;
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
function normalizeCollectionSchemas(
|
|
688
|
-
schemas: readonly ReadonlySet<number>[],
|
|
689
|
-
dimension: GeoArrowDimension,
|
|
690
|
-
forceDimension: boolean
|
|
691
|
-
): number[][] {
|
|
692
|
-
return schemas.map(schema =>
|
|
693
|
-
[...schema]
|
|
694
|
-
.map(key =>
|
|
695
|
-
forceDimension || getGeometryTypeFromId(key) === 'GeometryCollection'
|
|
696
|
-
? getGeometryTypeId(getGeometryTypeFromId(key), dimension)
|
|
697
|
-
: key
|
|
698
|
-
)
|
|
699
|
-
.filter((key, index, values) => values.indexOf(key) === index)
|
|
700
|
-
.sort((left, right) => left - right)
|
|
701
|
-
);
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
/** Replays one serialized geometry directly into a two-pass GeoArrowBuilder. */
|
|
705
|
-
function visitWKBIntoBuilder(
|
|
706
|
-
bytes: Uint8Array,
|
|
707
|
-
builder: GeoArrowBuilder,
|
|
708
|
-
targetType: Exclude<WKBHeader['geometryType'], 'GeometryCollection'>,
|
|
709
|
-
traversal?: WKBTraversalOptions
|
|
710
|
-
): void {
|
|
711
|
-
let rootType: WKBHeader['geometryType'] | undefined;
|
|
712
|
-
visitWKB(
|
|
713
|
-
bytes,
|
|
714
|
-
{
|
|
715
|
-
geometry: (header, _count, depth) => {
|
|
716
|
-
if (depth === 0) {
|
|
717
|
-
rootType = header.geometryType;
|
|
718
|
-
builder.beginGeometry(targetType, header.dimension, _count);
|
|
719
|
-
if (rootType === 'LineString' && targetType === 'MultiLineString')
|
|
720
|
-
builder.beginRing(_count);
|
|
721
|
-
if (rootType === 'Polygon' && targetType === 'MultiPolygon') builder.beginPolygon();
|
|
722
|
-
} else if (rootType === 'MultiLineString' && header.geometryType === 'LineString') {
|
|
723
|
-
builder.beginRing(_count);
|
|
724
|
-
} else if (rootType === 'MultiPolygon' && header.geometryType === 'Polygon') {
|
|
725
|
-
builder.beginPolygon();
|
|
726
|
-
}
|
|
727
|
-
},
|
|
728
|
-
ring: pointCount => {
|
|
729
|
-
if (rootType === 'Polygon' || rootType === 'MultiPolygon') builder.beginRing(pointCount);
|
|
730
|
-
},
|
|
731
|
-
coordinate: (x, y, z, m, dimension) => {
|
|
732
|
-
builder.writeCoordinateFromDimension(x, y, z, m, dimension);
|
|
733
|
-
}
|
|
734
|
-
},
|
|
735
|
-
traversal
|
|
736
|
-
);
|
|
737
|
-
builder.endGeometry();
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
function encodingFromGeometryType(
|
|
741
|
-
type: WKBHeader['geometryType']
|
|
742
|
-
): Exclude<
|
|
743
|
-
GeoArrowColumn['encoding'],
|
|
744
|
-
| 'geoarrow.geometry'
|
|
745
|
-
| 'geoarrow.geometrycollection'
|
|
746
|
-
| 'geoarrow.box'
|
|
747
|
-
| 'geoarrow.wkb'
|
|
748
|
-
| 'geoarrow.wkt'
|
|
749
|
-
> {
|
|
750
|
-
if (type === 'GeometryCollection')
|
|
751
|
-
throw new Error('GeometryCollection requires collection storage');
|
|
752
|
-
return `geoarrow.${type.toLowerCase()}` as Exclude<
|
|
753
|
-
GeoArrowColumn['encoding'],
|
|
754
|
-
| 'geoarrow.geometry'
|
|
755
|
-
| 'geoarrow.geometrycollection'
|
|
756
|
-
| 'geoarrow.box'
|
|
757
|
-
| 'geoarrow.wkb'
|
|
758
|
-
| 'geoarrow.wkt'
|
|
759
|
-
>;
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
function getGeometryTypeId(type: WKBHeader['geometryType'], dimension: GeoArrowDimension): number {
|
|
763
|
-
return getGeometryTypeIdFromIndices(getGeometryFamilyIndex(type), getDimensionIndex(dimension));
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
const GEOMETRY_TYPES: readonly WKBHeader['geometryType'][] = [
|
|
767
|
-
'Point',
|
|
768
|
-
'LineString',
|
|
769
|
-
'Polygon',
|
|
770
|
-
'MultiPoint',
|
|
771
|
-
'MultiLineString',
|
|
772
|
-
'MultiPolygon',
|
|
773
|
-
'GeometryCollection'
|
|
774
|
-
];
|
|
775
|
-
const DIMENSIONS: readonly GeoArrowDimension[] = ['xy', 'xyz', 'xym', 'xyzm'];
|
|
776
|
-
|
|
777
|
-
function getGeometryFamilyIndex(type: WKBHeader['geometryType']): number {
|
|
778
|
-
return GEOMETRY_TYPES.indexOf(type);
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
function getDimensionIndex(dimension: GeoArrowDimension): number {
|
|
782
|
-
return DIMENSIONS.indexOf(dimension);
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
function getGeometryTypeIdFromIndices(family: number, dimension: number): number {
|
|
786
|
-
return family * 4 + dimension + 1;
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
function getGeometryTypeFromId(typeId: number): WKBHeader['geometryType'] {
|
|
790
|
-
return GEOMETRY_TYPES[Math.floor((typeId - 1) / 4)];
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
function getConcreteGeometryTypeFromId(
|
|
794
|
-
typeId: number
|
|
795
|
-
): Exclude<WKBHeader['geometryType'], 'GeometryCollection'> {
|
|
796
|
-
const type = getGeometryTypeFromId(typeId);
|
|
797
|
-
if (type === 'GeometryCollection')
|
|
798
|
-
throw new Error('GeometryCollection requires collection storage');
|
|
799
|
-
return type;
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
function getDimensionFromId(typeId: number): GeoArrowDimension {
|
|
803
|
-
return DIMENSIONS[(typeId - 1) % 4];
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
function resolveDecodeDimension(
|
|
807
|
-
requested: DecodeGeoArrowWKBOptions['dimension'],
|
|
808
|
-
declared: GeoArrowDimension,
|
|
809
|
-
inferred: GeoArrowDimension
|
|
810
|
-
): GeoArrowDimension {
|
|
811
|
-
if (!requested || requested === 'infer') return inferred;
|
|
812
|
-
return requested === 'preserve' ? declared : requested;
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
function resolveDecodeEncoding(
|
|
816
|
-
requested: DecodeGeoArrowWKBOptions['encoding'],
|
|
817
|
-
families: ReadonlySet<number>
|
|
818
|
-
): GeoArrowBuilderEncoding | 'geoarrow.geometry' | 'geoarrow.geometrycollection' {
|
|
819
|
-
if (requested && requested !== 'native') return requested;
|
|
820
|
-
if (families.size !== 1) return 'geoarrow.geometry';
|
|
821
|
-
const type = GEOMETRY_TYPES[[...families][0]];
|
|
822
|
-
return type === 'GeometryCollection'
|
|
823
|
-
? 'geoarrow.geometrycollection'
|
|
824
|
-
: encodingFromGeometryType(type);
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
function validateDecodeEncoding(
|
|
828
|
-
encoding: GeoArrowBuilderEncoding | 'geoarrow.geometry' | 'geoarrow.geometrycollection',
|
|
829
|
-
families: ReadonlySet<number>
|
|
830
|
-
): void {
|
|
831
|
-
if (encoding === 'geoarrow.geometry') return;
|
|
832
|
-
if (encoding === 'geoarrow.geometrycollection') {
|
|
833
|
-
const collectionFamily = getGeometryFamilyIndex('GeometryCollection');
|
|
834
|
-
if ([...families].some(family => family !== collectionFamily)) {
|
|
835
|
-
throw new Error('Rows cannot be represented as geoarrow.geometrycollection');
|
|
836
|
-
}
|
|
837
|
-
return;
|
|
838
|
-
}
|
|
839
|
-
const targetType = geometryTypeFromEncoding(encoding);
|
|
840
|
-
for (const family of families) {
|
|
841
|
-
const sourceType = GEOMETRY_TYPES[family];
|
|
842
|
-
const promotable =
|
|
843
|
-
sourceType === targetType ||
|
|
844
|
-
(sourceType === 'Point' && targetType === 'MultiPoint') ||
|
|
845
|
-
(sourceType === 'LineString' && targetType === 'MultiLineString') ||
|
|
846
|
-
(sourceType === 'Polygon' && targetType === 'MultiPolygon');
|
|
847
|
-
if (!promotable) throw new Error(`Rows cannot be represented as ${encoding}`);
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
function geometryTypeFromEncoding(
|
|
852
|
-
encoding: GeoArrowBuilderEncoding
|
|
853
|
-
): Exclude<WKBHeader['geometryType'], 'GeometryCollection'> {
|
|
854
|
-
const type = GEOMETRY_TYPES.find(candidate => `geoarrow.${candidate.toLowerCase()}` === encoding);
|
|
855
|
-
if (!type || type === 'GeometryCollection')
|
|
856
|
-
throw new Error(`Unsupported target encoding ${encoding}`);
|
|
857
|
-
return type;
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
/** Encodes a native GeoArrow column as variable-width WKB bytes. */
|
|
861
|
-
export function encodeGeoArrowWKB(column: GeoArrowColumn): GeoArrowColumn {
|
|
862
|
-
if (column.encoding === 'geoarrow.wkb') return column;
|
|
863
|
-
return copyMetadata(column, {
|
|
864
|
-
encoding: 'geoarrow.wkb',
|
|
865
|
-
dimension: column.dimension,
|
|
866
|
-
coordinateLayout: null,
|
|
867
|
-
chunks: column.chunks.map(chunk => encodeWKBChunk(column, chunk))
|
|
868
|
-
});
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
function encodeWKBChunk(
|
|
872
|
-
column: GeoArrowColumn,
|
|
873
|
-
chunk: import('./types').GeoArrowArray
|
|
874
|
-
): GeoArrowSerialized {
|
|
875
|
-
const offsets = new Int32Array(chunk.length + 1);
|
|
876
|
-
const validity = new Uint8Array(Math.ceil(chunk.length / 8));
|
|
877
|
-
let nullCount = 0;
|
|
878
|
-
for (let rowIndex = 0; rowIndex < chunk.length; rowIndex++) {
|
|
879
|
-
let byteLength = 0;
|
|
880
|
-
if (isPhysicalGeometryRowValid(chunk, rowIndex, column.encoding)) {
|
|
881
|
-
const dimension = getPhysicalGeometryDimension(
|
|
882
|
-
chunk,
|
|
883
|
-
rowIndex,
|
|
884
|
-
column.encoding,
|
|
885
|
-
column.dimension
|
|
886
|
-
);
|
|
887
|
-
const builder = new WKBBuilder({mode: 'measure', dimension});
|
|
888
|
-
writePhysicalGeometry(builder, chunk, rowIndex, column.encoding, dimension);
|
|
889
|
-
byteLength = builder.finishGeometry();
|
|
890
|
-
validity[rowIndex >> 3] |= 1 << (rowIndex & 7);
|
|
891
|
-
} else {
|
|
892
|
-
nullCount++;
|
|
893
|
-
}
|
|
894
|
-
const nextOffset = offsets[rowIndex] + byteLength;
|
|
895
|
-
if (nextOffset > 0x7fffffff) throw new Error('WKB geometry chunk exceeds Int32 offsets');
|
|
896
|
-
offsets[rowIndex + 1] = nextOffset;
|
|
897
|
-
}
|
|
898
|
-
const values = new Uint8Array(offsets[offsets.length - 1]);
|
|
899
|
-
for (let rowIndex = 0; rowIndex < chunk.length; rowIndex++) {
|
|
900
|
-
if (!isPhysicalGeometryRowValid(chunk, rowIndex, column.encoding)) continue;
|
|
901
|
-
const dimension = getPhysicalGeometryDimension(
|
|
902
|
-
chunk,
|
|
903
|
-
rowIndex,
|
|
904
|
-
column.encoding,
|
|
905
|
-
column.dimension
|
|
906
|
-
);
|
|
907
|
-
const builder = new WKBBuilder({
|
|
908
|
-
mode: 'write',
|
|
909
|
-
target: values,
|
|
910
|
-
byteOffset: offsets[rowIndex],
|
|
911
|
-
dimension
|
|
912
|
-
});
|
|
913
|
-
writePhysicalGeometry(builder, chunk, rowIndex, column.encoding, dimension);
|
|
914
|
-
if (offsets[rowIndex] + builder.finishGeometry() !== offsets[rowIndex + 1]) {
|
|
915
|
-
throw new Error('WKB measure and write passes produced different byte lengths');
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
return {
|
|
919
|
-
kind: 'serialized',
|
|
920
|
-
encoding: 'binary',
|
|
921
|
-
length: chunk.length,
|
|
922
|
-
offsets,
|
|
923
|
-
values,
|
|
924
|
-
...(nullCount ? {validity: {values: validity}} : {})
|
|
925
|
-
};
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
function isPhysicalGeometryRowValid(
|
|
929
|
-
array: import('./types').GeoArrowArray,
|
|
930
|
-
rowIndex: number,
|
|
931
|
-
encoding: import('./types').GeoArrowEncoding
|
|
932
|
-
): boolean {
|
|
933
|
-
if (!isGeoArrowValueValid(array.validity, rowIndex)) return false;
|
|
934
|
-
if (encoding !== 'geoarrow.geometry' || array.kind !== 'dense-union') return true;
|
|
935
|
-
const physical = (array.offset || 0) + rowIndex;
|
|
936
|
-
const child = array.children.find(candidate => candidate.typeId === array.typeIds[physical]);
|
|
937
|
-
const childIndex = array.valueOffsets[physical];
|
|
938
|
-
return Boolean(
|
|
939
|
-
child &&
|
|
940
|
-
childIndex >= 0 &&
|
|
941
|
-
childIndex < child.data.length &&
|
|
942
|
-
isGeoArrowValueValid(child.data.validity, childIndex)
|
|
943
|
-
);
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
/** Decodes a GeoArrow WKT column into native physical geometry buffers. */
|
|
947
|
-
export function decodeGeoArrowWKT(column: GeoArrowColumn): GeoArrowColumn {
|
|
948
|
-
if (column.encoding !== 'geoarrow.wkt') throw new Error('Expected a geoarrow.wkt column');
|
|
949
|
-
const rows = normalizeRowsToDimension(
|
|
950
|
-
decodeSerializedRows(column, bytes => parseWKT(textDecoder.decode(bytes))),
|
|
951
|
-
column.dimension
|
|
952
|
-
);
|
|
953
|
-
return copyMetadata(
|
|
954
|
-
column,
|
|
955
|
-
makeGeoArrowColumnFromGeometryRows(rows, {dimension: column.dimension})
|
|
956
|
-
);
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
/** Encodes a native GeoArrow column as variable-width UTF-8 WKT. */
|
|
960
|
-
export function encodeGeoArrowWKT(column: GeoArrowColumn): GeoArrowColumn {
|
|
961
|
-
if (column.encoding === 'geoarrow.wkt') return column;
|
|
962
|
-
const values: Array<Uint8Array | null> = [];
|
|
963
|
-
for (const chunk of column.chunks) {
|
|
964
|
-
for (let rowIndex = 0; rowIndex < chunk.length; rowIndex++) {
|
|
965
|
-
const row = isGeoArrowValueValid(chunk.validity, rowIndex)
|
|
966
|
-
? materializeGeometryRow(chunk, rowIndex, column.encoding)
|
|
967
|
-
: null;
|
|
968
|
-
values.push(row ? textEncoder.encode(formatWKT(row, column.dimension)) : null);
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
return copyMetadata(column, makeSerializedColumn(values, 'geoarrow.wkt', column.dimension));
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
function writePhysicalGeometry(
|
|
975
|
-
builder: WKBBuilder,
|
|
976
|
-
array: import('./types').GeoArrowArray,
|
|
977
|
-
rowIndex: number,
|
|
978
|
-
encoding: import('./types').GeoArrowEncoding,
|
|
979
|
-
dimension: GeoArrowDimension
|
|
980
|
-
): void {
|
|
981
|
-
const depth = getEncodingDepth(encoding);
|
|
982
|
-
if (encoding === 'geoarrow.geometry' && array.kind === 'dense-union') {
|
|
983
|
-
const physical = (array.offset || 0) + rowIndex;
|
|
984
|
-
const typeId = array.typeIds[physical];
|
|
985
|
-
const child = array.children.find(candidate => candidate.typeId === typeId);
|
|
986
|
-
if (!child) throw new Error('Dense-union row references an unknown child');
|
|
987
|
-
const childDimension = child.dimension || dimension;
|
|
988
|
-
builder.withDimension(childDimension, () =>
|
|
989
|
-
writePhysicalGeometry(
|
|
990
|
-
builder,
|
|
991
|
-
child.data,
|
|
992
|
-
array.valueOffsets[physical],
|
|
993
|
-
child.encoding || encodingFromName(child.name),
|
|
994
|
-
childDimension
|
|
995
|
-
)
|
|
996
|
-
);
|
|
997
|
-
return;
|
|
998
|
-
}
|
|
999
|
-
if (encoding === 'geoarrow.geometrycollection' && array.kind === 'list') {
|
|
1000
|
-
const [first, last] = getListRange(array, rowIndex);
|
|
1001
|
-
builder.beginGeometry('GeometryCollection', last - first);
|
|
1002
|
-
if (array.child.kind !== 'dense-union')
|
|
1003
|
-
throw new Error('GeometryCollection requires dense union child');
|
|
1004
|
-
const union = array.child;
|
|
1005
|
-
for (let index = first; index < last; index++) {
|
|
1006
|
-
const physical = (union.offset || 0) + index;
|
|
1007
|
-
const child = union.children.find(candidate => candidate.typeId === union.typeIds[physical]);
|
|
1008
|
-
if (child) {
|
|
1009
|
-
const childDimension = child.dimension || dimension;
|
|
1010
|
-
builder.withDimension(childDimension, () =>
|
|
1011
|
-
writePhysicalGeometry(
|
|
1012
|
-
builder,
|
|
1013
|
-
child.data,
|
|
1014
|
-
union.valueOffsets[physical],
|
|
1015
|
-
child.encoding || encodingFromName(child.name),
|
|
1016
|
-
childDimension
|
|
1017
|
-
)
|
|
1018
|
-
);
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
return;
|
|
1022
|
-
}
|
|
1023
|
-
if (array.kind !== 'list' && depth > 0) throw new Error(`Invalid ${encoding} storage`);
|
|
1024
|
-
const writeCoordinate = (leaf: import('./types').GeoArrowArray, index: number): void => {
|
|
1025
|
-
const coordinate = readPhysicalCoordinate(leaf, index);
|
|
1026
|
-
if (!coordinate) throw new Error('Invalid GeoArrow coordinate storage');
|
|
1027
|
-
if (dimension === 'xym')
|
|
1028
|
-
builder.writeCoordinate(coordinate[0], coordinate[1], undefined, coordinate[2]);
|
|
1029
|
-
else if (dimension === 'xyzm')
|
|
1030
|
-
builder.writeCoordinate(coordinate[0], coordinate[1], coordinate[2], coordinate[3]);
|
|
1031
|
-
else builder.writeCoordinate(coordinate[0], coordinate[1], coordinate[2]);
|
|
1032
|
-
};
|
|
1033
|
-
const writeSequence = (
|
|
1034
|
-
leaf: import('./types').GeoArrowArray,
|
|
1035
|
-
first: number,
|
|
1036
|
-
last: number
|
|
1037
|
-
): void => {
|
|
1038
|
-
for (let index = first; index < last; index++) writeCoordinate(leaf, index);
|
|
1039
|
-
};
|
|
1040
|
-
if (encoding === 'geoarrow.point') {
|
|
1041
|
-
builder.beginPoint();
|
|
1042
|
-
writeCoordinate(array, rowIndex);
|
|
1043
|
-
} else if (encoding === 'geoarrow.linestring' || encoding === 'geoarrow.multipoint') {
|
|
1044
|
-
const [first, last] = getListRange(array as import('./types').GeoArrowList, rowIndex);
|
|
1045
|
-
if (encoding === 'geoarrow.linestring') {
|
|
1046
|
-
builder.beginLineString(last - first);
|
|
1047
|
-
writeSequence((array as import('./types').GeoArrowList).child, first, last);
|
|
1048
|
-
} else {
|
|
1049
|
-
builder.beginMultiPoint(last - first);
|
|
1050
|
-
const leaf = (array as import('./types').GeoArrowList).child;
|
|
1051
|
-
for (let index = first; index < last; index++) {
|
|
1052
|
-
builder.beginPoint();
|
|
1053
|
-
writeCoordinate(leaf, index);
|
|
1054
|
-
}
|
|
1055
|
-
}
|
|
1056
|
-
} else if (encoding === 'geoarrow.polygon' || encoding === 'geoarrow.multilinestring') {
|
|
1057
|
-
const [first, last] = getListRange(array as import('./types').GeoArrowList, rowIndex);
|
|
1058
|
-
const parts = (array as import('./types').GeoArrowList).child;
|
|
1059
|
-
if (encoding === 'geoarrow.polygon') builder.beginPolygon(last - first);
|
|
1060
|
-
else builder.beginMultiLineString(last - first);
|
|
1061
|
-
for (let partIndex = first; partIndex < last; partIndex++) {
|
|
1062
|
-
const [ringFirst, ringLast] = getListRange(
|
|
1063
|
-
parts as import('./types').GeoArrowList,
|
|
1064
|
-
partIndex
|
|
1065
|
-
);
|
|
1066
|
-
const leaf = (parts as import('./types').GeoArrowList).child;
|
|
1067
|
-
if (encoding === 'geoarrow.polygon') builder.beginLinearRing(ringLast - ringFirst);
|
|
1068
|
-
else builder.beginLineString(ringLast - ringFirst);
|
|
1069
|
-
writeSequence(leaf, ringFirst, ringLast);
|
|
1070
|
-
}
|
|
1071
|
-
} else if (encoding === 'geoarrow.multipolygon') {
|
|
1072
|
-
const [first, last] = getListRange(array as import('./types').GeoArrowList, rowIndex);
|
|
1073
|
-
const polygons = (array as import('./types').GeoArrowList).child;
|
|
1074
|
-
builder.beginMultiPolygon(last - first);
|
|
1075
|
-
for (let polygonIndex = first; polygonIndex < last; polygonIndex++) {
|
|
1076
|
-
const [partFirst, partLast] = getListRange(
|
|
1077
|
-
polygons as import('./types').GeoArrowList,
|
|
1078
|
-
polygonIndex
|
|
1079
|
-
);
|
|
1080
|
-
const parts = (polygons as import('./types').GeoArrowList).child;
|
|
1081
|
-
builder.beginPolygon(partLast - partFirst);
|
|
1082
|
-
for (let partIndex = partFirst; partIndex < partLast; partIndex++) {
|
|
1083
|
-
const [ringFirst, ringLast] = getListRange(
|
|
1084
|
-
parts as import('./types').GeoArrowList,
|
|
1085
|
-
partIndex
|
|
1086
|
-
);
|
|
1087
|
-
builder.beginLinearRing(ringLast - ringFirst);
|
|
1088
|
-
writeSequence((parts as import('./types').GeoArrowList).child, ringFirst, ringLast);
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
function getPhysicalGeometryDimension(
|
|
1095
|
-
array: import('./types').GeoArrowArray,
|
|
1096
|
-
rowIndex: number,
|
|
1097
|
-
encoding: import('./types').GeoArrowEncoding,
|
|
1098
|
-
dimension: GeoArrowDimension
|
|
1099
|
-
): GeoArrowDimension {
|
|
1100
|
-
if (encoding !== 'geoarrow.geometry' || array.kind !== 'dense-union') return dimension;
|
|
1101
|
-
const physical = (array.offset || 0) + rowIndex;
|
|
1102
|
-
const child = array.children.find(candidate => candidate.typeId === array.typeIds[physical]);
|
|
1103
|
-
return child?.dimension || dimension;
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
function readPhysicalCoordinate(
|
|
1107
|
-
array: import('./types').GeoArrowArray,
|
|
1108
|
-
index: number
|
|
1109
|
-
): number[] | null {
|
|
1110
|
-
if (array.kind === 'fixed-size-list' && array.child.kind === 'primitive') {
|
|
1111
|
-
const logical = (array.offset || 0) + index;
|
|
1112
|
-
const values: number[] = [];
|
|
1113
|
-
for (let component = 0; component < array.size; component++)
|
|
1114
|
-
values.push(
|
|
1115
|
-
Number(
|
|
1116
|
-
array.child.values[
|
|
1117
|
-
(array.child.offset || 0) +
|
|
1118
|
-
(logical * array.size + component) * (array.child.stride || 1)
|
|
1119
|
-
]
|
|
1120
|
-
)
|
|
1121
|
-
);
|
|
1122
|
-
return values;
|
|
1123
|
-
}
|
|
1124
|
-
if (array.kind === 'struct') {
|
|
1125
|
-
const logical = (array.offset || 0) + index;
|
|
1126
|
-
return ['x', 'y', 'z', 'm'].flatMap(name => {
|
|
1127
|
-
const child = array.children[name];
|
|
1128
|
-
return child?.kind === 'primitive'
|
|
1129
|
-
? [Number(child.values[(child.offset || 0) + logical * (child.stride || 1)])]
|
|
1130
|
-
: [];
|
|
1131
|
-
});
|
|
1132
|
-
}
|
|
1133
|
-
return null;
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
function getListRange(list: import('./types').GeoArrowList, index: number): [number, number] {
|
|
1137
|
-
const offset = (list.offset || 0) + index;
|
|
1138
|
-
const base =
|
|
1139
|
-
typeof (list.offsetBase ?? 0) === 'bigint'
|
|
1140
|
-
? Number(list.offsetBase)
|
|
1141
|
-
: Number(list.offsetBase ?? 0);
|
|
1142
|
-
return [
|
|
1143
|
-
getGeoArrowOffset(list.offsets, offset) - base,
|
|
1144
|
-
getGeoArrowOffset(list.offsets, offset + 1) - base
|
|
1145
|
-
];
|
|
1146
|
-
}
|
|
1147
|
-
|
|
1148
|
-
function getEncodingDepth(encoding: import('./types').GeoArrowEncoding): number {
|
|
1149
|
-
return encoding === 'geoarrow.point'
|
|
1150
|
-
? 0
|
|
1151
|
-
: encoding === 'geoarrow.linestring' || encoding === 'geoarrow.multipoint'
|
|
1152
|
-
? 1
|
|
1153
|
-
: encoding === 'geoarrow.polygon' || encoding === 'geoarrow.multilinestring'
|
|
1154
|
-
? 2
|
|
1155
|
-
: 3;
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
function encodingFromName(name: string): import('./types').GeoArrowEncoding {
|
|
1159
|
-
return `geoarrow.${name.toLowerCase()}` as import('./types').GeoArrowEncoding;
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
function normalizeRowsToDimension(
|
|
1163
|
-
rows: readonly (GeoArrowGeometryValue | null)[],
|
|
1164
|
-
dimension: GeoArrowDimension
|
|
1165
|
-
): Array<GeoArrowGeometryValue | null> {
|
|
1166
|
-
const size = getGeoArrowDimensionSize(dimension);
|
|
1167
|
-
const normalizeGeometry = (geometry: GeoArrowGeometryValue): GeoArrowGeometryValue => {
|
|
1168
|
-
if (geometry.type === 'GeometryCollection') {
|
|
1169
|
-
return {...geometry, geometries: geometry.geometries.map(normalizeGeometry)};
|
|
1170
|
-
}
|
|
1171
|
-
return {
|
|
1172
|
-
...geometry,
|
|
1173
|
-
coordinates: normalizeCoordinateNesting(geometry.coordinates, size)
|
|
1174
|
-
} as GeoArrowGeometryValue;
|
|
1175
|
-
};
|
|
1176
|
-
return rows.map(row => (row ? normalizeGeometry(row) : null));
|
|
1177
|
-
}
|
|
1178
|
-
|
|
1179
|
-
function normalizeCoordinateNesting(value: readonly unknown[], size: number): unknown {
|
|
1180
|
-
if (value.length === 0) return [];
|
|
1181
|
-
if (typeof value[0] === 'number') {
|
|
1182
|
-
const coordinate = (value as readonly number[]).slice(0, size);
|
|
1183
|
-
while (coordinate.length < size) coordinate.push(0);
|
|
1184
|
-
return coordinate;
|
|
1185
|
-
}
|
|
1186
|
-
return value.map(child => normalizeCoordinateNesting(child as readonly unknown[], size));
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
|
-
function decodeSerializedRows(
|
|
1190
|
-
column: GeoArrowColumn,
|
|
1191
|
-
decoder: (bytes: Uint8Array) => GeoArrowGeometryValue
|
|
1192
|
-
): Array<GeoArrowGeometryValue | null> {
|
|
1193
|
-
const rows: Array<GeoArrowGeometryValue | null> = [];
|
|
1194
|
-
for (const chunk of column.chunks) {
|
|
1195
|
-
if (chunk.kind !== 'serialized') throw new Error('Serialized column contains native storage');
|
|
1196
|
-
for (let rowIndex = 0; rowIndex < chunk.length; rowIndex++) {
|
|
1197
|
-
if (!isGeoArrowValueValid(chunk.validity, rowIndex)) {
|
|
1198
|
-
rows.push(null);
|
|
1199
|
-
continue;
|
|
1200
|
-
}
|
|
1201
|
-
rows.push(decoder(getSerializedBytes(chunk, rowIndex)));
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
return rows;
|
|
1205
|
-
}
|
|
1206
|
-
|
|
1207
|
-
function getSerializedBytes(array: GeoArrowSerialized, rowIndex: number): Uint8Array {
|
|
1208
|
-
if (array.views) {
|
|
1209
|
-
const viewIndex = ((array.offset || 0) + rowIndex) * 4;
|
|
1210
|
-
const length = array.views[viewIndex];
|
|
1211
|
-
// Arrow BinaryView stores short values inline in the 16-byte view record.
|
|
1212
|
-
if (length <= 12) {
|
|
1213
|
-
const byteOffset = array.views.byteOffset + viewIndex * 4 + 4;
|
|
1214
|
-
return new Uint8Array(array.views.buffer, byteOffset, length);
|
|
1215
|
-
}
|
|
1216
|
-
const bufferIndex = array.views[viewIndex + 2];
|
|
1217
|
-
const byteOffset = array.views[viewIndex + 3];
|
|
1218
|
-
const data = array.dataBuffers?.[bufferIndex];
|
|
1219
|
-
if (!data) throw new Error(`Serialized view references missing data buffer ${bufferIndex}`);
|
|
1220
|
-
return data.subarray(byteOffset, byteOffset + length);
|
|
1221
|
-
}
|
|
1222
|
-
const offsetIndex = (array.offset || 0) + rowIndex;
|
|
1223
|
-
const baseValue = array.offsetBase ?? 0;
|
|
1224
|
-
const base = typeof baseValue === 'bigint' ? Number(baseValue) : baseValue;
|
|
1225
|
-
const first = getGeoArrowOffset(array.offsets, offsetIndex) - base;
|
|
1226
|
-
const last = getGeoArrowOffset(array.offsets, offsetIndex + 1) - base;
|
|
1227
|
-
return array.values.subarray(first, last);
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
function makeSerializedColumn(
|
|
1231
|
-
rows: readonly (Uint8Array | null)[],
|
|
1232
|
-
encoding: 'geoarrow.wkb' | 'geoarrow.wkt',
|
|
1233
|
-
dimension: GeoArrowDimension
|
|
1234
|
-
): GeoArrowColumn {
|
|
1235
|
-
let byteLength = 0;
|
|
1236
|
-
for (const row of rows) byteLength += row?.byteLength || 0;
|
|
1237
|
-
const values = new Uint8Array(byteLength);
|
|
1238
|
-
const offsets = new Int32Array(rows.length + 1);
|
|
1239
|
-
const validity = new Uint8Array(Math.ceil(rows.length / 8));
|
|
1240
|
-
let byteOffset = 0;
|
|
1241
|
-
for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
|
|
1242
|
-
const row = rows[rowIndex];
|
|
1243
|
-
if (row) {
|
|
1244
|
-
values.set(row, byteOffset);
|
|
1245
|
-
byteOffset += row.byteLength;
|
|
1246
|
-
validity[rowIndex >> 3] |= 1 << (rowIndex & 7);
|
|
1247
|
-
}
|
|
1248
|
-
offsets[rowIndex + 1] = byteOffset;
|
|
1249
|
-
}
|
|
1250
|
-
const chunk: GeoArrowSerialized = {
|
|
1251
|
-
kind: 'serialized',
|
|
1252
|
-
encoding: encoding === 'geoarrow.wkb' ? 'binary' : 'utf8',
|
|
1253
|
-
length: rows.length,
|
|
1254
|
-
offsets,
|
|
1255
|
-
values,
|
|
1256
|
-
validity: {values: validity}
|
|
1257
|
-
};
|
|
1258
|
-
return {encoding, dimension, coordinateLayout: null, chunks: [chunk]};
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
function copyMetadata(source: GeoArrowColumn, target: GeoArrowColumn): GeoArrowColumn {
|
|
1262
|
-
return {
|
|
1263
|
-
...target,
|
|
1264
|
-
spatialReference: source.spatialReference,
|
|
1265
|
-
edges: source.edges,
|
|
1266
|
-
metadata: source.metadata
|
|
1267
|
-
};
|
|
1268
|
-
}
|