(output, settings)
return transects
Draw shore-normal transects interactively on top of the mapped shorelines

    KV WRL 2018       

    Arguments:
    -----------
    output: dict
        contains the extracted shorelines and corresponding metadata
    settings: dict with the following keys
        'inputs': dict
            input parameters (sitename, filepath, polygon, dates, sat_list)
            
    Returns:    
    -----------
    transects: dict
        contains the X and Y coordinates of all the transects drawn.
        Also saves the coordinates as a .geojson as well as a .jpg figure 
        showing the location of the transects.
Draw shore-normal transects interactively on top of the mapped shorelines
Draw shore - normal transects interactively on top of the mapped shorelines
def draw_transects(output, settings):
    """
    Draw shore-normal transects interactively on top of the mapped shorelines

    KV WRL 2018       

    Arguments:
    -----------
    output: dict
        contains the extracted shorelines and corresponding metadata
    settings: dict with the following keys
        'inputs': dict
            input parameters (sitename, filepath, polygon, dates, sat_list)
            
    Returns:    
    -----------
    transects: dict
        contains the X and Y coordinates of all the transects drawn.
        Also saves the coordinates as a .geojson as well as a .jpg figure 
        showing the location of the transects.       
    """   
    
    sitename = settings['inputs']['sitename']
    filepath = os.path.join(settings['inputs']['filepath'], sitename)

    # plot the mapped shorelines
    fig1 = plt.figure()
    ax1 = fig1.add_subplot(111)
    ax1.axis('equal')
    ax1.set_xlabel('Eastings [m]')
    ax1.set_ylabel('Northings [m]')
    ax1.grid(linestyle=':', color='0.5')
    for i in range(len(output['shorelines'])):
        sl = output['shorelines'][i]
        date = output['dates'][i]
        ax1.plot(sl[:, 0], sl[:, 1], '.', markersize=3, label=date.strftime('%d-%m-%Y'))
#    ax1.legend()
    fig1.set_tight_layout(True)
    mng = plt.get_current_fig_manager()                                         
    mng.window.showMaximized()
    ax1.set_title('Click two points to define each transect (first point is the ' +
                  'origin of the transect and is landwards, second point seawards).\n'+
                  'When all transects have been defined, click on <ENTER>', fontsize=16)
    
    # initialise transects dict
    transects = dict([])
    counter = 0
    # loop until user breaks it by click <enter>
    while 1:
        # let user click two points
        pts = ginput(n=2, timeout=-1)
        if len(pts) > 0:
            origin = pts[0]
        # if user presses <enter>, no points are selected
        else:
            # save figure as .jpg
            fig1.gca().set_title('Transect locations', fontsize=16)
            fig1.savefig(os.path.join(filepath, 'jpg_files', sitename + '_transect_locations.jpg'), dpi=200)
            plt.title('Transect coordinates saved as ' + sitename + '_transects.geojson')
            plt.draw()
            # wait 2 seconds for user to visualise the transects that are saved
            ginput(n=1, timeout=2, show_clicks=True)
            plt.close(fig1)
            # break the loop
            break
        
        # add selectect points to the transect dict
        counter = counter + 1
        transect = np.array([pts[0], pts[1]])
        
        # alternative of making the transect the origin, orientation and length
#        temp = np.array(pts[1]) - np.array(origin)
#        phi = np.arctan2(temp[1], temp[0])
#        orientation = -(phi*180/np.pi - 90)
#        length = np.linalg.norm(temp)
#        transect = create_transect(origin, orientation, length)
        
        transects[str(counter)] = transect
        
        # plot the transects on the figure
        ax1.plot(transect[:,0], transect[:,1], 'b-', lw=2.5)
        ax1.plot(transect[0,0], transect[0,1], 'rx', markersize=10)
        ax1.text(transect[-1,0], transect[-1,1], str(counter), size=16,
                 bbox=dict(boxstyle="square", ec='k',fc='w'))
        plt.draw()
        
    # save transects.geojson
    gdf = SDS_tools.transects_to_gdf(transects)
    # set projection
    gdf.crs = {'init':'epsg:'+str(settings['output_epsg'])}
    # save as geojson    
    gdf.to_file(os.path.join(filepath, sitename + '_transects.geojson'), driver='GeoJSON', encoding='utf-8')
    # print the location of the files
    print('Transect locations saved in ' + filepath)
        
    return transects
