class WSEL_Intersects:
    def __init__(self, config):
        self.config = config

    def __enter__(self):
        self.scratchgdb = self.config["scratchgdb"]
        self.streams_original = self.config["streams_original"]
        self.streams_intersect_dataset = self.config["streams_intersect_dataset"]
        self.streams_dataset = self.config["streams_dataset"]
        self.multi = self.config["multiproc"]
        self.modelbuilder = self.config["modelbuilder"]
        self.print_config = {"multi": self.multi, "modelbuilder": self.modelbuilder}
        self.safe_print = Safe_Print(self.print_config)
        env.workspace = self.scratchgdb
        env.overwriteOutput = True
        env.MResolution = 0.0001
        env.MDomain = "0 10000000"
        env.outputMFlag = "Enabled"
        env.outputZFlag = "Enabled"
        return self

    def __exit__(self, type, value, traceback):
        return self

    def get_intersect_all(self, comb_streams):
        self.safe_print.print_out("Intersecting all streams")
        env.workspace = self.streams_dataset
        streams_intersect = []
        tempLayer = "streamLayer"
        streamLayer = "streamsAll"
        expression = """ "Route_ID" = "Route_ID_1" """
        fieldName = "WSEL"
        stream_array = [fc for fc in arcpy.ListFeatureClasses() if fc.endswith("_stream_feature")]
        clusterTolerance = 0
        for stream in stream_array:
            sep = "_"
            name = stream.split(sep, 1)[0]
            self.safe_print.print_out("Intersecting " + name)
            expression2 = """ "Route_ID" <>""" + "'" + name + "'"
            arcpy.SelectLayerByAttribute_management(comb_streams, "NEW_SELECTION", expression2)
            outFeature = self.streams_intersect_dataset + "/" + name + "_pt_intersect"
            streams_intersect.append(outFeature)
            pt = arcpy.Intersect_analysis([stream, comb_streams], outFeature, "ALL", clusterTolerance, "POINT")
            arcpy.AddXY_management(pt)
            arcpy.AddField_management(pt, fieldName, "FLOAT", 10, 3)
            arcpy.MakeFeatureLayer_management(pt, tempLayer)
            arcpy.SelectLayerByAttribute_management(tempLayer, "NEW_SELECTION", expression)

            if int(arcpy.GetCount_management(tempLayer).getOutput(0)) > 0:
                arcpy.DeleteFeatures_management(tempLayer)

        env.workspace = scratchgdb
        return

    def processStream(self):
        comb_streams = self.scratchgdb + "\\streams_all"
        streams_layer = arcpy.MakeFeatureLayer_management(comb_streams, "streams_lyr")
        intersect = self.get_intersect_all(streams_layer)
        return intersect
Example #2
0
 def __enter__(self):
     self.scratch = self.config['scratch']
     self.table_folder =self.config['table_folder']
     self.scratchgdb = self.config['scratchgdb']
     self.xs_original = self.config['xs_original']
     self.output_workspace = self.config['output_workspace']
     self.xs_dataset = self.config['xs_dataset']
     self.streams_original = self.config['streams_original']
     self.flood_original =self.config['flood_original']
     self.xs_intersect_dataset = self.config['xs_intersect_dataset']
     self.streams_intersect_dataset = self.config['streams_intersect_dataset']
     self.routes_dataset = self.config['routes_dataset']
     self.streams_dataset = self.config['streams_dataset']
     self.vertices_dataset = self.config['vertices_dataset']
     self.streams_zm =self.config['streams_zm']
     self.backwater =self.config['backwater']
     self.sr = self.config['sr']
     self.multi=self.config['multiproc']
     self.modelbuilder=self.config['modelbuilder']
     self.print_config = {'multi': self.multi, 'modelbuilder': self.modelbuilder}
     self.safe_print = Safe_Print(self.print_config)
     env.workspace = self.scratch
     #env.parallelProcessingFactor = "4"
     env.overwriteOutput = True
     env.MResolution = 0.0001
     env.MDomain = "0 10000000"
     env.outputMFlag = "Enabled"
     env.outputZFlag = "Enabled"
     return self
