|
|
|
@ -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 pointsWithinPolygon from '@turf/points-within-polygon'; |
|
|
|
|
|
|
|
|
|
export async function sqljs_async_queries(sqljs_object, queries) { |
|
|
|
|
//var t0 = performance.now();
|
|
|
|
|
for (let i = 0; i < (queries.length - 1); i++) { |
|
|
|
@ -105,6 +107,44 @@ export async function add_full_tag_info(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) { |
|
|
|
|
const { children, db_url } = props; |
|
|
|
|
const [db, setDb] = useState(null); |
|
|
|
@ -116,6 +156,7 @@ export function ProvideDB(props) { |
|
|
|
|
add_full_tag_info(db).then((newdb) => { |
|
|
|
|
db.create_function("REGEXP", regexp_match); |
|
|
|
|
db.create_function("IS_IN_GEO", is_in_geo_polygon_from_store); |
|
|
|
|
polygons_benchmark(db); |
|
|
|
|
setError(false); |
|
|
|
|
setDb(newdb); |
|
|
|
|
}) |
|
|
|
|