Skip to content

Commit

Permalink
update to 0.2.7
Browse files Browse the repository at this point in the history
add spatial union
  • Loading branch information
lixun910 committed Jan 25, 2022
1 parent 295d7e9 commit 0c8bbf2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"build:wasm": "node tools/binary-to-json src/jsgeoda.wasm > src/jsgeoda-wasm.json",
"build:bundle": "webpack",
"build": "npm run build:wasm && npm run build:bundle",
"test-local": "npm run build && cp lib/index.js ~/unfolded/platform/node_modules/@geodacenter/jsgeoda/lib/index.js",
"serve": "http-server",
"start": "npm run build && npm run serve",
"doc": "jsdoc -d docs --configure jsconf.json --readme README.md",
Expand Down Expand Up @@ -33,7 +34,7 @@
"webpack-cli": "^4.7.0",
"worker-loader": "^3.0.8"
},
"version": "0.2.6",
"version": "0.2.7",
"description": "A javascript library for spatial data analysis",
"main": "./lib/index.js",
"repository": {
Expand Down
31 changes: 31 additions & 0 deletions src/geoda-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,37 @@ export default class GeoDaWasm {
return GeoDaWasm.parseVecDouble(counts);
}

/**
* Spatial union
* @param {String} mapUid
* @returns {Object}
*/
spatialUnion(mapUid) {
if (!this.checkMapUid(mapUid)) return null;
const mp = this.wasm.spatial_union(mapUid);
const xx = mp.get_x();
const yy = mp.get_y();
const parts = mp.get_parts();

let i = 0;
let j = 0;
const n = xx.size();
let count = 0;
const multiPolygon = [];

while (i < n) {
if (i === count) {
multiPolygon.push([[]]);
count += parts.get(j);
j += 1;
}
multiPolygon[j - 1][0].push([xx.get(i), yy.get(i)]);
i += 1;
}
const tmpGeojson = { type: 'Feature', geometry: { type: 'MultiPolygon', coordinates: multiPolygon }, properties: {} };
return tmpGeojson;
}

/**
* Get the column names of the geojson map
* @param {String} mapUid A unique map id.
Expand Down
2 changes: 1 addition & 1 deletion src/jsgeoda-wasm.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/jsgeoda.js

Large diffs are not rendered by default.

Binary file modified src/jsgeoda.wasm
Binary file not shown.

0 comments on commit 0c8bbf2

Please sign in to comment.