class WSEL_Stream_Setup:

    def __init__(self, config, streams):
        self.streams = streams
        self.config = config
        arcpy.CheckOutExtension("3D")

    def __enter__(self):
        self.scratchgdb = self.config['scratchgdb']
        self.streams_original = self.config['streams_original']
        self.streams_dataset = self.config['streams_dataset']
        self.rid_field = self.config['rid_field']
        self.multi=self.config['multiproc']
        self.modelbuilder=self.config['modelbuilder']
        self.print_config = {'multi': self.multi, 'modelbuilder': self.modelbuilder}
        self.safe_print = Safe_Print(self.print_config)
        env.workspace = self.scratchgdb
        env.overwriteOutput = True
        env.MResolution = 0.0001
        env.MDomain = "0 10000000"
        env.outputMFlag = "Enabled"
        env.outputZFlag = "Enabled"
        return self

    def __exit__(self, type, value, traceback):
        return self

    def processStream(self):
        for stream in self.streams:
            name = stream
            self.safe_print.print_out("Configuring stream "+name)
            expression = "'"+name+"'"
            stream =arcpy.CopyFeatures_management(self.streams_original+"\\"+name+"_stream_feature", self.streams_dataset+"\\"+name+"_stream_feature" )
            arcpy.AddField_management(stream, "strm_length", "FLOAT",10,3)
            arcpy.CalculateField_management(stream, "strm_length", "float(!SHAPE.LENGTH!)","PYTHON")
            arcpy.AddField_management(stream,"Route_ID","TEXT","","",50)
            arcpy.CalculateField_management(stream,"Route_ID",expression,"PYTHON")
        return self.streams
 def __enter__(self):
     self.scratchgdb = self.config["scratchgdb"]
     self.streams_original = self.config["streams_original"]
     self.streams_intersect_dataset = self.config["streams_intersect_dataset"]
     self.streams_dataset = self.config["streams_dataset"]
     self.multi = self.config["multiproc"]
     self.modelbuilder = self.config["modelbuilder"]
     self.print_config = {"multi": self.multi, "modelbuilder": self.modelbuilder}
     self.safe_print = Safe_Print(self.print_config)
     env.workspace = self.scratchgdb
     env.overwriteOutput = True
     env.MResolution = 0.0001
     env.MDomain = "0 10000000"
     env.outputMFlag = "Enabled"
     env.outputZFlag = "Enabled"
     return self
 def __enter__(self):
     self.scratchgdb = self.config['scratchgdb']
     self.streams_original = self.config['streams_original']
     self.streams_dataset = self.config['streams_dataset']
     self.rid_field = self.config['rid_field']
     self.multi=self.config['multiproc']
     self.modelbuilder=self.config['modelbuilder']
     self.print_config = {'multi': self.multi, 'modelbuilder': self.modelbuilder}
     self.safe_print = Safe_Print(self.print_config)
     env.workspace = self.scratchgdb
     env.overwriteOutput = True
     env.MResolution = 0.0001
     env.MDomain = "0 10000000"
     env.outputMFlag = "Enabled"
     env.outputZFlag = "Enabled"
     return self
