fix(geometry): preserve polygon holes
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { wktToGeoJson } from "@/lib/geometryPreview";
|
||||
|
||||
describe("wktToGeoJson", () => {
|
||||
it("preserves polygon interior rings", () => {
|
||||
const geometry = wktToGeoJson("POLYGON((0 0,10 0,10 10,0 10,0 0),(2 2,8 2,8 8,2 8,2 2))");
|
||||
|
||||
expect(geometry).toEqual({
|
||||
type: "Polygon",
|
||||
coordinates: [
|
||||
[
|
||||
[0, 0],
|
||||
[10, 0],
|
||||
[10, 10],
|
||||
[0, 10],
|
||||
[0, 0],
|
||||
],
|
||||
[
|
||||
[2, 2],
|
||||
[8, 2],
|
||||
[8, 8],
|
||||
[2, 8],
|
||||
[2, 2],
|
||||
],
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves multipolygon interior rings", () => {
|
||||
const geometry = wktToGeoJson("MULTIPOLYGON(((0 0,10 0,10 10,0 10,0 0),(2 2,8 2,8 8,2 8,2 2)))");
|
||||
|
||||
expect(geometry).toEqual({
|
||||
type: "MultiPolygon",
|
||||
coordinates: [
|
||||
[
|
||||
[
|
||||
[0, 0],
|
||||
[10, 0],
|
||||
[10, 10],
|
||||
[0, 10],
|
||||
[0, 0],
|
||||
],
|
||||
[
|
||||
[2, 2],
|
||||
[8, 2],
|
||||
[8, 8],
|
||||
[2, 8],
|
||||
[2, 2],
|
||||
],
|
||||
],
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -73,8 +73,10 @@ function parseGroups(tokens: (string | number)[], start: number): { groups: Geom
|
||||
i = inner.end;
|
||||
}
|
||||
if (i < tokens.length && tokens[i] === ")") i++;
|
||||
} else if (tokens[i] === ")" || tokens[i] === ",") {
|
||||
} else if (tokens[i] === ")") {
|
||||
break;
|
||||
} else if (tokens[i] === ",") {
|
||||
i++;
|
||||
} else if (typeof tokens[i] === "number") {
|
||||
const seq = parseCoordSequence(tokens, i);
|
||||
groups.push({ coords: seq.coords, children: [] });
|
||||
|
||||
Reference in New Issue
Block a user