Work on polygon benchmark

master
Sander Vocke 6 years ago
parent 4ce9f56ecb
commit dc14e652f7
  1. 1
      README.md
  2. 1
      package.json
  3. 20
      public/runtime-config.js
  4. 41
      src/database.js
  5. 36
      yarn.lock

@ -2,6 +2,7 @@
- which-polygon - which-polygon
- supercluster - supercluster
- @spatial/points-within-polygon
# Create React App parts # Create React App parts

@ -14,6 +14,7 @@
"@testing-library/jest-dom": "^4.2.4", "@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2", "@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2", "@testing-library/user-event": "^7.1.2",
"@turf/points-within-polygon": "^5.1.5",
"alasql": "^0.5.4", "alasql": "^0.5.4",
"console": "^0.7.2", "console": "^0.7.2",
"date-fns": "^2.0.0", "date-fns": "^2.0.0",

@ -1,18 +1,18 @@
// Away config // Away config
// window['runtimeConfig'] = {
// digikamDbUrl: "https://sandervocke-nas.duckdns.org/digikam-fatclient-data/digikam4.db",
// photosUrl: "https://sandervocke-nas.duckdns.org/digikam-fatclient-data/photos",
// thumbsUrl: "https://sandervocke-nas.duckdns.org/digikam-fatclient-data/thumbs",
// }
// Home config
window['runtimeConfig'] = { window['runtimeConfig'] = {
digikamDbUrl: "https://192.168.1.101/digikam-fatclient-data/digikam4.db", digikamDbUrl: "https://sandervocke-nas.duckdns.org/digikam-fatclient-data/digikam4.db",
photosUrl: "https://192.168.1.101/digikam-fatclient-data/photos", photosUrl: "https://sandervocke-nas.duckdns.org/digikam-fatclient-data/photos",
thumbsUrl: "https://192.168.1.101/digikam-fatclient-data/thumbs", thumbsUrl: "https://sandervocke-nas.duckdns.org/digikam-fatclient-data/thumbs",
} }
// Home config
// window['runtimeConfig'] = {
// digikamDbUrl: "https://192.168.1.101/digikam-fatclient-data/digikam4.db",
// photosUrl: "https://192.168.1.101/digikam-fatclient-data/photos",
// thumbsUrl: "https://192.168.1.101/digikam-fatclient-data/thumbs",
// }
// Production config // Production config
// window['runtimeConfig'] = { // window['runtimeConfig'] = {
// digikamDbUrl: "/digikam-fatclient-data/digikam4.db", // digikamDbUrl: "/digikam-fatclient-data/digikam4.db",