Example #6
0
class WSEL_Step_2:

    def __init__(self, config, streams):
        self.config = config
        self.streams = streams

    def __enter__(self):
        self.scratchgdb = self.config['scratchgdb']
        self.xs_original = self.config['xs_original']
        self.xs_dataset = self.config['xs_dataset']
        self.streams_original = self.config['streams_original']
        self.xs_intersect_dataset = self.config['xs_intersect_dataset']
        self.streams_intersect_dataset = self.config['streams_intersect_dataset']
        self.routes_dataset = self.config['routes_dataset']
        self.streams_dataset = self.config['streams_dataset']
        self.vertices_dataset = self.config['vertices_dataset']
        self.multi=self.config['multiproc']
        self.modelbuilder=self.config['modelbuilder']
        self.print_config = {'multi': self.multi, 'modelbuilder': self.modelbuilder}
        self.safe_print = Safe_Print(self.print_config)
        env.workspace = self.scratchgdb
        env.overwriteOutput = True
        env.MResolution = 0.0001
        env.MDomain = "0 10000000"
        env.outputMFlag = "Enabled"
        env.outputZFlag = "Enabled"
        return self

    def __exit__(self, type, value, traceback):
        return self

    #Intersects stream with completed streams
    #may want to put cluster tolerance to 0
    def get_intersect_all(self,comb_streams,name):
        self.safe_print.print_out("Intersecting all streams")
        env.workspace = self.routes_dataset        
        
        tempLayer = "streamLayer"

        keep_fields =['Route_ID','WSEL','Intersects','XS_Section']
        expression = """ "Route_ID" = "Intersects" """
        expression2 = "[POINT_Z]"
        expression4 = "[Route_ID]"
        expression5 = "[Route_ID_1]"
        expression6 = "[POINT_M]"

        
        stream = self.routes_dataset +'\\'+name+'_stream_routes'
        clusterTolerance = 0        
        self.safe_print.print_out("Intersecting "+name)              
        outFeature = self.streams_intersect_dataset+"/"+name+'_pt_intersect'        
        pt = arcpy.Intersect_analysis([comb_streams,stream], outFeature, "ALL", clusterTolerance, "POINT")
        arcpy.AddXY_management(pt)
        arcpy.AddField_management(pt, "WSEL", "FLOAT",10,3)
        arcpy.AddField_management(pt,'Intersects',"TEXT","","",50)
        arcpy.AddField_management(pt,'XS_Section',"FLOAT",10,3)
        arcpy.CalculateField_management(pt, "WSEL", expression2, "VB")
        arcpy.CalculateField_management(pt, "Intersects", expression4, "VB")
        arcpy.CalculateField_management(pt, "Route_ID", expression5, "VB")
        arcpy.CalculateField_management(pt, "XS_Section", expression6, "VB")
        fields = [f.name for f in arcpy.ListFields(pt) if not f.required and f.name not in keep_fields ]
        arcpy.DeleteField_management(pt, fields)
        arcpy.MakeFeatureLayer_management(pt, tempLayer)
        arcpy.SelectLayerByAttribute_management(tempLayer, "NEW_SELECTION",expression)
        if int(arcpy.GetCount_management(tempLayer).getOutput(0)) > 0:
            arcpy.DeleteFeatures_management(tempLayer)

        env.workspace = scratchgdb
        return

    def processStream(self):
        all_streams = self.streams
        env.overwriteOutput = True
        for streams in all_streams:
            name = streams
            comb_streams = self.scratchgdb+'\\streams_all'
            streams_layer = arcpy.MakeFeatureLayer_management(comb_streams,"streams_lyr")
            self.get_intersect_all(streams_layer,name)
        return
