mark-p-thomas : GeoJSON Bounding Boxes

These terms adhere to RFC 7946 - The GeoJSON Format.

Sections

Definition

Often referred to as bbox, Bounding Boxes contain information on the coordinate range for GeoJSON Geometries, Features, or FeatureCollections. At a minimum, a bounding box will have two Points or four coordinates which define the box. A 3rd dimensional bounding box can be produced if elevation or altitude is defined.

The convention for the two Points is [lower-left (southwest) corner, upper-right (northeast) corner].

This object type is immutable.

JSON Example & Class Diagram

Raw GeoJSON

 [100.0, 0.0, -100.0, 105.0, 1.0, 0.0]

With a schema below:

[
  SW Longitude, 
  SW Latitude, 
  SW Altitude, 
  NE Longitude, 
  NE Latitude, 
  NE Altitude
]

Class Diagram

For a dynamic interactive diagram, see the FigJam diagram.

Reading from JSON

If there is a bounding box defined in the raw JSON geometry, this is specified as the bounding box for the created object. Take note that it is assumed that these bounding boxes are assumed to be correct, or any deviation is intended by the user. In this case, if the incoming JSON object has an incorrect bounding box, this will be preserved. Such a discrepancy is only corrected by creating a new object & then accessing the bounding box.

Lazy Loading & Updates

Even Points may have Bounding Boxes, so it is unreasonable to have bounding boxes for every single object contained within the GeoJSON object. As such, the library does the following:

  1. If there is a bounding box defined in the raw JSON geometry, this is specified as the bounding box for the created object.

  2. Otherwise, the property is left empty for a given parent object.

    1. If a user attempts to access the property, it is lazy loaded at that time and stored. This lazy loading creates a new bounding box by considering all Points & Geometries contained within.

Apart from collections & features, GeoJSON objects are immutable, so bounding boxes do not change. Instead, a new object is created that will lazy load a bounding box as needed.

For collections & features, a dirty flag pattern is used to track when items are added/removed in collections, or a geometry child of a feature is changed. In these cases, the lazy loading trigger is reset so that a new bounding box is created when needed.

Writing to JSON

All bounding boxes that have been loaded in a session will be written out to a JSON object. In the simplest case, this means that bounding boxes in the original JSON object are preserved. Additionally more bounding boxes are computationally added to the output by accessing them in the objects.