@ -3,6 +3,8 @@ import NodeEnvironment from 'jest-environment-node';
import { add_geo_area_to_store, get_geo_area_from_store } from './geo_store.js'; import { add_geo_area_to_store, get_geo_area_from_store } from './geo_store.js';
import pointsWithinPolygon from '@turf/points-within-polygon';
export async function sqljs_async_queries(sqljs_object, queries) { export async function sqljs_async_queries(sqljs_object, queries) {
//var t0 = performance.now(); //var t0 = performance.now();
for (let i = 0; i < (queries.length - 1); i++) { for (let i = 0; i < (queries.length - 1); i++) {
@ -105,6 +107,44 @@ export async function add_full_tag_info(db) {
return db; return db;
} }
function polygons_benchmark(database) {
var img_query = "SELECT Images.id, ImagePositions.latitudeNumber, ImagePositions.longitudeNumber FROM Images "
+ "LEFT JOIN ImagePositions ON ImagePositions.imageid=Images.id GROUP BY Images.id;";
sqljs_async_queries(database, [img_query]).then(res => {
fetch("https://nominatim.openstreetmap.org/search?polygon_geojson=1&polygon_threshold=0.001&format=json&limit=5&q=Australia")
.then(res => res.json())
.then(jsonres => {
var geojson;
var points = [];
console.log("Nominatim geo answer:", jsonres);
if (Array.isArray(jsonres) && jsonres.length > 0) {
geojson = jsonres[0].geojson;
}
if (res && Array.isArray(res) && res.length > 0) {
var cols = res[0].columns;
var data = res[0].values;
data.forEach(row => {
points.push([row[cols.indexOf("longitudeNumber")], row[cols.indexOf("latitudeNumber")]]);
});
}
console.log("Points: ", points);
console.log("GEOJSON: ", geojson);
console.time("points within polygon");
var found = pointsWithinPolygon(points, geojson);
console.timeEnd("points within polygon");
console.log("PointsWithinPolygon: ", found);
});
})
.catch(err => { throw err; });
}
export function ProvideDB(props) { export function ProvideDB(props) {
const { children, db_url } = props; const { children, db_url } = props;
const [db, setDb] = useState(null); const [db, setDb] = useState(null);
@ -116,6 +156,7 @@ export function ProvideDB(props) {
add_full_tag_info(db).then((newdb) => { add_full_tag_info(db).then((newdb) => {
db.create_function("REGEXP", regexp_match); db.create_function("REGEXP", regexp_match);
db.create_function("IS_IN_GEO", is_in_geo_polygon_from_store); db.create_function("IS_IN_GEO", is_in_geo_polygon_from_store);
polygons_benchmark(db);
setError(false); setError(false);
setDb(newdb); setDb(newdb);
}) })

@ -1508,6 +1508,42 @@
resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-7.2.1.tgz#2ad4e844175a3738cb9e7064be5ea070b8863a1c" resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-7.2.1.tgz#2ad4e844175a3738cb9e7064be5ea070b8863a1c"
integrity sha512-oZ0Ib5I4Z2pUEcoo95cT1cr6slco9WY7yiPpG+RGNkj8YcYgJnM7pXmYmorNOReh8MIGcKSqXyeGjxnr8YiZbA== integrity sha512-oZ0Ib5I4Z2pUEcoo95cT1cr6slco9WY7yiPpG+RGNkj8YcYgJnM7pXmYmorNOReh8MIGcKSqXyeGjxnr8YiZbA==
"@turf/boolean-point-in-polygon@^5.1.5":
version "5.1.5"
resolved "https://registry.yarnpkg.com/@turf/boolean-point-in-polygon/-/boolean-point-in-polygon-5.1.5.tgz#f01cc194d1e030a548bfda981cba43cfd62941b7"
integrity sha1-8BzBlNHgMKVIv9qYHLpDz9YpQbc=
dependencies:
"@turf/helpers" "^5.1.5"
"@turf/invariant" "^5.1.5"
"@turf/helpers@^5.1.5":
version "5.1.5"
resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-5.1.5.tgz#153405227ab933d004a5bb9641a9ed999fcbe0cf"
integrity sha1-FTQFInq5M9AEpbuWQantmZ/L4M8=
"@turf/invariant@^5.1.5":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@turf/invariant/-/invariant-5.2.0.tgz#f0150ff7290b38577b73d088b7932c1ee0aa90a7"
integrity sha1-8BUP9ykLOFd7c9CIt5MsHuCqkKc=
dependencies:
"@turf/helpers" "^5.1.5"
"@turf/meta@^5.1.5":
version "5.2.0"
resolved "https://registry.yarnpkg.com/@turf/meta/-/meta-5.2.0.tgz#3b1ad485ee0c3b0b1775132a32c384d53e4ba53d"
integrity sha1-OxrUhe4MOwsXdRMqMsOE1T5LpT0=
dependencies:
"@turf/helpers" "^5.1.5"
"@turf/points-within-polygon@^5.1.5":
version "5.1.5"
resolved "https://registry.yarnpkg.com/@turf/points-within-polygon/-/points-within-polygon-5.1.5.tgz#2b855a5df3aada57c2ee820a0754ab94928a2337"
integrity sha1-K4VaXfOq2lfC7oIKB1SrlJKKIzc=
dependencies:
"@turf/boolean-point-in-polygon" "^5.1.5"
"@turf/helpers" "^5.1.5"
"@turf/meta" "^5.1.5"
"@types/babel__core@^7.1.0": "@types/babel__core@^7.1.0":
version "7.1.3" version "7.1.3"
resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.3.tgz#e441ea7df63cd080dfcd02ab199e6d16a735fc30" resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.3.tgz#e441ea7df63cd080dfcd02ab199e6d16a735fc30"

Loading…
Cancel
Save