Example #7
0
class WSEL_Step_3:

    def __init__(self, config, streams):
        self.config = config
        self.streams = streams

    def __enter__(self):
        self.scratchgdb = self.config['scratchgdb']
        self.xs_original = self.config['xs_original']
        self.xs_dataset = self.config['xs_dataset']
        self.streams_original = self.config['streams_original']
        self.xs_intersect_dataset = self.config['xs_intersect_dataset']
        self.streams_intersect_dataset = self.config['streams_intersect_dataset']
        self.routes_dataset = self.config['routes_dataset']
        self.streams_dataset = self.config['streams_dataset']
        self.vertices_dataset = self.config['vertices_dataset']
        self.multi=self.config['multiproc']
        self.modelbuilder=self.config['modelbuilder']
        self.print_config = {'multi': self.multi, 'modelbuilder': self.modelbuilder}
        self.safe_print = Safe_Print(self.print_config)
        env.workspace = self.scratchgdb
        env.overwriteOutput = True
        env.MResolution = 0.0001
        env.MDomain = "0 10000000"
        env.outputMFlag = "Enabled"
        env.outputZFlag = "Enabled"
        return self

    def __exit__(self, type, value, traceback):
        return self.warnings

    def remove_duplicate_pts(self, stream_intersects):
        ###THIS MAY NOT BE NEEDED WITH THE NEW PROCESS OF INTERSECTING
        self.safe_print.print_out("Removing duplicate intersection points keeping ones with higher WSEL")
        tempLayer = "intersectLayer"
        expression = """ "Intersects"='Delete' """
        comb_intersect = stream_intersects
        compare =[]

        cursor = arcpy.SearchCursor(comb_intersect, ['Route_ID','Intersects','WSEL', 'XS_Section'])

        for row in cursor:
            compare.append([row.getValue('Route_ID'),row.getValue('Intersects'),row.getValue('WSEL'),row.getValue('XS_Section')])
        del cursor

        cursor = arcpy.UpdateCursor(comb_intersect, ['Intersects', 'Route_ID','WSEL','XS_Section'])
        for row in cursor:
            intersect = row.getValue('Intersects')
            intersect_stream = row.getValue('Route_ID')
            intersect_WSEL = row.getValue('WSEL')
            for strm in compare:
                stream = strm[1]
                stream_name = strm[0]
                stream_WSEL = strm[2]
                if intersect == stream_name and intersect_stream == stream and intersect_WSEL < stream_WSEL:
                    #print(intersect_stream+": "+str(intersect_WSEL)+" "+stream_name+": "+str(stream_WSEL))
                    row.setValue("Intersects","Delete")
                    cursor.updateRow(row)
        del cursor

        arcpy.MakeFeatureLayer_management(comb_intersect, tempLayer)
        arcpy.SelectLayerByAttribute_management(tempLayer, "NEW_SELECTION",expression)
        if int(arcpy.GetCount_management(tempLayer).getOutput(0)) > 0:
            arcpy.DeleteFeatures_management(tempLayer)

        return
    #Will update xs with the backwater WSEL found by previous processes intersection
    def update_xs(self, intersect_fc, xs_name):
        self.safe_print.print_out("Updating All XS's with backwater WSEL")
        warning ={}
        error = 0
        env.workspace = self.xs_dataset
        #xs_array = arcpy.ListFeatureClasses()
        cursor = arcpy.SearchCursor(intersect_fc, ['Route_ID', 'Intersects','WSEL','XS_Section'])
        compare =[]
        

        for row in cursor:
            name = row.getValue('Route_ID')
            intersect_stream = row.getValue('Intersects')
            section = row.getValue('XS_Section')
            if section != 0 and name == xs_name:
                compare.append([name,row.getValue('WSEL'),section])
            else:
                error =error+1
                intersection = {name:intersect_stream}
                warning.update(intersection)

        del cursor
        
        for strm in compare:
            xs_name= strm[0]+"_xs"
            xs_WSEL= strm[1]
            cursor = arcpy.UpdateCursor(xs_name, ['Route_ID','WSEL','WSEL_REG','Backwater'])
            for row in cursor:
                original_wsel = row.getValue('WSEL')
                if original_wsel < xs_WSEL:
                    row.setValue("WSEL_REG",xs_WSEL)
                    row.setValue("Backwater","yes")
                    cursor.updateRow(row)
            del cursor
        env.workspace = self.scratchgdb
        return warning
        

    def processStream(self):
        self.warnings=[]
        all_streams = self.streams        
        for streams in all_streams:
            comb_intersect = self.scratchgdb+'\\streams_intersect_all_2'
            self.remove_duplicate_pts(comb_intersect)
            warning = self.update_xs(comb_intersect, streams)
            #self.update_xs(comb_intersect, streams)
            if warning != 'null':
                self.warnings.append(warning)
        return self.warnings
class WSEL_XS_Check:

    def __init__(self, config, streams):
        self.streams = streams
        self.config = config


    def __enter__(self):
        self.scratchgdb = self.config['scratchgdb']
        self.xs_original = self.config['xs_original']
        self.xs_dataset = self.config['xs_dataset']
        self.streams_original = self.config['streams_original']
        self.xs_intersect_dataset = self.config['xs_intersect_dataset']
        self.routes_dataset = self.config['routes_dataset']
        self.streams_dataset = self.config['streams_dataset']
        self.vertices_dataset = self.config['vertices_dataset']
        self.wsel_field =self.config['wsel_field']
        self.station_field =self.config['station_field']
        self.rid_field =self.config['rid_field']
        self.backwater = self.config['backwater']
        self.multi=self.config['multiproc']
        self.modelbuilder=self.config['modelbuilder']
        self.print_config = {'multi': self.multi, 'modelbuilder': self.modelbuilder}
        self.safe_print = Safe_Print(self.print_config)
        env.workspace = self.scratchgdb
        env.overwriteOutput = True
        env.MResolution = 0.0001
        env.MDomain = "0 10000000"
        env.outputMFlag = "Enabled"
        env.outputZFlag = "Enabled"
        return self

    def __exit__(self, type, value, traceback):
        return self.warnings

    def FieldExist(self,featureclass, fieldname):
        fieldList = arcpy.ListFields(featureclass, fieldname)
        fieldCount = len(fieldList)
        if (fieldCount == 1):
            return True
        else:
            return False

    def xs_check(self, xs, name):
        warning ={name:[]}
        expression = "["+self.wsel_field+"]"
        expression2 = "["+self.station_field+"]"
        expression3 = "'"+name+"'"

        arcpy.AddField_management(xs,'Valid',"Double")
        arcpy.AddField_management(xs,'WSEL',"FLOAT",10,3)
        arcpy.AddField_management(xs,'WSEL_REG',"FLOAT",10,3)
        arcpy.AddField_management(xs,'XS_Station',"FLOAT",10,3)
        arcpy.AddField_management(xs,'Route_ID',"TEXT","","",254)

        arcpy.CalculateField_management(xs, 'WSEL', expression, "VB")
        arcpy.CalculateField_management(xs, 'WSEL_REG', expression, "VB")
        arcpy.CalculateField_management(xs, 'XS_Station', expression2, "VB")
        arcpy.CalculateField_management(xs, 'Valid', "0", "VB")
        arcpy.CalculateField_management(xs, 'Route_ID', expression3, "PYTHON")

        if self.backwater == True:
            arcpy.AddField_management(xs,'Backwater',"TEXT","","",6)
            arcpy.CalculateField_management(xs, 'Backwater', "'no'", "PYTHON")


        cursor = arcpy.UpdateCursor(xs, fields='Valid; WSEL; XS_Station',sort_fields="XS_Station A")
        count = arcpy.GetCount_management(xs).getOutput(0)
        i=0
        error = 0
        prevrow =''
        for row in cursor:
            wsel = row.getValue('WSEL_REG')
            section =row.getValue('XS_Station')
            if section == 0:
               row.setValue("Valid",1)
               row.setValue("XS_Station",0.001)
               cursor.updateRow(row)
            if i == 0:
                prevrow = wsel
            if i != 0:
                previous = prevrow
                if previous> wsel:
                    error = error + 1
                    section = row.getValue('XS_Station')
                    self.safe_print.print_out("Section: " + str(section) + " invalid")
                    row.setValue("Valid",1)
                    row.setValue("WSEL",previous+0.001)
                    row.setValue("WSEL_REG",previous+0.001)
                    warning[name].append(section)
                    cursor.updateRow(row)
                wsel = row.getValue('WSEL_REG')
                prevrow = wsel
            i=i+1
        del row
        del cursor
        if error != 0:
            return warning
        else:
            return 'null'


    def processStream(self):
        self.warnings=[]
        for stream in self.streams:
            name = stream
            self.safe_print.print_out("XS Check processing stream "+name)
            xs = arcpy.FeatureToLine_management(self.xs_original+"\\"+name+"_xs", self.xs_dataset+"\\"+name+"_xs")
            warning = self.xs_check(xs, name)
            if warning != 'null':
                self.warnings.append(warning)
            
        return self.warnings