def draw_transects ( output , settings ) : sitename = settings [ 'inputs' ] [ 'sitename' ] filepath = os . path . join ( settings [ 'inputs' ] [ 'filepath' ] , sitename ) # plot the mapped shorelines fig1 = plt . figure ( ) ax1 = fig1 . add_subplot ( 111 ) ax1 . axis ( 'equal' ) ax1 . set_xlabel ( 'Eastings [m]' ) ax1 . set_ylabel ( 'Northings [m]' ) ax1 . grid ( linestyle = ':' , color = '0.5' ) for i in range ( len ( output [ 'shorelines' ] ) ) : sl = output [ 'shorelines' ] [ i ] date = output [ 'dates' ] [ i ] ax1 . plot ( sl [ : , 0 ] , sl [ : , 1 ] , '.' , markersize = 3 , label = date . strftime ( '%d-%m-%Y' ) ) #    ax1.legend() fig1 . set_tight_layout ( True ) mng = plt . get_current_fig_manager ( ) mng . window . showMaximized ( ) ax1 . set_title ( 'Click two points to define each transect (first point is the ' + 'origin of the transect and is landwards, second point seawards).\n' + 'When all transects have been defined, click on <ENTER>' , fontsize = 16 ) # initialise transects dict transects = dict ( [ ] ) counter = 0 # loop until user breaks it by click <enter> while 1 : # let user click two points pts = ginput ( n = 2 , timeout = - 1 ) if len ( pts ) > 0 : origin = pts [ 0 ] # if user presses <enter>, no points are selected else : # save figure as .jpg fig1 . gca ( ) . set_title ( 'Transect locations' , fontsize = 16 ) fig1 . savefig ( os . path . join ( filepath , 'jpg_files' , sitename + '_transect_locations.jpg' ) , dpi = 200 ) plt . title ( 'Transect coordinates saved as ' + sitename + '_transects.geojson' ) plt . draw ( ) # wait 2 seconds for user to visualise the transects that are saved ginput ( n = 1 , timeout = 2 , show_clicks = True ) plt . close ( fig1 ) # break the loop break # add selectect points to the transect dict counter = counter + 1 transect = np . array ( [ pts [ 0 ] , pts [ 1 ] ] ) # alternative of making the transect the origin, orientation and length #        temp = np.array(pts[1]) - np.array(origin) #        phi = np.arctan2(temp[1], temp[0]) #        orientation = -(phi*180/np.pi - 90) #        length = np.linalg.norm(temp) #        transect = create_transect(origin, orientation, length) transects [ str ( counter ) ] = transect # plot the transects on the figure ax1 . plot ( transect [ : , 0 ] , transect [ : , 1 ] , 'b-' , lw = 2.5 ) ax1 . plot ( transect [ 0 , 0 ] , transect [ 0 , 1 ] , 'rx' , markersize = 10 ) ax1 . text ( transect [ - 1 , 0 ] , transect [ - 1 , 1 ] , str ( counter ) , size = 16 , bbox = dict ( boxstyle = "square" , ec = 'k' , fc = 'w' ) ) plt . draw ( ) # save transects.geojson gdf = SDS_tools . transects_to_gdf ( transects ) # set projection gdf . crs = { 'init' : 'epsg:' + str ( settings [ 'output_epsg' ] ) } # save as geojson     gdf . to_file ( os . path . join ( filepath , sitename + '_transects.geojson' ) , driver = 'GeoJSON' , encoding = 'utf-8' ) # print the location of the files print ( 'Transect locations saved in ' + filepath ) return transects