Add clipping to generateCache
This commit is contained in:
parent
f7f0ccdb7d
commit
509b237d02
3 changed files with 177 additions and 90 deletions
|
@ -2,6 +2,7 @@ import { describe } from "mocha"
|
|||
import { expect } from "chai"
|
||||
import * as turf from "@turf/turf"
|
||||
import { GeoOperations } from "../../Logic/GeoOperations"
|
||||
import { Feature, LineString, Polygon } from "geojson"
|
||||
|
||||
describe("GeoOperations", () => {
|
||||
describe("calculateOverlap", () => {
|
||||
|
@ -133,4 +134,44 @@ describe("GeoOperations", () => {
|
|||
expect(overlapsRev).empty
|
||||
})
|
||||
})
|
||||
describe("clipWith", () => {
|
||||
it("clipWith should clip linestrings", () => {
|
||||
const bbox: Feature<Polygon> = {
|
||||
type: "Feature",
|
||||
properties: {},
|
||||
geometry: {
|
||||
coordinates: [
|
||||
[
|
||||
[3.218560377159008, 51.21600586532159],
|
||||
[3.218560377159008, 51.21499687768525],
|
||||
[3.2207456783268356, 51.21499687768525],
|
||||
[3.2207456783268356, 51.21600586532159],
|
||||
[3.218560377159008, 51.21600586532159],
|
||||
],
|
||||
],
|
||||
type: "Polygon",
|
||||
},
|
||||
}
|
||||
const line: Feature<LineString> = {
|
||||
type: "Feature",
|
||||
properties: {},
|
||||
geometry: {
|
||||
coordinates: [
|
||||
[3.218405371672816, 51.21499091846559],
|
||||
[3.2208408127450525, 51.21560173433727],
|
||||
],
|
||||
type: "LineString",
|
||||
},
|
||||
}
|
||||
const result = GeoOperations.clipWith(line, bbox)
|
||||
expect(result.length).to.equal(1)
|
||||
expect(result[0].geometry.type).to.eq("LineString")
|
||||
const clippedLine = (<Feature<LineString>>result[0]).geometry.coordinates
|
||||
const expCoordinates = [
|
||||
[3.2185480732975975, 51.21502965337126],
|
||||
[3.2207456783252724, 51.2155808773463],
|
||||
]
|
||||
expect(clippedLine).to.deep.equal(expCoordinates)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue