def nearest_pillars(line_list, grid, ref_k = 0, ref_kp = 0):
    """Finds pillars nearest to each point on each line; returns list of lists of (j0, i0).

    arguments:
       line_list (list of numpy arrays of floats): set of poly-lines, the points of which are used
          to find the nearest pillars in grid
       grid (grid.Grid object): the grid whose pillars are compared with the poly-line vertices
       ref_k (integer, default 0): the reference layer in the grid to compare against the vertices;
          zero based
       ref_kp (integer, default 0): 0 to indicate the top corners of the reference layer, 1 for the base

    returns:
       a list of lists of pairs of integers, each being the (j, i) pillar indices of the nearest pillar
       to the corresponding vertex of the poly-line; zero based indexing

    notes:
       this is a 2D search in the x, y plane; z values are ignored;
       poly-line x, y values must implicitly be in the same crs as the grid's points data
    """

    pillar_list_list = []
    for line in line_list:
        pillar_list = []
        p_count = line.shape[0]
        for p in range(p_count):
            xy = line[p, 0:2]
            ji = grid.nearest_pillar(xy, ref_k0 = ref_k + ref_kp)
            pillar_list.append(ji)
        pillar_list_list.append(pillar_list)
    return pillar_list_list