class WSEL_Intersects_Clean:

    def __init__(self, config):
        self.config = config

    def __enter__(self):
        self.scratchgdb = self.config['scratchgdb']
        self.xs_original = self.config['xs_original']
        self.xs_dataset = self.config['xs_dataset']
        self.streams_original = self.config['streams_original']
        self.xs_intersect_dataset = self.config['xs_intersect_dataset']
        self.streams_intersect_dataset = self.config['streams_intersect_dataset']
        self.routes_dataset = self.config['routes_dataset']
        self.streams_dataset = self.config['streams_dataset']
        self.vertices_dataset = self.config['vertices_dataset']
        self.multi=self.config['multiproc']
        self.modelbuilder=self.config['modelbuilder']
        self.print_config = {'multi': self.multi, 'modelbuilder': self.modelbuilder}
        self.safe_print = Safe_Print(self.print_config)
        env.workspace = self.scratchgdb
        env.overwriteOutput = True
        env.MResolution = 0.0001
        env.MDomain = "0 10000000"
        env.outputMFlag = "Enabled"
        env.outputZFlag = "Enabled"
        return self

    def __exit__(self, type, value, traceback):
        return


    def remove_duplicate_pts(self, stream_intersects):
        self.safe_print.print_out("Removing duplicate intersection points keeping ones with higher WSEL")
        tempLayer = "intersectLayer"
        expression = """ "Route_ID_1"='Delete' """
        expression2 = "[Route_ID]"
        expression3 = "[Route_ID_1]"
        expression4 = "[POINT_M]"
        keep_fields=['SHAPE', 'OBJECTID', 'Route_ID', 'Intersects','WSEL', 'Station','strm_length']
        comb_intersect = stream_intersects
        compare =[]
        fields = [f.name for f in arcpy.ListFields(comb_intersect)]

        cursor = arcpy.SearchCursor(comb_intersect, ['Route_ID','Route_ID_1','strm_length'])
        for row in cursor:
            compare.append([row.getValue('Route_ID'),row.getValue('Route_ID_1'),row.getValue('strm_length')])
        del row
        del cursor


        cursor = arcpy.UpdateCursor(comb_intersect,['Route_ID','Route_ID_1','strm_length'])
        for row in cursor:
            intersect = row.getValue('Route_ID_1')
            intersect_stream = row.getValue('Route_ID')
            intersect_length = int(row.getValue('strm_length'))


            for strm in compare:
                stream = strm[1]
                stream_name = strm[0]
                stream_length = int(strm[2])
                if intersect == stream_name and intersect_stream == stream and intersect_length < stream_length:
                    row.setValue("Route_ID_1","Delete")
                    cursor.updateRow(row)
        del row
        del cursor
        arcpy.AddField_management(comb_intersect,"Intersects","TEXT","","",50)
        arcpy.AddField_management(comb_intersect,'Station',"FLOAT",10,3)
        arcpy.CalculateField_management(comb_intersect, "Intersects", expression2, "VB")
        arcpy.CalculateField_management(comb_intersect, "Route_ID", expression3, "VB")
        arcpy.CalculateField_management(comb_intersect, "Station", expression4, "VB")
        arcpy.MakeFeatureLayer_management(comb_intersect, tempLayer)
        arcpy.SelectLayerByAttribute_management(tempLayer, "NEW_SELECTION",expression)
        if int(arcpy.GetCount_management(tempLayer).getOutput(0)) > 0:
            arcpy.DeleteFeatures_management(tempLayer)
        fields = [f.name for f in arcpy.ListFields(comb_intersect) if not f.required and f.name not in keep_fields ]
        arcpy.DeleteField_management(comb_intersect, fields)
        return



    def processStream(self):
        self.warnings=[]
        comb_intersect = self.scratchgdb+'\\streams_intersect_all_1'
        self.remove_duplicate_pts(comb_intersect)

        return
