Skip to content

Commit

Permalink
Update all examples and tests with dimensionality
Browse files Browse the repository at this point in the history
  • Loading branch information
reilem committed Oct 7, 2024
1 parent c2066a8 commit 4cac3c9
Show file tree
Hide file tree
Showing 19 changed files with 330 additions and 84 deletions.
24 changes: 19 additions & 5 deletions examples/feature_collection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GeoJSONFeatureCollection } from "../src";
import { GeoJSON2DFeatureCollection, GeoJSON3DFeatureCollection, GeoJSONFeatureCollection } from "../src";

export const singleGeoJsonFeatureCollection: GeoJSONFeatureCollection = {
export const singleGeoJsonFeatureCollection2D: GeoJSON2DFeatureCollection = {
type: "FeatureCollection",
features: [
{
Expand All @@ -14,7 +14,21 @@ export const singleGeoJsonFeatureCollection: GeoJSONFeatureCollection = {
],
};

export const multiGeoJsonFeatureCollection: GeoJSONFeatureCollection = {
export const singleGeoJsonFeatureCollection3D: GeoJSON3DFeatureCollection = {
type: "FeatureCollection",
features: [
{
type: "Feature",
properties: {},
geometry: {
type: "Point",
coordinates: [0.0, 0.0, 1.0],
},
},
],
};

export const multiGeoJsonFeatureCollection2D: GeoJSON2DFeatureCollection = {
type: "FeatureCollection",
features: [
{
Expand All @@ -39,7 +53,7 @@ export const multiGeoJsonFeatureCollection: GeoJSONFeatureCollection = {
],
};

export const multiGeoJsonFeatureCollectionWithBbox: GeoJSONFeatureCollection = {
...multiGeoJsonFeatureCollection,
export const multiGeoJsonFeatureCollectionWithBbox2D: GeoJSONFeatureCollection = {
...multiGeoJsonFeatureCollection2D,
bbox: [0.0, 0.0, 10.0, 10.0],
};
14 changes: 7 additions & 7 deletions examples/geometry/geometry_collection.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
import { GeoJSONGeometryCollection } from "../../src";
import { GeoJSON2DGeometryCollection, GeoJSON3DGeometryCollection } from "../../src";
import { geoJsonLineString3D } from "./line_string";
import { multiGeoJsonMultiLineString2D } from "./multi_line_string";
import { geoJsonMultiPoint2D } from "./multi_point";
import { singleGeoJsonMultiPolygon3D } from "./multi_polygon";
import { geoJsonPoint2D, geoJsonPoint2DWithBbox, geoJsonPoint3D } from "./point";
import { geoJsonPolygon2D } from "./polygon";

export const singleGeoJsonGeometryCollection2D: GeoJSONGeometryCollection = {
export const singleGeoJsonGeometryCollection2D: GeoJSON2DGeometryCollection = {
type: "GeometryCollection",
geometries: [geoJsonPoint2D],
};

export const multiGeoJsonGeometryCollection2D: GeoJSONGeometryCollection = {
export const multiGeoJsonGeometryCollection2D: GeoJSON2DGeometryCollection = {
type: "GeometryCollection",
geometries: [geoJsonPoint2D, geoJsonMultiPoint2D, geoJsonPolygon2D, multiGeoJsonMultiLineString2D],
};

export const multiGeoJsonGeometryCollection3D: GeoJSONGeometryCollection = {
export const multiGeoJsonGeometryCollection3D: GeoJSON3DGeometryCollection = {
type: "GeometryCollection",
geometries: [geoJsonPoint3D, geoJsonLineString3D, singleGeoJsonMultiPolygon3D],
};

export const singleGeoJsonGeometryCollection2DWithBbox: GeoJSONGeometryCollection = {
export const singleGeoJsonGeometryCollection2DWithBbox: GeoJSON2DGeometryCollection = {
...singleGeoJsonGeometryCollection2D,
bbox: geoJsonPoint2DWithBbox.bbox,
};

export const multiGeoJsonGeometryCollection2DWithBbox: GeoJSONGeometryCollection = {
export const multiGeoJsonGeometryCollection2DWithBbox: GeoJSON2DGeometryCollection = {
...multiGeoJsonGeometryCollection2D,
bbox: [-3.0, -2.0, 30.0, 30.0],
};

export const multiGeoJsonGeometryCollection3DWithBbox: GeoJSONGeometryCollection = {
export const multiGeoJsonGeometryCollection3DWithBbox: GeoJSON3DGeometryCollection = {
...multiGeoJsonGeometryCollection3D,
bbox: [0.0, 0.0, 0.0, 20.0, 10.0, 10.0],
};
10 changes: 5 additions & 5 deletions examples/geometry/line_string.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { GeoJSONLineString } from "../../src";
import { GeoJSON2DLineString, GeoJSON3DLineString } from "../../src";

export const geoJsonLineString2D: GeoJSONLineString = {
export const geoJsonLineString2D: GeoJSON2DLineString = {
type: "LineString",
coordinates: [
[1.0, 2.0],
[3.0, 4.0],
],
};

export const geoJsonLineString3D: GeoJSONLineString = {
export const geoJsonLineString3D: GeoJSON3DLineString = {
type: "LineString",
coordinates: [
[0.0, 0.0, 0.0],
Expand All @@ -17,12 +17,12 @@ export const geoJsonLineString3D: GeoJSONLineString = {
],
};

export const geoJsonLineString2DWithBbox: GeoJSONLineString = {
export const geoJsonLineString2DWithBbox: GeoJSON2DLineString = {
...geoJsonLineString2D,
bbox: [1.0, 2.0, 3.0, 4.0],
};

export const geoJsonLineString3DWithBbox: GeoJSONLineString = {
export const geoJsonLineString3DWithBbox: GeoJSON3DLineString = {
...geoJsonLineString3D,
bbox: [0.0, 0.0, 0.0, 20.0, 10.0, 2.0],
};
14 changes: 7 additions & 7 deletions examples/geometry/multi_line_string.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { GeoJSONMultiLineString } from "../../src";
import { GeoJSON2DMultiLineString, GeoJSON3DMultiLineString } from "../../src";
import {
geoJsonLineString2D,
geoJsonLineString2DWithBbox,
geoJsonLineString3D,
geoJsonLineString3DWithBbox,
} from "./line_string";

export const singleGeoJsonMultiLineString2D: GeoJSONMultiLineString = {
export const singleGeoJsonMultiLineString2D: GeoJSON2DMultiLineString = {
type: "MultiLineString",
coordinates: [geoJsonLineString2D.coordinates],
};
export const multiGeoJsonMultiLineString2D: GeoJSONMultiLineString = {
export const multiGeoJsonMultiLineString2D: GeoJSON2DMultiLineString = {
type: "MultiLineString",
coordinates: [
geoJsonLineString2D.coordinates,
Expand All @@ -20,22 +20,22 @@ export const multiGeoJsonMultiLineString2D: GeoJSONMultiLineString = {
],
],
};
export const singleGeoJsonMultiLineString3D: GeoJSONMultiLineString = {
export const singleGeoJsonMultiLineString3D: GeoJSON3DMultiLineString = {
type: "MultiLineString",
coordinates: [geoJsonLineString3D.coordinates],
};

export const singleGeoJsonMultiLineString2DWithBbox: GeoJSONMultiLineString = {
export const singleGeoJsonMultiLineString2DWithBbox: GeoJSON2DMultiLineString = {
...singleGeoJsonMultiLineString2D,
bbox: geoJsonLineString2DWithBbox.bbox,
};

export const multiGeoJsonMultiLineString2DWithBbox: GeoJSONMultiLineString = {
export const multiGeoJsonMultiLineString2DWithBbox: GeoJSON2DMultiLineString = {
...multiGeoJsonMultiLineString2D,
bbox: [1.0, 2.0, 30.0, 30.0],
};

export const singleGeoJsonMultiLineString3DWithBbox: GeoJSONMultiLineString = {
export const singleGeoJsonMultiLineString3DWithBbox: GeoJSON3DMultiLineString = {
...singleGeoJsonMultiLineString3D,
bbox: geoJsonLineString3DWithBbox.bbox,
};
10 changes: 5 additions & 5 deletions examples/geometry/multi_point.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GeoJSONMultiPoint } from "../../src";
import { GeoJSON2DMultiPoint, GeoJSON3DMultiPoint } from "../../src";

export const geoJsonMultiPoint2D: GeoJSONMultiPoint = {
export const geoJsonMultiPoint2D: GeoJSON2DMultiPoint = {
type: "MultiPoint",
coordinates: [
[0.0, 0.0],
Expand All @@ -9,7 +9,7 @@ export const geoJsonMultiPoint2D: GeoJSONMultiPoint = {
],
};

export const geoJsonMultiPoint3D: GeoJSONMultiPoint = {
export const geoJsonMultiPoint3D: GeoJSON3DMultiPoint = {
type: "MultiPoint",
coordinates: [
[0.0, 0.0, 0.0],
Expand All @@ -18,12 +18,12 @@ export const geoJsonMultiPoint3D: GeoJSONMultiPoint = {
],
};

export const geoJsonMultiPoint2DWithBbox: GeoJSONMultiPoint = {
export const geoJsonMultiPoint2DWithBbox: GeoJSON2DMultiPoint = {
...geoJsonMultiPoint2D,
bbox: [-3.0, -2.0, 8.0, 4.0],
};

export const geoJsonMultiPoint3DWithBbox: GeoJSONMultiPoint = {
export const geoJsonMultiPoint3DWithBbox: GeoJSON3DMultiPoint = {
...geoJsonMultiPoint3D,
bbox: [-3.0, -2.0, 0.0, 8.0, 4.0, 5.0],
};
12 changes: 6 additions & 6 deletions examples/geometry/multi_polygon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GeoJSON2DMultiPolygon, GeoJSONMultiPolygon } from "../../src";
import { GeoJSON2DMultiPolygon, GeoJSON3DMultiPolygon } from "../../src";
import {
geoJsonPolygon2D,
geoJsonPolygon2DWithBbox,
Expand All @@ -13,27 +13,27 @@ export const singleGeoJsonMultiPolygon2D: GeoJSON2DMultiPolygon = {
coordinates: [geoJsonPolygon2D.coordinates],
};

export const multiGeoJsonMultiPolygon2D: GeoJSONMultiPolygon = {
export const multiGeoJsonMultiPolygon2D: GeoJSON2DMultiPolygon = {
type: "MultiPolygon",
coordinates: [geoJsonPolygon2D.coordinates, geoJsonPolygon2DWithHole.coordinates],
};

export const singleGeoJsonMultiPolygon3D: GeoJSONMultiPolygon = {
export const singleGeoJsonMultiPolygon3D: GeoJSON3DMultiPolygon = {
type: "MultiPolygon",
coordinates: [geoJsonPolygon3D.coordinates],
};

export const singleGeoJsonMultiPolygon2DWithBbox: GeoJSONMultiPolygon = {
export const singleGeoJsonMultiPolygon2DWithBbox: GeoJSON2DMultiPolygon = {
...singleGeoJsonMultiPolygon2D,
bbox: geoJsonPolygon2DWithBbox.bbox,
};

export const multiGeoJsonMultiPolygon2DWithBbox: GeoJSONMultiPolygon = {
export const multiGeoJsonMultiPolygon2DWithBbox: GeoJSON2DMultiPolygon = {
...multiGeoJsonMultiPolygon2D,
bbox: geoJsonPolygon2DWithHoleAndBbox.bbox,
};

export const singleGeoJsonMultiPolygon3DWithBbox: GeoJSONMultiPolygon = {
export const singleGeoJsonMultiPolygon3DWithBbox: GeoJSON3DMultiPolygon = {
...singleGeoJsonMultiPolygon3D,
bbox: geoJsonPolygon3DWithBbox.bbox,
};
10 changes: 5 additions & 5 deletions examples/geometry/point.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { GeoJSONPoint } from "../../src";
import { GeoJSON2DPoint, GeoJSON3DPoint } from "../../src";

export const geoJsonPoint2D: GeoJSONPoint = {
export const geoJsonPoint2D: GeoJSON2DPoint = {
type: "Point",
coordinates: [1.0, 2.0],
};

export const geoJsonPoint3D: GeoJSONPoint = {
export const geoJsonPoint3D: GeoJSON3DPoint = {
type: "Point",
coordinates: [1.0, 2.0, 10.0],
};

export const geoJsonPoint2DWithBbox: GeoJSONPoint = {
export const geoJsonPoint2DWithBbox: GeoJSON2DPoint = {
...geoJsonPoint2D,
bbox: [1.0, 2.0, 1.0, 2.0],
};

export const geoJsonPoint3DWithBbox: GeoJSONPoint = {
export const geoJsonPoint3DWithBbox: GeoJSON3DPoint = {
...geoJsonPoint3D,
bbox: [1.0, 2.0, 10.0, 1.0, 2.0, 10.0],
};
12 changes: 6 additions & 6 deletions examples/geometry/polygon.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GeoJSON2DPolygon, GeoJSONPolygon } from "../../src";
import { GeoJSON2DPolygon, GeoJSON3DPolygon } from "../../src";

export const geoJsonPolygon2D: GeoJSON2DPolygon = {
type: "Polygon",
Expand All @@ -13,7 +13,7 @@ export const geoJsonPolygon2D: GeoJSON2DPolygon = {
],
};

export const geoJsonPolygon3D: GeoJSONPolygon = {
export const geoJsonPolygon3D: GeoJSON3DPolygon = {
type: "Polygon",
coordinates: [
[
Expand All @@ -26,7 +26,7 @@ export const geoJsonPolygon3D: GeoJSONPolygon = {
],
};

export const geoJsonPolygon2DWithHole: GeoJSONPolygon = {
export const geoJsonPolygon2DWithHole: GeoJSON2DPolygon = {
...geoJsonPolygon2D,
coordinates: [
[
Expand All @@ -46,17 +46,17 @@ export const geoJsonPolygon2DWithHole: GeoJSONPolygon = {
],
};

export const geoJsonPolygon2DWithBbox: GeoJSONPolygon = {
export const geoJsonPolygon2DWithBbox: GeoJSON2DPolygon = {
...geoJsonPolygon2D,
bbox: [0.0, 0.0, 1.0, 1.0],
};

export const geoJsonPolygon3DWithBbox: GeoJSONPolygon = {
export const geoJsonPolygon3DWithBbox: GeoJSON3DPolygon = {
...geoJsonPolygon3D,
bbox: [0.0, 0.0, 0.0, 1.0, 2.0, 2.0],
};

export const geoJsonPolygon2DWithHoleAndBbox: GeoJSONPolygon = {
export const geoJsonPolygon2DWithHoleAndBbox: GeoJSON2DPolygon = {
...geoJsonPolygon2DWithHole,
bbox: [0.0, 0.0, 10.0, 10.0],
};
20 changes: 19 additions & 1 deletion tests/feature.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
geoJsonFeaturePolygon2D,
geoJsonFeaturePolygon3DWithBbox,
} from "../examples/feature";
import { GeoJSONFeatureSchema } from "../src";
import { GeoJSON2DFeatureSchema, GeoJSON3DFeatureSchema, GeoJSONFeatureSchema } from "../src";

function passGeoJSONFeatureSchemaTest(object: unknown) {
expect(GeoJSONFeatureSchema.parse(object)).toEqual(object);
Expand Down Expand Up @@ -146,4 +146,22 @@ describe("GeoJSONFeature", () => {
bbox: ["bbox must not contain strings"],
});
});

describe("2D", () => {
it("allows a 2D feature", () => {
expect(GeoJSON2DFeatureSchema.parse(geoJsonFeaturePolygon2D)).toEqual(geoJsonFeaturePolygon2D);
});
it("does not allow a 3D feature", () => {
expect(() => GeoJSON2DFeatureSchema.parse(geoJsonFeaturePoint3D)).toThrow(ZodError);
});
});

describe("3D", () => {
it("allows a 3D feature", () => {
expect(GeoJSON3DFeatureSchema.parse(geoJsonFeaturePoint3D)).toEqual(geoJsonFeaturePoint3D);
});
it("does not allow a 2D feature", () => {
expect(() => GeoJSON3DFeatureSchema.parse(geoJsonFeaturePolygon2D)).toThrow(ZodError);
});
});
});
Loading

0 comments on commit 4cac3c9

Please sign in to comment.