Splitting a polygon along the antimeridian can potentially much more involved than expected. In Python, we can use the Shapely library to accomplish this with the following steps
- Taking a given polygon's coordinates (in GeoJSON format), then detecting whether there are antimeridian crossings by checking if the absolute value of the longitudinal difference between two consecutive vertices of the polygon is greater than a certain threshold. Practically, 180 degrees could be a sensible threshold value.
- If there are antimeridian crossing, you will next need to determine the direction (e.g. is it going from +179.9 to -179.9 or vice versa). Once you know the direction, you can shift certain vertices of the polygon into a new Cartesian space. For example, consider the case of the previous vertex at +179.9 the the current vertex at -179.9:
- we can shift the current vertex to +180.1 in our new Cartesian space
- we note down that the antimeridian crossing is a line at +180.0 of longitude
- Once the entire polygon's vertices have been appropriately shifted into the new Cartesian space, we can then leverage Shapely's Cartesian geometry operations (particularly the
shapely.ops.split
function) to split the polygon safely. - Finally, for each of the resultant polygons from the
split
operation, you'll need to shift their longitude values to appropriate geographic coordinates (+/- 360.0)
Here's athe full tutorial + code snippets using Shapely.