-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add more tests to getFeaturesForSketchBBoxes, improve squareSketches,…
… add squares.fgb with txt file showing layout, update squares.json
- Loading branch information
Showing
9 changed files
with
382 additions
and
155 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
|
||
|
||
|
||
squares.fgb polygons are rectangles in increments of 1 degree | ||
|
||
4 @@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@ | ||
@ ---------------- @ @ ---------------- @ | ||
@ ---------------- @ @ ---------------- @ | ||
@ ---------------- @ @ ---------------- @ | ||
@ ---------------- @ @ ---------------- @ | ||
@ ---------------- @ @ ---------------- @ | ||
@ ---------------- @ @ ---------------- @ | ||
@ ---------------- @ @ ---------------- @ | ||
@ ---------------- @ @ ---------------- @ | ||
@ ---------------- @ @ ---------------- @ | ||
3 @@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@ | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
2 wide polygon overlaps top right of 2x2 | ||
2 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@ ---------------- @ +++++++++++++++++@ ---------------- @ | ||
@ ---------------- @ +++++++++++++++++@ ---------------- @ | ||
@ ---------------- @ +++++++++++++++++@ ---------------- @ | ||
@ ---------------- @ +++++++++++++++++@ ---------------- @ | ||
@ ---------------- @ +++++++++++++++++@ ---------------- @ | ||
@ ---------------- @ +++++++++++++++++@ ---------------- @ | ||
@ ---------------- @ +++++++++++++++++@ ---------------- @ | ||
@ ---------------- @ +++++++++++++++++@ ---------------- @ | ||
@ ---------------- @ +++++++++++++++++@ ---------------- @ | ||
1 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | ||
@+++++++++++++++++ @ ---------------- @ @ ---------------- @ | ||
@+++++++++++++++++ @ ---------------- @ @ ---------------- @ | ||
@+++++++++++++++++ @ ---------------- @ @ ---------------- @ | ||
@+++++++++++++++++ @ ---------------- @ @ ---------------- @ | ||
@+++++++++++++++++ @ ---------------- @ @ ---------------- @ | ||
@+++++++++++++++++ @ ---------------- @ @ ---------------- @ | ||
@+++++++++++++++++ @ ---------------- @ @ ---------------- @ | ||
@+++++++++++++++++ @ ---------------- @ @ ---------------- @ | ||
@+++++++++++++++++ @ ---------------- @ @ ---------------- @ | ||
0 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@ | ||
1x1 poly overlaps | ||
bottom left of | ||
2x2 square | ||
|
||
0 1 2 3 4 | ||
|
||
|
119 changes: 90 additions & 29 deletions
119
packages/geoprocessing/src/dataproviders/getFeaturesForSketchBBoxes.test.e2e.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,100 @@ | ||
import { expect, test } from "vitest"; | ||
import { loadFgb } from "./flatgeobuf.js"; | ||
import canonicalize from "../util/canonicalize.js"; | ||
import { deserialize } from "flatgeobuf/lib/mjs/geojson.js"; | ||
|
||
import { readFileSync } from "node:fs"; | ||
import path from "node:path"; | ||
import { isFeatureCollection } from "../index.js"; | ||
import fs from "fs-extra"; | ||
import { | ||
getFeaturesForBBoxes, | ||
getFeaturesForSketchBBoxes, | ||
} from "./getFeaturesForSketchBBoxes.js"; | ||
import { genSampleSketch } from "../helpers/sketch.js"; | ||
import { bbox, featureCollection, polygon } from "@turf/turf"; | ||
import fix from "../testing/fixtures/squareSketches.js"; | ||
import { SketchCollection } from "../types/sketch.js"; | ||
import { Polygon } from "geojson"; | ||
|
||
describe("getFeaturesForBBoxes", () => { | ||
test("getFeaturesForBBoxes - simple", async () => { | ||
const canonicalStr = canonicalize([ | ||
{ | ||
id: 0, // this is not in the data, but fgb client automatically adds it on deserialize as of v3.36.0 | ||
type: "Feature", | ||
properties: { | ||
name: "World boundary", | ||
description: "World", | ||
}, | ||
geometry: { | ||
coordinates: [ | ||
[ | ||
[-180, 90], | ||
[-180, -90], | ||
[180, -90], | ||
[180, 90], | ||
[-180, 90], | ||
], | ||
], | ||
type: "Polygon", | ||
}, | ||
}, | ||
]); | ||
const worldJson = fs.readJsonSync("data/in/world.json"); | ||
// pull features out of FC and add index based ID, just as the flatgeobuf client does on read | ||
const worldFeatures = worldJson.features.map((f, index) => { | ||
f.id = index; | ||
return f; | ||
}); | ||
const canonicalStr = canonicalize(worldFeatures); | ||
const url = "http://127.0.0.1:8080/data/in/world.fgb"; | ||
const features = await getFeaturesForBBoxes([[-1, -1, 1, 1]], url); | ||
expect(features.length).toEqual(1); | ||
expect(canonicalize(features)).toEqual(canonicalStr); | ||
}); | ||
}); | ||
|
||
describe("getFeaturesForSketchBBoxes", () => { | ||
test("getFeaturesForSketchBBoxes - simple", async () => { | ||
const worldJson = fs.readJsonSync("data/in/world.json"); | ||
// pull features out of FC and add index based ID, just as the flatgeobuf client does on read | ||
const worldFeatures = worldJson.features.map((f, index) => { | ||
f.id = index; | ||
return f; | ||
}); | ||
const canonicalStr = canonicalize(worldFeatures); | ||
const url = "http://127.0.0.1:8080/data/in/world.fgb"; | ||
const features = await loadFgb(url); | ||
const poly = polygon([ | ||
[ | ||
[0, 0], | ||
[1, 0], | ||
[1, 1], | ||
[0, 1], | ||
[0, 0], | ||
], | ||
]); | ||
const sketch = genSampleSketch(poly.geometry, "sketch1"); | ||
const features = await getFeaturesForSketchBBoxes(sketch, url); | ||
expect(features.length).toEqual(1); | ||
expect(canonicalize(features)).toEqual(canonicalStr); | ||
}); | ||
|
||
test("getFeaturesForSketchBBoxes - bottom left squares", async () => { | ||
const url = "http://127.0.0.1:8080/data/in/squares.fgb"; | ||
const poly = polygon([ | ||
[ | ||
[0, 0], | ||
[1, 0], | ||
[1, 1], | ||
[0, 1], | ||
[0, 0], | ||
], | ||
]); | ||
const sketch = genSampleSketch(poly.geometry, "sketch1"); | ||
const features = await getFeaturesForSketchBBoxes(sketch, url); | ||
// Should pick up twoByPoly, insideTwoByPoly, and the corner of halfInsideTwoByPoly | ||
expect(features.length).toEqual(3); | ||
}); | ||
|
||
test("getFeaturesForSketchBBoxes - sketch collection", async () => { | ||
const url = "http://127.0.0.1:8080/data/in/squares.fgb"; | ||
const testSC: SketchCollection<Polygon> = { | ||
type: "FeatureCollection", | ||
properties: { | ||
id: "test", | ||
name: "Collection 1", | ||
updatedAt: "2021-11-20T00:00:34.269Z", | ||
createdAt: "2021-11-19T23:34:12.889Z", | ||
sketchClassId: "615b65a2aac8c8285d50d9f3", | ||
isCollection: true, | ||
userAttributes: [], | ||
}, | ||
bbox: bbox( | ||
featureCollection([ | ||
fix.outsideTwoByPolyTopLeftSketch, | ||
fix.outsideTwoByPolyBottomRightSketch, | ||
]), | ||
), | ||
features: [ | ||
fix.outsideTwoByPolyTopLeftSketch, | ||
fix.outsideTwoByPolyBottomRightSketch, | ||
], | ||
}; | ||
const features = await getFeaturesForSketchBBoxes(testSC, url); | ||
// Should pick up outsideTwoByPolyTopLeftSketch, outsideTwoByPolyBottomRightSketch, and the corner of halfInsideTwoByPoly | ||
expect(features.length).toEqual(3); | ||
}); | ||
}); |
Oops, something went wrong.