Millwork
    Preparing search index...

    Module @millwork-ts/geo

    @millwork-ts/geo

    Millwork codecs for WKT with betterknown and for geohash with ngeohash.

    Install the peer of each codec that you use.

    pnpm add @millwork-ts/geo @millwork-ts/core betterknown ngeohash
    

    Entry points

    Entry Codecs Peers
    @millwork-ts/geo wkt, geohash, codecs betterknown, ngeohash
    @millwork-ts/geo/wkt wkt betterknown
    @millwork-ts/geo/geohash geohash ngeohash

    The root entry loads both peers. If you use only one codec, import its entry.

    Codec Value Raw
    wkt a frozen GeoJSON geometry "POINT(-79.38 43.65)"
    geohash a frozen { lat, lng, error, precision } "dpz83d"
    • The codec writes WKT in the betterknown form, with a space after the keyword, such as "POINT (1 2)". It reads both "POINT(1 2)" and "POINT (1 2)".
    • The codec reads lower-case keywords, such as "point(1 2)", and writes upper case.
    • The codec does not read EWKT, such as "SRID=4326;POINT(1 2)". GeoJSON has no SRID, so a write would remove it.
    • There is no WKB codec. PostGIS hex WKB is EWKB with an SRID, so a write would remove the SRID.
    • The codec does not read EMPTY geometries, such as "POINT EMPTY". They are bad input, because betterknown gives no geometry for them.
    • betterknown needs no Buffer, so the entry loads in a browser.
    • lat and lng are the center of the cell. error is the half-size of the cell in degrees. precision is the length of the hash.
    • The codec reads upper case and writes lower case.
    Codec Option Type Use
    geohash precision number The length of the hash that the codec writes. The default is the precision of the value.
    • wkt: equals compares the WKT form.
    • geohash: equals compares the point and the precision. "dpz83d" equals "DPZ83D". "dpz83" is a different cell.

    Register the codecs before the store calls transformations(), because transformations() reads the registry when it runs. See the @millwork-ts/warp-drive README.

    import { codecs } from '@millwork-ts/geo'
    import { registerCodecs, valueField } from '@millwork-ts/warp-drive'
    import { withDefaults } from '@warp-drive/core/reactive'

    registerCodecs(codecs)

    export const StoreSchema = withDefaults({
    type: 'store',
    fields: [valueField('area', 'wkt'), valueField('cell', 'geohash', { precision: 7 })],
    })
    GeohashOptions
    GeohashValue
    codecs
    geohash
    wkt