Created
January 3, 2018 06:29
-
-
Save dg3feiko/292c35121b66fd5c6913cf97e8d3df7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var BoostSpatialIndex = require('boost-geospatial-index'); | |
var _ = require("lodash"); | |
var bsi = new BoostSpatialIndex(); | |
var districts = require("/Users/feikolai/Downloads/hkpolygon.json"); | |
bsi.addBoundingBox('Hong Kong', 113.5932, 22.1022, 114.7104, 22.6188); | |
districts.features.map(f => { | |
bsi.addPolygon(f.properties.CNAME, f.geometry.coordinates[0]) | |
}) | |
for (let i = 0; i < 12; i++) { | |
for (let j = 0; j < 12; j++) { | |
let x = i, y = j; | |
bsi.addPolygon(`District ${i}, ${j}`, [ | |
[x, y], | |
[x, y + 1], | |
[x + 1, y + 1], | |
[x + 1, y] | |
]); | |
} | |
} | |
console.time("query") | |
for (let i = 0; i < 100000; i++) { | |
let x = _.random(113.5932, 114.2879, true); | |
let y = _.random(22.1022, 22.6188, true); | |
let res = bsi.queryPoint(x,y); | |
// console.log(x, y, res) | |
} | |
console.timeEnd("query") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment