Skip to content

Commit

Permalink
add tests verifying behavior of getFeatures for bounding boxes around…
Browse files Browse the repository at this point in the history
… the antimeridian
  • Loading branch information
twelch committed Dec 1, 2023
1 parent 2535631 commit f805f9c
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion packages/geoprocessing/src/dataproviders/getFeatures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import { getFeatures } from "./getFeatures";
import project from "../testing/project";
import { toJsonFile } from "../helpers";
import { featureCollection } from "@turf/helpers";
import { ExternalVectorDatasource } from "../types";

// import micronesia eez from global subdivided
describe("getFeatures", () => {
Expand Down Expand Up @@ -53,5 +56,67 @@ describe("getFeatures", () => {
expect(feats.length).toEqual(1050);
}, 5000);

// import of internal datasources is tested by precalcVectorDatasource.test.ts and precalcRasterDatasource.test.ts
test("getFeatures - fetch subdivided with bbox crossing antimeridian greater than 180", async () => {
const eezDatasource = project.getExternalVectorDatasourceById(
"global-clipping-eez-land-union"
);
if (!eezDatasource)
throw new Error("missing global eez land union datasource");
const feats = await getFeatures(
eezDatasource,
project.getDatasourceUrl(eezDatasource, { format: "fgb" }),
{
bbox: [170.3874, -15.761472, 186.44315, -14.24049],
}
);
// toJsonFile(featureCollection(feats), "SUB_FIJI_OUTSIDE_SUB.json");
expect(feats.length).toEqual(4); // Only returns left side of antimeridian
}, 10000);

test("getFeatures - fetch subdivided with bbox crossing antimeridian within 180", async () => {
const eezDatasource = project.getExternalVectorDatasourceById(
"global-clipping-eez-land-union"
);
if (!eezDatasource)
throw new Error("missing global eez land union datasource");
const feats = await getFeatures(
eezDatasource,
project.getDatasourceUrl(eezDatasource, { format: "fgb" }),
{
bbox: [-180, -15.706455006156576, 180, -14.274583217973047],
}
);
// toJsonFile(featureCollection(feats), "SUB_FIJI_INSIDE_SUB.json");
expect(feats.length).toEqual(29); // Returns eez features across entire world crossing
}, 10000);

// The same behavior is observed when using a flatgeobuf datasource, they just take a lot more time to run

// test("getFeatures - fetch flatgeobuf with bbox crossing antimeridian outside 180 returns long way", async () => {
// const fgbDatasourceId =
// project.getVectorDatasourceById("global-eez-mr-v12");
// const feats = await getFeatures(
// fgbDatasourceId,
// project.getDatasourceUrl(fgbDatasourceId, { format: "fgb" }),
// {
// bbox: [170.3874, -15.761472, 186.44315, -14.24049],
// }
// );
// // toJsonFile(featureCollection(feats), "SUB_FIJI_OUTSIDE_FGB.json");
// expect(feats.length).toEqual(4); // Returns eez features across entire world crossing
// }, 90000);

// test("getFeatures - fetch flatgeobuf with bbox crossing antimeridian within 180 returns long way", async () => {
// const fgbDatasourceId =
// project.getVectorDatasourceById("global-eez-mr-v12");
// const feats = await getFeatures(
// fgbDatasourceId,
// project.getDatasourceUrl(fgbDatasourceId, { format: "fgb" }),
// {
// bbox: [-180, -15.706455006156576, 180, -14.274583217973047],
// }
// );
// // toJsonFile(featureCollection(feats), "SUB_FIJI_INSIDE_FGB.json");
// expect(feats.length).toEqual(25); // Returns 50 eez features because bbox spans the world
// }, 90000);
});

0 comments on commit f805f9c

Please sign in to comment.