<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def CreateNetworkConnectivity(in_drainage_line, river_id, next_down_id, out_connectivity_file, file_geodatabase=None):
 """ Creates Network Connectivity input CSV file for RAPID based on the Drainage Line shapefile with river ID and next downstream ID fields. Parameters in_drainage_line: str Path to the stream network (i.e. Drainage Line) shapefile. river_id: str The name of the field with the river ID (Ex. 'HydroID', 'COMID', or 'LINKNO'). next_down_id: str The name of the field with the river ID of the next downstream river segment (Ex. 'NextDownID' or 'DSLINKNO'). out_connectivity_file: str The path to the output connectivity file. file_geodatabase Path to the file geodatabase. If you use this option, in_drainage_line is the name of the stream network feature class. (WARNING: Not always stable with GDAL.) Example:: from RAPIDpy.gis.network import CreateNetworkConnectivity CreateNetworkConnectivity( in_drainage_line='/path/to/drainageline.shp', river_id='LINKNO', next_down_id='DSLINKNO', out_connectivity_file='/path/to/rapid_connect.csv') """

    ogr_drainage_line_shapefile_lyr, ogr_drainage_line_shapefile = \
        open_shapefile(in_drainage_line, file_geodatabase)

    stream_id_array = []
    next_down_id_array = []
    for drainage_line_feature in ogr_drainage_line_shapefile_lyr:
        stream_id_array.append(drainage_line_feature.GetField(river_id))
        next_down_id_array.append(drainage_line_feature.GetField(next_down_id))

    stream_id_array = np.array(stream_id_array, dtype=np.int32)
    next_down_id_array = np.array(next_down_id_array, dtype=np.int32)

    StreamIDNextDownIDToConnectivity(stream_id_array,
                                     next_down_id_array,
                                     out_connectivity_file)

    del ogr_drainage_line_shapefile