2

Many geo libraries (for example, geoPHP) support finding the centroid of a geoJSON shapes:

$geom = geoPHP::load(file_get_contents('USA.json'), 'json');
$centroid = $geom->centroid();

The code will find the centerpoint of that shape, but does not handle crossing the 180th meridian in a manner that works well for centering on that shape on a continuous map. For a country shape like Russia, the bounding box and the centerpoint are based on a non-continuous shape:

russia and the 180th meridian

The centerpoint is calculated for the shape based on this coordinate system, rather than if the shape would "wrap" around the meridian. Is the a library or tool which can calculate the centerpoint of these shapes while accounting for wrapping?

(This is tangential to my question here: Display GeoJSON with leaflet that spans the 180th meridian)

Community
  • 1
  • 1
Rob
  • 7,377
  • 7
  • 36
  • 38

0 Answers0