original_docstring: 
      Function that splits a polygon at the antimeridian
      (i.e. the 180 degree dateline)
  
      Parameters
      ----------
      lonlat_polygon : OGRGeometry
          geometry object in lonlat space to be split by the antimeridian
      split_limit : float, optional
          longitude that determines what is split and what not. default is 150.0
          e.g. a polygon with a centre east of 150E or west of 150W will be split!
      Returns
      -------
      splitted_polygons : OGRGeometry
          MULTIPOLYGON comprising east and west parts of lonlat_polygon
          contains only one POLYGON if no intersect with antimeridian is given
  
      
docstring: Function that splits a polygon at the antimeridian
  
  Parameters
  
  lonlat_polygon : OGRGeometry
  geometry object in lonlat space to be split by the antimeridian
  split_limit : float, optional
  longitude that determines what is split and what not.
  
  splitted_polygons : OGRGeometry
  MULTIPOLYGON comprising east and west parts of lonlat_polygon
  contains only one POLYGON if no intersect with antimeridian is given
docstring_tokens: Function that splits a polygon at the antimeridian Parameters lonlat_polygon : OGRGeometry geometry object in lonlat space to be split by the antimeridian split_limit : float optional longitude that determines what is split and what not . splitted_polygons : OGRGeometry MULTIPOLYGON comprising east and west parts of lonlat_polygon contains only one POLYGON if no intersect with antimeridian is given
code: def split_polygon_by_antimeridian(lonlat_polygon, split_limit=150.0):
      """
      Function that splits a polygon at the antimeridian
      (i.e. the 180 degree dateline)
  
      Parameters
      ----------
      lonlat_polygon : OGRGeometry
          geometry object in lonlat space to be split by the antimeridian
      split_limit : float, optional
          longitude that determines what is split and what not. default is 150.0
          e.g. a polygon with a centre east of 150E or west of 150W will be split!
      Returns
      -------
      splitted_polygons : OGRGeometry
          MULTIPOLYGON comprising east and west parts of lonlat_polygon
          contains only one POLYGON if no intersect with antimeridian is given
  
      """
  
      # prepare the input polygon
      in_points = lonlat_polygon.GetGeometryRef(0).GetPoints()
      lons = [p[0] for p in in_points]
  
      # case of very long polygon in east-west direction,
      # crossing the Greenwich meridian, but not the antimeridian,
      # which is most probably a wrong interpretion.
      # --> wrapping longitudes to the eastern Hemisphere (adding 360°)
      if (len(np.unique(np.sign(lons))) == 2) and (np.mean(np.abs(lons)) > split_limit):
          new_points = [(y[0] + 360, y[1]) if y[0] < 0 else y for y in in_points]
          lonlat_polygon = create_polygon_geometry(new_points,
                                                   lonlat_polygon.GetSpatialReference(),
                                                   segment=0.5)
  
      # return input polygon if not cross anti-meridian
      max_lon = np.max([p[0]
                        for p in lonlat_polygon.GetGeometryRef(0).GetPoints()])
      if max_lon <= 180:
          return lonlat_polygon
  
      # define the antimeridian
      antimeridian = LineString([(180, -90), (180, 90)])
  
      # use shapely for the splitting
      merged = linemerge(
          [Polygon(lonlat_polygon.GetBoundary().GetPoints()).boundary, antimeridian])
      borders = unary_union(merged)
      polygons = polygonize(borders)
  
      # setup OGR multipolygon
      splitted_polygons = ogr.Geometry(ogr.wkbMultiPolygon)
      geo_sr = get_geog_spatial_ref()
      splitted_polygons.AssignSpatialReference(geo_sr)
  
      # wrap the longitude coordinates
      # to get only longitudes out out [0, 180] or [-180, 0]
      for p in polygons:
  
          point_coords = p.exterior.coords[:]
          lons = [p[0] for p in point_coords]
  
          # all greater than 180° longitude (Western Hemisphere)
          if (len(np.unique(np.sign(lons))) == 1) and (np.greater_equal(lons, 180).all()):
              wrapped_points = [(y[0] - 360, y[1], y[2]) for y in point_coords]
  
          # all less than 180° longitude (Eastern Hemisphere)
          elif (len(np.unique(np.sign(lons))) == 1) and (np.less_equal(lons, 180).all()):
              wrapped_points = point_coords
  
          # crossing the Greenwhich-meridian
          elif (len(np.unique(np.sign(lons))) >= 2) and (np.mean(np.abs(lons)) < split_limit):
              wrapped_points = point_coords
  
          # crossing the Greenwhich-meridian, but should cross the antimeridian
          # (should not be happen actually)
          else:
              continue
  
          new_poly = Polygon(wrapped_points)
          splitted_polygons.AddGeometry(ogr.CreateGeometryFromWkt(new_poly.wkt))
  
      return splitted_polygons
