opendatalab-de / geojson-jackson

GeoJson POJOs for Jackson - serialize and deserialize objects with ease
http://blog.opendatalab.de
Apache License 2.0
263 stars 94 forks source link

Implement `calculateBoundingBox()` method for `GeoJsonObject`s. #45

Open zerobandwidth opened 6 years ago

zerobandwidth commented 6 years ago

Add a calculateBoundingBox() method to GeoJsonObject, which would calculate (and reset) the object's bbox based on the instance's other attributes.

Class Suggested Implementation
GeoJsonObject Define it as abstract to force implementation classes to provide it.
Feature Call this.getGeometry().calculateBoundingBox().
FeatureCollection Get the box for each Feature in the collection, then draw a box around all results.
Geometry Leave it abstract.
LineString Might get away with using MultiPoint's implementation?
MultiLineString Calculate min/max lat/long among all line endpoints.
MultiPoint Calculate the min/max lat/long from all points.
MultiPolygon Get the box for each Polygon, then draw a box around all of those boxes.
Point Set a "box" at the point's coordinates.
Polygon Calculate the min/max lat/long from all points on the outermost ring.

The order of the four double values must correspond to the order assumed in the definition of the bbox member of GeoJsonObject (whatever that is).

Consider calling this method automatically in any method that alters the shape of the object, such that the bounding box is updated in real time.