Example #10
0
class WSEL_Step_4:

    def __init__(self, config, streams):
        self.streams = streams
        self.config = config
        arcpy.CheckOutExtension("3D")

    def __enter__(self):
        self.scratch = self.config['scratch']
        self.table_folder =self.config['table_folder']
        self.scratchgdb = self.config['scratchgdb']
        self.xs_original = self.config['xs_original']
        self.output_workspace = self.config['output_workspace']
        self.xs_dataset = self.config['xs_dataset']
        self.streams_original = self.config['streams_original']
        self.flood_original =self.config['flood_original']
        self.xs_intersect_dataset = self.config['xs_intersect_dataset']
        self.streams_intersect_dataset = self.config['streams_intersect_dataset']
        self.routes_dataset = self.config['routes_dataset']
        self.streams_dataset = self.config['streams_dataset']
        self.vertices_dataset = self.config['vertices_dataset']
        self.streams_zm =self.config['streams_zm']
        self.backwater =self.config['backwater']
        self.sr = self.config['sr']
        self.multi=self.config['multiproc']
        self.modelbuilder=self.config['modelbuilder']
        self.print_config = {'multi': self.multi, 'modelbuilder': self.modelbuilder}
        self.safe_print = Safe_Print(self.print_config)
        env.workspace = self.scratch
        #env.parallelProcessingFactor = "4"
        env.overwriteOutput = True
        env.MResolution = 0.0001
        env.MDomain = "0 10000000"
        env.outputMFlag = "Enabled"
        env.outputZFlag = "Enabled"
        return self

    def __exit__(self, type, value, traceback):
        return

    #Gets intersection between stream's centerline and the stream's xs
    def get_intersection(self, stream, xs, name):
        self.safe_print.print_out("Getting Intersection between "+name+"'s Stream and XS files")
        inFeatures = [stream, xs]
        intersectOutput = self.xs_intersect_dataset+"/"+name+"_xs_pt"
        clusterTolerance = 0
        pt = arcpy.Intersect_analysis(inFeatures, intersectOutput, "ALL", clusterTolerance, "POINT")
        self.feature = arcpy.FeatureToPoint_management(pt, self.xs_intersect_dataset+"/"+name+"_xs_pt_feature","CENTROID")
        arcpy.Delete_management(pt)
        return self.feature

    #Creates zm attributes on the stream centerline using linear referencing tools
    def add_routes(self,stream,xs_pt,name,status):

        rid = "Route_ID"

        if status == 0:
            self.safe_print.print_out("Adding Z-values to Polyline ZM")
            mfield="WSEL_REG"
            stationList = [r[0] for r in arcpy.da.SearchCursor (xs_pt, ["XS_Station"])]#gives me a list of all the stations/profilem
            min_station = min(stationList)# gives me the minimum xs value(should be 0.01)
            if min_station > 0:
                self.safe_print.print_out("Creating zero station before processing")
                pts = self.add_zero_station(stream, xs_pt,min_station,name)
        if status == 1:
            self.safe_print.print_out("Adding M-values to Polyline ZM")
            mfield ="XS_Station"
            #need to add 0 station at beginning of line if there is none, other wise the tool may encounter a boundary error with
            #a m-value being less than 0
            stationList = [r[0] for r in arcpy.da.SearchCursor (xs_pt, [mfield])]#gives me a list of all the stations/profilem
            min_station = min(stationList)# gives me the minimum station value(should be 0.01)
            if min_station > 0:
                self.safe_print.print_out("Creating zero station before processing")
                pts = self.add_zero_station(stream, xs_pt,min_station,name)
            else:
                pts = xs_pt

        out_fc = self.routes_dataset+"/"+name+"_stream_routes" 
        rts = stream
        out_routes = self.routes_dataset+"\\stream_measures"
        route_evt_layer_temp =name+"_evt_lyr"
        route_evt_layer= self.scratch+"\\"+name+"_evt"
        props = "RID POINT MEAS"
        out_table =self.table_folder+"\\route_loc.dbf"

        route_meas = arcpy.CreateRoutes_lr(rts, rid, out_routes,"LENGTH", "#", "#", "UPPER_LEFT",1,0,"IGNORE", "INDEX")#creates an m field based on the length of the streamline
        loc_features = arcpy.LocateFeaturesAlongRoutes_lr(pts, route_meas, rid, "0", out_table, props, 'FIRST', 'NO_DISTANCE','NO_ZERO','FIELDS')#finds the points along the streamline based of the m-field found in previous process
        evt_lyr = arcpy.MakeRouteEventLayer_lr(route_meas, rid, loc_features, props, route_evt_layer_temp, "#",  "NO_ERROR_FIELD",  "NO_ANGLE_FIELD","NORMAL","ANGLE", "LEFT", "POINT")#creates a layer based of the route table from previous process
        lyr = arcpy.SaveToLayerFile_management(evt_lyr, route_evt_layer, "RELATIVE")#may or may not need to save layer to disc. I only did this when I was trying to use parrallel processing
        #depending on which time the process is called either the WSEL or Station field is used
        if status == 0:
            routes = arcpy.CalibrateRoutes_lr (route_meas, rid, lyr, rid, mfield, out_fc,"MEASURES","0","BETWEEN","BEFORE","AFTER","IGNORE","KEEP","INDEX")
        else:
            routes = arcpy.CalibrateRoutes_lr (route_meas, rid, lyr, rid, mfield, out_fc,"MEASURES","0","BETWEEN","NO_BEFORE","AFTER","IGNORE","KEEP","INDEX")
        arcpy.Delete_management(loc_features)
        arcpy.Delete_management(route_meas)
        arcpy.Delete_management(lyr)
        return routes



    def add_zero_station(self, stream, xs_pt, min_station, name):
        tempLayer="min_stationxs"
        temp_pt_Layer="zero_station"
        keep_fields = [f.name for f in arcpy.ListFields(xs_pt)]
        fieldName = "XS_Station"
        fieldName2 = "OBJECTID"
        sqlExp = "{0} = {1}".format(fieldName, min_station)
        sqlExp2 = "'{0}'".format(name)
        arcpy.MakeFeatureLayer_management(xs_pt, tempLayer)
        arcpy.SelectLayerByAttribute_management(tempLayer, "NEW_SELECTION", sqlExp)
        pts = arcpy.FeatureVerticesToPoints_management(stream, self.vertices_dataset+'/'+name+"_endpts","BOTH_ENDS")
        stream_startend= arcpy.FeatureToPoint_management(pts,self.vertices_dataset+'/'+ name+"_endpts_feature","CENTROID")
        arcpy.Delete_management(pts)
        arcpy.Near_analysis(tempLayer, stream_startend)
        start_oid =[r for r in arcpy.da.SearchCursor (xs_pt,("WSEL_REG","NEAR_FID"),where_clause=sqlExp)][0]        
        sqlExp3 = "{0} <> {1}".format(fieldName2, start_oid[1])
        arcpy.MakeFeatureLayer_management(stream_startend, temp_pt_Layer)
        arcpy.SelectLayerByAttribute_management(temp_pt_Layer, "NEW_SELECTION", sqlExp3)
        if int(arcpy.GetCount_management(temp_pt_Layer).getOutput(0)) > 0:
            arcpy.DeleteFeatures_management(temp_pt_Layer)
        arcpy.AddField_management(stream_startend,'XS_Station',"FLOAT")
        arcpy.CalculateField_management(stream_startend, 'XS_Station', 0, "VB")
        arcpy.AddField_management(stream_startend,'WSEL_REG',"FLOAT")
        arcpy.CalculateField_management(stream_startend, 'WSEL_REG', start_oid[0], "VB")
        arcpy.AddField_management(stream_startend,'Route_ID',"TEXT","","",50)
        arcpy.CalculateField_management(stream_startend, 'Route_ID', sqlExp2, "PYTHON")
        stream_start =[r for r in arcpy.da.SearchCursor (stream_startend,("Route_ID","WSEL_REG","XS_Station","Shape@XY"))]

        cursor = arcpy.da.InsertCursor(xs_pt, ("Route_ID","WSEL_REG","XS_Station","Shape@XY"))

        for row in stream_start:
            cursor.insertRow(row)
        fields = [f.name for f in arcpy.ListFields(xs_pt) if not f.required and f.name not in keep_fields ]
        arcpy.DeleteField_management(xs_pt, fields)
        return xs_pt


    def vertices_to_pts(self, feature,name):
        pts = arcpy.FeatureVerticesToPoints_management(feature, self.vertices_dataset+'/'+name+"_pts","ALL")
        self.verticies = arcpy.FeatureToPoint_management(pts,self.vertices_dataset+'/'+ name+"_vertices_feature","CENTROID")
        arcpy.Delete_management(pts)
        return self.verticies

    def processStream(self):
        all_streams = self.streams
        env.overwriteOutput = True
        for streams in all_streams:
            name = streams
            self.safe_print.print_out("Step 4 processing "+name)
            stream = self.streams_dataset+"\\"+name+"_stream_feature"
            xs = self.xs_dataset+'\\'+ name+'_xs'
            xs_intersect_pt = self.get_intersection(stream, xs, name)
            keep_fields = [f.name for f in arcpy.ListFields(stream)]
            routes = self.add_routes(stream, xs_intersect_pt, name, 0)
            streampt = self.vertices_to_pts(routes, name+'_stream')
            streamxy = arcpy.AddXY_management(streampt)
            dpts = arcpy.FeatureTo3DByAttribute_3d(streamxy, self.streams_zm+'/'+ name+"_pts_temp", 'POINT_M')
            dpts_clean = arcpy.FeatureToPoint_management(dpts, self.streams_zm+'/'+ name+"_pts_zm","CENTROID")
            arcpy.Delete_management(dpts)
            streamline = arcpy.PointsToLine_management(dpts_clean, self.streams_zm+'/'+ name+"_line_zm")
            updated_stream = arcpy.SpatialJoin_analysis(streamline, stream, self.streams_zm+'/'+ name+"_zm")
            fields = [f.name for f in arcpy.ListFields(updated_stream) if not f.required and f.name not in keep_fields ]
            arcpy.DeleteField_management(updated_stream, fields)
            routes = self.add_routes(updated_stream,xs_intersect_pt, name, 1)
            streampt = self.vertices_to_pts(routes, name+'_stream')
            streamxy = arcpy.AddXY_management(streampt)
            streamline = arcpy.PointsToLine_management(streamxy, self.streams_zm+'/'+ name+"_line_zm")
            updated_stream = arcpy.SpatialJoin_analysis(streamline, stream, self.routes_dataset+"/"+name+"_stream_routes")
            arcpy.DeleteField_management(updated_stream, fields)
        return