(polygon, tolerance=1.0)
return best_cell.centroid
Finds pole of inaccessibility for a given polygon. Based on
    Vladimir Agafonkin's https://github.com/mapbox/polylabel

    Parameters
    ----------
    polygon : shapely.geometry.Polygon
    tolerance : int or float, optional
                `tolerance` represents the highest resolution in units of the
                input geometry that will be considered for a solution. (default
                value is 1.0).

    Returns
    -------
    shapely.geometry.Point
        A point representing the pole of inaccessibility for the given input
        polygon.

    Raises
    ------
    shapely.geos.TopologicalError
        If the input polygon is not a valid geometry.

    Example
    -------
    >>> polygon = LineString([(0, 0), (50, 200), (100, 100), (20, 50),
    ... (-100, -20), (-150, -200)]).buffer(100)
    >>> label = polylabel(polygon, tolerance=10)
    >>> label.wkt
    'POINT (59.35615556364569 121.8391962974644)'
Finds pole of inaccessibility for a given polygon. Based on
    Vladimir Agafonkin's https://github.com/mapbox/polylabel
Finds pole of inaccessibility for a given polygon . Based on Vladimir Agafonkin s https : // github . com / mapbox / polylabel
def polylabel(polygon, tolerance=1.0):
    """Finds pole of inaccessibility for a given polygon. Based on
    Vladimir Agafonkin's https://github.com/mapbox/polylabel

    Parameters
    ----------
    polygon : shapely.geometry.Polygon
    tolerance : int or float, optional
                `tolerance` represents the highest resolution in units of the
                input geometry that will be considered for a solution. (default
                value is 1.0).

    Returns
    -------
    shapely.geometry.Point
        A point representing the pole of inaccessibility for the given input
        polygon.

    Raises
    ------
    shapely.geos.TopologicalError
        If the input polygon is not a valid geometry.

    Example
    -------
    >>> polygon = LineString([(0, 0), (50, 200), (100, 100), (20, 50),
    ... (-100, -20), (-150, -200)]).buffer(100)
    >>> label = polylabel(polygon, tolerance=10)
    >>> label.wkt
    'POINT (59.35615556364569 121.8391962974644)'
    """
    if not polygon.is_valid:
        raise TopologicalError('Invalid polygon')
    minx, miny, maxx, maxy = polygon.bounds
    cell_size = min(maxx - minx, maxy - miny)
    h = cell_size / 2.0
    cell_queue = []

    # First best cell approximation is one constructed from the centroid
    # of the polygon
    x, y = polygon.centroid.coords[0]
    best_cell = Cell(x, y, 0, polygon)

    # build a regular square grid covering the polygon
    x = minx
    while x < maxx:
        y = miny
        while y < maxy:
            heappush(cell_queue, Cell(x + h, y + h, h, polygon))
            y += cell_size
        x += cell_size

    # minimum priority queue
    while cell_queue:
        cell = heappop(cell_queue)

        # update the best cell if we find a better one
        if cell.distance > best_cell.distance:
            best_cell = cell

        # continue to the next iteration if we cant find a better solution
        # based on tolerance
        if cell.max_distance - best_cell.distance <= tolerance:
            continue

        # split the cell into quadrants
        h = cell.h / 2.0
        heappush(cell_queue, Cell(cell.x - h, cell.y - h, h, polygon))
        heappush(cell_queue, Cell(cell.x + h, cell.y - h, h, polygon))
        heappush(cell_queue, Cell(cell.x - h, cell.y + h, h, polygon))
        heappush(cell_queue, Cell(cell.x + h, cell.y + h, h, polygon))

    return best_cell.centroid
def polylabel ( polygon , tolerance = 1.0 ) : if not polygon . is_valid : raise TopologicalError ( 'Invalid polygon' ) minx , miny , maxx , maxy = polygon . bounds cell_size = min ( maxx - minx , maxy - miny ) h = cell_size / 2.0 cell_queue = [ ] # First best cell approximation is one constructed from the centroid # of the polygon x , y = polygon . centroid . coords [ 0 ] best_cell = Cell ( x , y , 0 , polygon ) # build a regular square grid covering the polygon x = minx while x < maxx : y = miny while y < maxy : heappush ( cell_queue , Cell ( x + h , y + h , h , polygon ) ) y += cell_size x += cell_size # minimum priority queue while cell_queue : cell = heappop ( cell_queue ) # update the best cell if we find a better one if cell . distance > best_cell . distance : best_cell = cell # continue to the next iteration if we cant find a better solution # based on tolerance if cell . max_distance - best_cell . distance <= tolerance : continue # split the cell into quadrants h = cell . h / 2.0 heappush ( cell_queue , Cell ( cell . x - h , cell . y - h , h , polygon ) ) heappush ( cell_queue , Cell ( cell . x + h , cell . y - h , h , polygon ) ) heappush ( cell_queue , Cell ( cell . x - h , cell . y + h , h , polygon ) ) heappush ( cell_queue , Cell ( cell . x + h , cell . y + h , h , polygon ) ) return best_cell . centroid