Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to store the clustered values into file #134

Open
jpnathannew opened this issue Aug 15, 2019 · 1 comment
Open

How to store the clustered values into file #134

jpnathannew opened this issue Aug 15, 2019 · 1 comment
Labels

Comments

@jpnathannew
Copy link

I have one question after cluster the values I want to store it in file.
after super cluster object initialize I am getting the following response

Supercluster {
  options: { log: true, radius: 60, extent: 512, maxZoom: 16 },
  trees:
   [ KDBush {
       nodeSize: 64,
       points: [Array],
       ids: [Uint16Array],
       coords: [Float32Array] },
     KDBush {
       nodeSize: 64,
       points: [Array],
       ids: [Uint16Array],
       coords: [Float32Array] },
      points:
   [ { type: 'Feature', properties: [Object], geometry: [Object] },
     { type: 'Feature', properties: [Object], geometry: [Object] },
     { type: 'Feature', properties: [Object], geometry: [Object] },
     { type: 'Feature', properties: [Object], geometry: [Object] },
     { type: 'Feature', properties: [Object], geometry: [Object] },
     { type: 'Feature', properties: [Object], geometry: [Object] },
     { type: 'Feature', properties: [Object], geometry: [Object] },
     { type: 'Feature', properties: [Object], geometry: [Object] },
     { type: 'Feature', properties: [Object], geometry: [Object] },
     { type: 'Feature', properties: [Object], geometry: [Object] },
     { type: 'Feature', properties: [Object], geometry: [Object] },
     { type: 'Feature', properties: [Object], geometry: [Object] },
     { type: 'Feature', properties: [Object], geometry: [Object] },
     { type: 'Feature', properties: [Object], geometry: [Object] },
     { type: 'Feature', properties: [Object], geometry: [Object] } ] }

When I convert and write into a file. Format is changing
I am using Node js. Before writing into file i am JSON.stringify
After that stringify I am getting response like this

{
  "options": {
    "log": true,
    "radius": 60,
    "extent": 512,
    "maxZoom": 16
  },
  "trees": [
    {
      "nodeSize": 64,
      "points": [
        {
          "x": 0.24396358761574075,
          "y": 0.38899943574185264,
          "zoom": null,
          "id": 1,
          "parentId": -1,
          "numPoints": 12,
          "properties": null
        },
        {
          "x": 0.7360923611111111,
          "y": 0.4629351025691785,
          "zoom": null,
          "id": 33,
          "parentId": -1,
          "numPoints": 2,
          "properties": null
        }etc

supercluster name and KDBUSH also missed in that.
Please suggest something

@maxgr0
Copy link

maxgr0 commented Aug 22, 2021

let's say r is the result of your JSON.stringify(...), you can just assign all the properties and serialize trees to KDBush instances. The example uses a worker to index all the points and returns a serialized Supercluster.

        const r = await workerPool.exec('index', [features]);
        if (r?.points && r?.trees) {
          r.trees = r.trees.map((t) =>
            Object.assign(
              new KDBush(
                [],
                () => 0,
                () => 0,
              ),
              t,
            ),
          );
          this.clusterIndex = Object.assign(
            new Supercluster({
              ...(r?.options ?? {}),
            }),
            {
              points: r.points,
              trees: r.trees,
            },
          );
          this.logger.log(
            `Successfully loaded ${features.length} features in ${
              (new Date().valueOf() - start) / 1000
            }s`,
          );
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants