def get_centerlines_from_geom(
    geometry,
    segmentize_maxlen=0.5,
    max_points=3000,
    simplification=0.05,
    smooth_sigma=5,
    debug=False
    ):

    if geometry.geom_type == "MultiPolygon":
        out_centerlines = MultiLineString([
            get_centerlines_from_geom(subgeom, segmentize_maxlen)
            for subgeom in geometry
            if get_centerlines_from_geom(subgeom, segmentize_maxlen) != None
            ])
        return out_centerlines
    else:

        # Convert Polygon to Linestring.
        if len(geometry.interiors) > 0:
            boundary = geometry.exterior
        else:
            boundary = geometry.boundary

        # print list(boundary.coords)
        if debug:
            debug_output['original_points'] = MultiPoint([
                point
                for point in list(boundary.coords)
            ])

        # Convert to OGR object and segmentize.
        ogr_boundary = ogr.CreateGeometryFromWkb(boundary.wkb)
        ogr_boundary.Segmentize(segmentize_maxlen)
        segmentized = loads(ogr_boundary.ExportToWkt())

        # Get points.
        points = segmentized.coords

        # Simplify segmentized geometry if necessary. This step is required
        # as huge geometries slow down the centerline extraction significantly.
        tolerance = simplification
        while len(points) > max_points:
            # If geometry is too large, apply simplification until geometry
            # is simplified enough (indicated by the "max_points" value)
            tolerance += simplification
            simplified = boundary.simplify(tolerance)
            points = simplified.coords
        if debug:
            debug_output['segmentized_points'] = MultiPoint([
                point
                for point in points
            ])

        # Calculate Voronoi diagram.
        vor = Voronoi(points)
        if debug:
            debug_output['voronoi'] = multilinestring_from_voronoi(
                vor,
                geometry
            )

        # The next three steps are the most processing intensive and probably
        # not the most efficient method to get the skeleton centerline. If you
        # have any recommendations, I would be very happy to know.

        # Convert to networkx graph.
        graph = graph_from_voronoi(vor, geometry)

        # Get end nodes from graph.
        end_nodes = get_end_nodes(graph)

        if len(end_nodes) < 2:
            return None

        # Get longest path.
        longest_paths = get_longest_paths(
            end_nodes,
            graph
            )

        # get least curved path.
        best_path = get_least_curved_path(longest_paths[:5], vor.vertices)

        #print (best_path == longest_paths[0])

        #best_path = longest_paths[0]

        centerline = LineString(vor.vertices[best_path])
        if debug:
            debug_output['centerline'] = centerline

        # Simplify again to reduce number of points.
        # simplified = centerline.simplify(tolerance)
        # centerline = simplified


        # Smooth out geometry.
        centerline_smoothed = smooth_linestring(centerline, smooth_sigma)

        out_centerline = centerline_smoothed

        return out_centerline
(1, 2)
dataset/ETHPy150Open ungarj/label_centerlines/src_create_centerlines.py/get_centerlines_from_geom--crossover with--dataset/ETHPy150Open anandology/pyjamas/examples/libtest/CompileTest.py/CompileTest.test_discard_expressions