def linestrings_intersect(line1, line2):
    """
    To valid whether linestrings from geojson are intersected with each other.
    reference: http://www.kevlindev.com/gui/math/intersection/Intersection.js

    Keyword arguments:
    line1 -- first line geojson object
    line2 -- second line geojson object

    if(line1 intersects with other) return intersect point array else empty array
    """
    intersects = []
    for i in range(0, len(line1['coordinates']) - 1):
        for j in range(0, len(line2['coordinates']) - 1):
            a1_x = line1['coordinates'][i][1]
            a1_y = line1['coordinates'][i][0]
            a2_x = line1['coordinates'][i + 1][1]
            a2_y = line1['coordinates'][i + 1][0]
            b1_x = line2['coordinates'][j][1]
            b1_y = line2['coordinates'][j][0]
            b2_x = line2['coordinates'][j + 1][1]
            b2_y = line2['coordinates'][j + 1][0]
            ua_t = (b2_x - b1_x) * (a1_y - b1_y) - (b2_y - b1_y) * (a1_x - b1_x
                )
            ub_t = (a2_x - a1_x) * (a1_y - b1_y) - (a2_y - a1_y) * (a1_x - b1_x
                )
            u_b = (b2_y - b1_y) * (a2_x - a1_x) - (b2_x - b1_x) * (a2_y - a1_y)
            if not u_b == 0:
                u_a = ua_t / u_b
                u_b = ub_t / u_b
                if 0 <= u_a and u_a <= 1 and 0 <= u_b and u_b <= 1:
                    intersects.append({'type': 'Point', 'coordinates': [
                        a1_x + u_a * (a2_x - a1_x), a1_y + u_a * (a2_y -
                        a1_y)]})
    return intersects
