Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toHaveBoundingBox #53

Open
M-Scott-Lassiter opened this issue Jun 8, 2022 · 0 comments
Open

toHaveBoundingBox #53

M-Scott-Lassiter opened this issue Jun 8, 2022 · 0 comments
Assignees
Labels
new matcher proposal Proposal for a new GeoJSON matcher

Comments

@M-Scott-Lassiter
Copy link
Owner

M-Scott-Lassiter commented Jun 8, 2022

Description

Bounding boxes are an optional GeoJSON property that describe a box of longitude boundaries that run along meridians and latitude boundaries that are parallel to the equator. A 2D Bounding Box only describes longitude and latitude boundaries, whereas a 3D Bounding Box describes an additional min and max altitude/depth value.

A GeoJSON object MAY have a member named "bbox" to include information on the coordinate range for its Geometries, Features, or FeatureCollections. The value of the bbox member MUST be an array of length 2*n where n is the number of dimensions represented in the contained geometries, with all axes of the most southwesterly point followed by all axes of the more northeasterly point. The axes order of a bbox follows the axes order of geometries.

The "bbox" values define shapes with edges that follow lines of constant longitude, latitude, and elevation.
~ https://datatracker.ietf.org/doc/html/rfc7946#section-5

This matcher evaluates any Geometry, GeometryCollection, Feature, or FeatureCollection object to ensure it has a valid 2D or 3D bounding box. It will not check any subsets of these objects (i.e. it will not check all "geometries" in the collection also have bounding boxes).

It takes an optional argument of a valid bounding box array, bboxEquals. If present, the feature must have a bounding box that exactly equals this value.

Example Matcher Usage

const testCollection = {
    type: "FeatureCollection",
    bbox: [-100.0, -10, 10, 49.5],
    features: [
        {
            type: "Feature",
            geometry: {...}
        },
        {
            type: "Feature",
            bbox: [-20, -5, 0, 5]
            geometry: {...}
        }
    ]
}
const testPolygon = {
    type: "Polygon",
    bbox: [-10, -10, 10, 10],
    coordinates: [
        [
            [-10.0, -10.0],
            [10.0, -10.0],
            [10.0, 10.0],
            [-10.0, -10.0]
        ]
    ]
}

expect(testCollection).toHaveBoundingBox()
expect(testCollection).toHaveBoundingBox([-100.0, -10, 10, 49.5])
expect(testCollection.features[1]).toHaveBoundingBox()
expect(testCollection.features[1]).toHaveBoundingBox([-20, -5, 0, 5])
expect(testPolygon).toHaveBoundingBox()


expect(testCollection).not.toHaveBoundingBox([-10, -10, 10, 10])
expect(testCollection.features[0]).not.toHaveBoundingBox()
expect(testPolygon.bbox).not.toHaveBoundingBox()

Passing Tests

Valid GeoJSON Objects with a BBox

Check with and without optional bboxEquals

  • Each of the seven Geometry, Feature, and FeatureCollection valid objects

Valid GeoJSON Objects with a BBox

A GeometryCollection, Feature, and FeatureCollection that has a BBox, but one or more components do not

Failing Tests

Invalid Inputs To Matcher

Rejects each of the following:

  • Each of the seven Geometry, Feature, and FeatureCollection objects when invalid
  • Arrays: [], [0, 0], [0, 0, 0], [[-20], [10], [-10], [20]], [0, 0, 0, 0], [0, 0, 0, 0, 0, 0]
  • undefined, null, false, true, 0
  • { someProp: 'I am not GeoJSON', id: 4 }
  • {}
  • '',
  • 'Random Feature',
  • JSON.stringify({
        type: 'Feature',
        geometry: null,
        properties: null
    })

Valid GeoJSON Objects without a BBox

Each of the seven Geometry, Feature, and FeatureCollection valid objects

Valid GeoJSON Objects with Component BBox but no Overall BBox

A GeometryCollection, Feature, and FeatureCollection that has no BBox, but the geometries do

Valid GeoJSON Objects with a BBox, bboxEquals Does Not Match

Each of the seven Geometry, Feature, and FeatureCollection valid objects

Incorrect number of array elements in bboxEquals

All items in "Invalid Inputs To Matcher" except the 4 and 6 element arrays

@M-Scott-Lassiter M-Scott-Lassiter added the new matcher proposal Proposal for a new GeoJSON matcher label Jun 8, 2022
@M-Scott-Lassiter M-Scott-Lassiter self-assigned this Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new matcher proposal Proposal for a new GeoJSON matcher
Projects
None yet
Development

No branches or pull requests

1 participant