Skip to main content
added high-level logic for the solution detailed in the link
Source Link

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

  1. 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.
  2. 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
  3. 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.
  4. 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.

Splitting a polygon along the antimeridian can potentially much more involved than expected. Here's a full tutorial + code snippets using Shapely.

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

  1. 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.
  2. 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
  3. 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.
  4. 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 the full tutorial + code snippets using Shapely.

removed HTH
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65

Splitting a polygon along the antimeridian can potentially much more involved than expected. Here's a full tutorial + code snippets using Shapely. Hope this helps!

Splitting a polygon along the antimeridian can potentially much more involved than expected. Here's a full tutorial + code snippets using Shapely. Hope this helps!

Splitting a polygon along the antimeridian can potentially much more involved than expected. Here's a full tutorial + code snippets using Shapely.

Source Link

Splitting a polygon along the antimeridian can potentially much more involved than expected. Here's a full tutorial + code snippets using Shapely. Hope this helps!