code_tokens: def split_polygon_by_antimeridian ( lonlat_polygon , split_limit = 150.0 ) : in_points = lonlat_polygon . GetGeometryRef ( 0 ) . GetPoints ( ) lons = [ p [ 0 ] for p in in_points ] if ( len ( np . unique ( np . sign ( lons ) ) ) == 2 ) and ( np . mean ( np . abs ( lons ) ) > split_limit ) : new_points = [ ( y [ 0 ] + 360 , y [ 1 ] ) if y [ 0 ] < 0 else y for y in in_points ] lonlat_polygon = create_polygon_geometry ( new_points , lonlat_polygon . GetSpatialReference ( ) , segment = 0.5 ) max_lon = np . max ( [ p [ 0 ] for p in lonlat_polygon . GetGeometryRef ( 0 ) . GetPoints ( ) ] ) if max_lon <= 180 : return lonlat_polygon antimeridian = LineString ( [ ( 180 , - 90 ) , ( 180 , 90 ) ] ) merged = linemerge ( [ Polygon ( lonlat_polygon . GetBoundary ( ) . GetPoints ( ) ) . boundary , antimeridian ] ) borders = unary_union ( merged ) polygons = polygonize ( borders ) splitted_polygons = ogr . Geometry ( ogr . wkbMultiPolygon ) geo_sr = get_geog_spatial_ref ( ) splitted_polygons . AssignSpatialReference ( geo_sr ) for p in polygons : point_coords = p . exterior . coords [ : ] lons = [ p [ 0 ] for p in point_coords ] if ( len ( np . unique ( np . sign ( lons ) ) ) == 1 ) and ( np . greater_equal ( lons , 180 ) . all ( ) ) : wrapped_points = [ ( y [ 0 ] - 360 , y [ 1 ] , y [ 2 ] ) for y in point_coords ] elif ( len ( np . unique ( np . sign ( lons ) ) ) == 1 ) and ( np . less_equal ( lons , 180 ) . all ( ) ) : wrapped_points = point_coords elif ( len ( np . unique ( np . sign ( lons ) ) ) >= 2 ) and ( np . mean ( np . abs ( lons ) ) < split_limit ) : wrapped_points = point_coords else : continue new_poly = Polygon ( wrapped_points ) splitted_polygons . AddGeometry ( ogr . CreateGeometryFromWkt ( new_poly . wkt ) ) return splitted_polygons
short_docstring: Function that splits a polygon at the antimeridian
  (i.e.
short_docstring_tokens: Function that splits a polygon at the antimeridian ( i . e .
comment: """
      Function that splits a polygon at the antimeridian
      (i.e. the 180 degree dateline)
  
      Parameters
      ----------
      lonlat_polygon : OGRGeometry
          geometry object in lonlat space to be split by the antimeridian
      split_limit : float, optional
          longitude that determines what is split and what not. default is 150.0
          e.g. a polygon with a centre east of 150E or west of 150W will be split!
      Returns
      -------
      splitted_polygons : OGRGeometry
          MULTIPOLYGON comprising east and west parts of lonlat_polygon
          contains only one POLYGON if no intersect with antimeridian is given
  
      """$SEP$# prepare the input polygon$SEP$# case of very long polygon in east-west direction,$SEP$# crossing the Greenwich meridian, but not the antimeridian,$SEP$# which is most probably a wrong interpretion.$SEP$# --> wrapping longitudes to the eastern Hemisphere (adding 360°)$SEP$# return input polygon if not cross anti-meridian$SEP$# define the antimeridian$SEP$# use shapely for the splitting$SEP$# setup OGR multipolygon$SEP$# wrap the longitude coordinates$SEP$# to get only longitudes out out [0, 180] or [-180, 0]$SEP$# all greater than 180° longitude (Western Hemisphere)$SEP$# all less than 180° longitude (Eastern Hemisphere)$SEP$# crossing the Greenwhich-meridian$SEP$# crossing the Greenwhich-meridian, but should cross the antimeridian$SEP$# (should not be happen actually)