Exemplo n.º 1
0
def ImportIntAtt(Intersections, TrafficControl, Routes, RouteID, BMP, EMP,
                 AttTable, Fields, Output, OutputTable):
    def FindAngle(O, P):
        import math
        if P[0] == O[0]:
            if P[1] == O[1]:
                #arcpy.AddWarning(str(O) + str(P))
                return 0  #1
            else:
                if P[1] > O[1]:
                    return 90  #2
                if P[1] < O[1]:
                    return 270  #3
        else:
            if P[1] == O[1]:
                if P[0] > O[0]:
                    return 0  #4
                else:
                    return 180  #5
            else:
                if (P[0] - O[0]) > 0 and (P[1] - O[1]) > 0:
                    return math.degrees(
                        math.atan((P[1] - O[1]) / (P[0] - O[0])))  #6
                elif (P[0] - O[0]) > 0 and (P[1] - O[1]) < 0:
                    return 360 - math.degrees(
                        math.atan(-(P[1] - O[1]) / (P[0] - O[0])))  #7
                elif (P[0] - O[0]) < 0 and (P[1] - O[1]) > 0:
                    return 180 - math.degrees(
                        math.atan(-(P[1] - O[1]) / (P[0] - O[0])))  #8
                elif (P[0] - O[0]) < 0 and (P[1] - O[1]) < 0:
                    return 180 + math.degrees(
                        math.atan((P[1] - O[1]) / (P[0] - O[0])))

    def FindClosestPoint(PolylineList, IntPoint):
        n = len(PolylineList)
        Dist0 = ((PolylineList[0][0] - IntPoint[0])**2 +
                 (PolylineList[0][1] - IntPoint[1])**2)**0.5
        Distn = ((PolylineList[n - 1][0] - IntPoint[0])**2 +
                 (PolylineList[n - 1][1] - IntPoint[1])**2)**0.5
        if Dist0 <= Distn:
            return [PolylineList[0], PolylineList[1]]
        else:
            return [PolylineList[n - 1], PolylineList[n - 2]]

    Buffer = "80 Feet"
    Tolerance = "10 Feet"
    Int = common.CreateOutPath(MainFile=Output, appendix='Int', Extension='')
    arcpy.Intersect_analysis(in_features=Routes,
                             out_feature_class=Int,
                             join_attributes="ALL",
                             cluster_tolerance="-1 Unknown",
                             output_type="POINT")

    SPJ = common.CreateOutPath(MainFile=Output, appendix='SPJ', Extension='')
    arcpy.SpatialJoin_analysis(target_features=Int,
                               join_features=Intersections,
                               out_feature_class=SPJ,
                               join_operation="JOIN_ONE_TO_ONE",
                               join_type="KEEP_COMMON",
                               match_option="CLOSEST",
                               search_radius=Buffer,
                               distance_field_name="")

    arcpy.DeleteIdentical_management(in_dataset=SPJ,
                                     fields=arcpy.Describe(SPJ).ShapeFieldName,
                                     xy_tolerance="",
                                     z_tolerance="0")

    OrgFields = [f.name for f in arcpy.ListFields(Intersections)]
    arcpy.DeleteField_management(SPJ, [
        f.name for f in arcpy.ListFields(SPJ)
        if not f.required and not f.name in OrgFields
    ])

    arcpy.SpatialJoin_analysis(target_features=SPJ,
                               join_features=TrafficControl,
                               out_feature_class=Output,
                               join_operation="JOIN_ONE_TO_ONE",
                               join_type="KEEP_COMMON",
                               match_option="CLOSEST",
                               search_radius=Buffer,
                               distance_field_name="")

    OrgFields.extend(['TRAF_CONT', 'LEG_COUNT', 'PeerGroup_CH2M_TJM'])
    arcpy.DeleteField_management(Output, [
        f.name for f in arcpy.ListFields(Output)
        if not f.required and not f.name in OrgFields
    ])

    EventTable = common.CreateOutPath(MainFile=Output,
                                      appendix='EventTable',
                                      Extension='')
    arcpy.LocateFeaturesAlongRoutes_lr(in_features=Output,
                                       in_routes=Routes,
                                       route_id_field=RouteID,
                                       radius_or_tolerance=Tolerance,
                                       out_table=EventTable,
                                       out_event_properties=" ".join(
                                           [RouteID, "POINT", "MP"]),
                                       route_locations="ALL",
                                       in_fields="FIELDS",
                                       m_direction_offsetting="M_DIRECTON")

    # Milepost Correction
    EMPDict = {
        r.getValue('INVENTORY'): r.getValue('Shape').lastPoint.M
        for r in arcpy.SearchCursor(Routes)
    }
    r = 0
    uc = arcpy.UpdateCursor(EventTable)
    for r in uc:
        inv = r.getValue('INVENTORY')
        MP = r.getValue('MP')
        if MP < 0:
            r.setValue('MP', 0)
            uc.updateRow(r)
        if MP > EMPDict[inv]:
            r.setValue('MP', EMPDict[inv])
            uc.updateRow(r)
    del uc, r

    AllF = [f.name for f in arcpy.ListFields(AttTable)]
    MF = [f for f in Fields if not f in AllF]
    if not MF == []:
        print(str(MF) + ' not found in ' + AttTable)
    IRIS_Diss = common.CreateOutPath(MainFile=Output,
                                     appendix='diss',
                                     Extension='')
    arcpy.DissolveRouteEvents_lr(
        in_events=AttTable,
        in_event_properties=' '.join([RouteID, 'LINE', BMP, EMP]),
        dissolve_field=';'.join(Fields),
        out_table=IRIS_Diss,
        out_event_properties=' '.join([RouteID, 'LINE', BMP, EMP]),
        dissolve_type="DISSOLVE",
        build_index="INDEX")

    arcpy.OverlayRouteEvents_lr(
        in_table=EventTable,
        in_event_properties=' '.join([RouteID, 'POINT', 'MP']),
        overlay_table=IRIS_Diss,
        overlay_event_properties=' '.join([RouteID, 'LINE', BMP, EMP]),
        overlay_type="INTERSECT",
        out_table=OutputTable,
        out_event_properties=' '.join([RouteID, 'POINT', 'MP']),
        in_fields="FIELDS",
        build_index="INDEX")

    common.AddField(Output, [
        fields_SC.intr.AADT_Major, fields_SC.intr.AADT_Minor,
        fields_SC.crash.ABuffer, fields_SC.crash.BBuffer
    ])

    arcpy.AddField_management(OutputTable, 'ApprType', 'TEXT')
    #arcpy.AddField_management(OutputTable,'ApprDeg','Double')
    Approach = {r.getValue('SiteID'): [] for r in arcpy.SearchCursor(Output)}

    OID = arcpy.Describe(OutputTable).OIDFieldName
    for r in arcpy.SearchCursor(OutputTable):
        k = r.getValue('SiteID')
        if k in Approach.keys():
            Approach[k].append({
                'OID': r.getValue(OID),
                'INV': r.getValue('INVENTORY'),
                'AADT': common.GetIntVal(r, 'AADT'),
                'Lanes': common.GetIntVal(r, 'LNS', 2),
                'Urban': r.getValue('URBAN'),
                'SurfWid': common.GetFloatVal(r, 'SURF_WTH', 24),
                'MedWid': common.GetFloatVal(r, 'MED_WTH')
            })
    for k in Approach.keys():
        AADT = [i['AADT'] for i in Approach[k]]
        INV = [i['INV'] for i in Approach[k]]
        major_i = AADT.index(max(AADT))
        major_inv = INV[major_i]
        for i, appr in enumerate(Approach[k]):
            if appr['AADT'] == max(AADT) or appr['INV'] == major_inv:
                Approach[k][i].update({'ApprType': 'Major'})
            else:
                Approach[k][i].update({'ApprType': 'Minor'})

    UC = arcpy.UpdateCursor(OutputTable)
    for r in UC:
        k = r.getValue('SiteID')
        o = r.getValue(OID)
        Type = ''
        for appr in Approach[k]:
            if appr['OID'] == o:
                Type = appr['ApprType']
        r.setValue('ApprType', Type)

        UC.updateRow(r)

    UC = arcpy.UpdateCursor(Output)
    for r in UC:
        k = r.getValue('SiteID')
        try:
            r.setValue(
                fields_SC.intr.AADT_Major['name'],
                max([
                    appr['AADT'] for appr in Approach[k]
                    if appr['ApprType'] == 'Major'
                ]))
        except:
            r.setValue(fields_SC.intr.AADT_Major['name'], 0)
        try:
            r.setValue(
                fields_SC.intr.AADT_Minor['name'],
                max([
                    appr['AADT'] for appr in Approach[k]
                    if appr['ApprType'] == 'Minor'
                ]))
        except:
            r.setValue(fields_SC.intr.AADT_Minor['name'], 0)
        try:
            W_Major = max([
                appr['SurfWid'] + appr['MedWid'] for appr in Approach[k]
                if appr['ApprType'] == 'Major'
            ])
        except:
            W_Major = 24
        try:
            W_Minor = max([
                appr['SurfWid'] + appr['MedWid'] for appr in Approach[k]
                if appr['ApprType'] == 'Minor'
            ])
        except:
            W_Minor = 24
        ABuffer = max(1.2 * (W_Major**2 + W_Minor**2)**0.5, 50)
        r.setValue(fields_SC.crash.ABuffer['name'], ABuffer)
        r.setValue(fields_SC.crash.BBuffer['name'], max(ABuffer, 250))
        AADT = [i['AADT'] for i in Approach[k]]
        major_i = AADT.index(max(AADT))
        LaneMajor = [i['Lanes'] for i in Approach[k]][0]
        UC.updateRow(r)

    arcpy.Delete_management(Int)
    arcpy.Delete_management(EventTable)
    arcpy.Delete_management(SPJ)
    arcpy.Delete_management(IRIS_Diss)
Exemplo n.º 2
0
def ImportRoadwayData(Input, Route, AttTable, Fields, Output, RouteID, BMP,
                      EMP, XY_Tolerance):
    #Output should be on a GDB not a shapefile

    #Step 1: Create a route FC based on the input
    Sites_Event_Table = common.CreateOutPath(MainFile=Output,
                                             appendix='EventTab',
                                             Extension='')
    arcpy.LocateFeaturesAlongRoutes_lr(in_features=Input,
                                       in_routes=Route,
                                       route_id_field=RouteID,
                                       radius_or_tolerance=XY_Tolerance,
                                       out_table=Sites_Event_Table,
                                       out_event_properties=' '.join(
                                           [RouteID, 'LINE', BMP, EMP]),
                                       route_locations="FIRST",
                                       distance_field="DISTANCE",
                                       zero_length_events="ZERO",
                                       in_fields="FIELDS",
                                       m_direction_offsetting="M_DIRECTON")
    Sites_Event_Layer = common.CreateOutLayer('EventLayer')
    arcpy.MakeRouteEventLayer_lr(in_routes=Route,
                                 route_id_field=RouteID,
                                 in_table=Sites_Event_Table,
                                 in_event_properties=' '.join(
                                     [RouteID, 'LINE', BMP, EMP]),
                                 out_layer=Sites_Event_Layer,
                                 add_error_field="NO_ERROR_FIELD")

    Sites_Routes = common.CreateOutPath(MainFile=Output,
                                        appendix='route',
                                        Extension='')
    arcpy.CopyFeatures_management(in_features=Sites_Event_Layer,
                                  out_feature_class=Sites_Routes)

    IRIS_Diss = common.CreateOutPath(MainFile=Output,
                                     appendix='diss',
                                     Extension='')
    arcpy.DissolveRouteEvents_lr(
        in_events=AttTable,
        in_event_properties=' '.join([RouteID, 'LINE', BMP, EMP]),
        dissolve_field=';'.join(Fields),
        out_table=IRIS_Diss,
        out_event_properties=' '.join([RouteID, 'LINE', BMP, EMP]),
        dissolve_type="DISSOLVE",
        build_index="INDEX")

    Overlay_Event_Table1 = common.CreateOutPath(MainFile=Output,
                                                appendix='OverlayTab1',
                                                Extension='')
    arcpy.OverlayRouteEvents_lr(
        in_table=IRIS_Diss,
        in_event_properties=' '.join([RouteID, 'LINE', BMP, EMP]),
        overlay_table=Sites_Event_Table,
        overlay_event_properties=' '.join([RouteID, 'LINE', BMP, EMP]),
        overlay_type="INTERSECT",
        out_table=Overlay_Event_Table1,
        out_event_properties=' '.join([RouteID, 'LINE', BMP, EMP]),
        zero_length_events="NO_ZERO",
        in_fields="FIELDS",
        build_index="INDEX")

    Overlay_Event_Layer = common.CreateOutLayer('OverlayEventLayer')
    arcpy.MakeRouteEventLayer_lr(in_routes=Route,
                                 route_id_field=RouteID,
                                 in_table=Overlay_Event_Table1,
                                 in_event_properties=' '.join(
                                     [RouteID, 'LINE', BMP, EMP]),
                                 out_layer=Overlay_Event_Layer,
                                 offset_field="",
                                 add_error_field="ERROR_FIELD")

    Sites_segs1 = common.CreateOutPath(MainFile=Output,
                                       appendix='seg1',
                                       Extension='')
    arcpy.CopyFeatures_management(in_features=Overlay_Event_Layer,
                                  out_feature_class=Sites_segs1)

    #Curves_Table = common.CreateOutPath(MainFile=Output,appendix='curves',Extension='')
    #ExtractCurves(inp=Sites_segs1,IDField=RouteID,RMax=5280,RMin=10,DegMin=2,desd=1000,LenMin=1000,out=Curves_Table)

    #Overlay_Event_Table2 = common.CreateOutPath(MainFile=Output,appendix='OverlayTab2',Extension='')
    #arcpy.OverlayRouteEvents_lr(in_table = Overlay_Event_Table1,
    #                            in_event_properties = ' '.join([RouteID,'LINE',BMP,EMP]),
    #                            overlay_table = Curves_Table,
    #                            overlay_event_properties = ' '.join([RouteID,'LINE',BMP,EMP]),
    #                            overlay_type = "UNION",
    #                            out_table = Overlay_Event_Table2,
    #                            out_event_properties = ' '.join([RouteID,'LINE',BMP,EMP]),
    #                            zero_length_events = "NO_ZERO",
    #                            in_fields = "FIELDS",
    #                            build_index="INDEX")

    #Overlay_Event_Layer2 = common.CreateOutLayer('OverlayEventLayer2')
    #arcpy.MakeRouteEventLayer_lr(in_routes = Route,
    #                             route_id_field = RouteID,
    #                             in_table = Overlay_Event_Table2,
    #                             in_event_properties = ' '.join([RouteID,'LINE',BMP,EMP]),
    #                             out_layer = Overlay_Event_Layer2,
    #                             offset_field = "",
    #                             add_error_field = "ERROR_FIELD")

    Sort = common.CreateOutPath(MainFile=Output, appendix='sort', Extension='')
    arcpy.Sort_management(in_dataset=Sites_segs1,
                          out_dataset=Sort,
                          sort_field=';'.join([RouteID, BMP, EMP]))
    Final_Layer = common.CreateOutLayer('FinalLayer')

    arcpy.MakeFeatureLayer_management(in_features=Sort, out_layer=Final_Layer)
    arcpy.SelectLayerByAttribute_management(in_layer_or_view=Final_Layer,
                                            selection_type='NEW_SELECTION',
                                            where_clause="Shape_Length > 52")

    arcpy.Delete_management(Output)
    arcpy.MultipartToSinglepart_management(in_features=Final_Layer,
                                           out_feature_class=Output)
    arcpy.DeleteField_management(Output, 'ORIG_FID')
    FL = [
        f.name for f in arcpy.ListFields(Output)
        if f.name != arcpy.Describe(Output).OIDFieldName
    ]
    arcpy.DeleteIdentical_management(in_dataset=Output,
                                     fields=';'.join(FL),
                                     xy_tolerance="",
                                     z_tolerance="0")

    arcpy.Delete_management(Sites_Event_Table)
    arcpy.Delete_management(Sites_Event_Layer)
    arcpy.Delete_management(Sites_Routes)
    arcpy.Delete_management(IRIS_Diss)
    arcpy.Delete_management(Overlay_Event_Table1)
    arcpy.Delete_management(Overlay_Event_Layer)
    arcpy.Delete_management(Sites_segs1)
    #arcpy.Delete_management(Curves_Table)
    #arcpy.Delete_management(Overlay_Event_Table2)
    #arcpy.Delete_management(Overlay_Event_Layer2)
    arcpy.Delete_management(Sort)
    arcpy.Delete_management(Final_Layer)
Exemplo n.º 3
0
def Infrastructure(int_fc, int_roads, inventory, 
                    traffic, geometrics, urban, rural):
    """This function calculates the infrastructure score for all input 
    intersections. This is a composite score calculated from four main
    factors: daily total entering vehicles, total entering travel lanes,
    average speed limit, and intersection control type. The final output 
    is an infrastructure score field added to the input intersection point
    feature class. This function takes 5 arguments:

    int_fc - input intersection point feature class with unique ID for each
            intersection
    int_roads - TRIMS INTSECT_RDSYS table; contains route data for all roads
                at points of intersections
    inventory - TRIMS INTSECT_INV table; contains control data for all
                intersections
    traffic - TRIMS TRAFFIC table; contains traffic segment termini and AADT
                counts
    geometrics - TRIMS GEOMETRICS table; contains geometric road data, including
                speed limit and number of lanes"""

    # Create unique ID for each road at point of intersection
    ap.AddField_management(int_roads, "RtID", "TEXT")

    ap.CalculateField_management(
        int_roads, "RtID", 
        "str(!ID_NUMBER!) + str(!IS_LOG_MLE!)", "PYTHON3")
    ap.AddMessage("traffic")
    # Overlay intersection route table with traffic segments
    ap.OverlayRouteEvents_lr(
        int_roads, "ID_NUMBER POINT IS_LOG_MLE", traffic, 
        "ID_NUMBER LINE TR_BEG_LOG_MLE TR_END_LOG_MLE", 
        "INTERSECT", "Int_Traffic", "ID_NUMBER POINT LOG_MLE")

    # Calculate average AADT for traffic segments which split at an intersection
    # on the same route
    ap.Statistics_analysis("Int_Traffic", r"in_memory\Int_trf_stats", 
                            [["AADT", "MEAN"]], "RtID")

    ap.DeleteIdentical_management("Int_Traffic", ["RtID"])

    # Update AADT field in overlay table with updated values
    ap.MakeTableView_management("Int_Traffic", "Trf_view")

    ap.AddJoin_management("Trf_view", "RtID", 
                            r"in_memory\Int_trf_stats", "RtID")

    ap.CalculateField_management(
        "Trf_view", "AADT", "!Int_trf_stats.MEAN_AADT!", "PYTHON3")

    ap.RemoveJoin_management("Trf_view")

    ap.Delete_management(r"in_memory\Int_trf_stats")

    # Many intersecting roads are not coincident with traffic segments. A new
    # AADTCheck field is created which indicates whether or not all the roads
    # leading to an intersection have known AADTs

    def CheckNulls(int_fc, in_rows, ov_rows, in_f, out_f):

        ap.AddField_management(in_rows, "CheckField", "DOUBLE")

        ap.MakeTableView_management(in_rows, "rows_view")

        ap.AddJoin_management("rows_view", "RtID", 
                            ov_rows, "RtID")

        codeblock = [
        # This first field calculator function returns 1 when the input field
        # contains values, and 0 if it is null.
        """def NullVals(field):
            if field == None:
                return 0
            else: return 1""",

        # This second function is used to populate the final field indicating whether
        # the input data is complete or not
        """def status(mean_field):
            if mean_field < 1:
                return 'N'
            else: return 'Y'"""
            ]

        ap.CalculateField_management(
            "rows_view", "CheckField", "NullVals(!{}.{}!)".format(ov_rows, in_f), 
            "PYTHON3", codeblock[0])

        ap.Delete_management("rows_view")

        # Once a new field is calculated with the NullVals function, values with the 
        # same intersection ID are averaged together. A mean of 1 indicates data
        # completeness, less than 1 indicates at least one value is missing.

        ap.Statistics_analysis(in_rows, r"in_memory\stats_table",
                                [["CheckField", "MEAN"]], "ID")

        ap.AddField_management(int_fc, out_f, "TEXT")

        ap.MakeFeatureLayer_management(int_fc, "int_lyr")
        ap.AddJoin_management("int_lyr", "MSLINK", r"in_memory\stats_table", "ID")

        ap.CalculateField_management(
            "int_lyr", out_f, "status(!stats_table.MEAN_CheckField!)", 
            "PYTHON3", codeblock[1])
        ap.Delete_management(r"in_memory\stats_table")
        ap.Delete_management("int_lyr")
    ap.AddMessage("check traffic nulls")
    CheckNulls(int_fc, int_roads, "Int_Traffic", "AADT", "AllTraffic")

    # Finally, AADT values are summed for each intersection. These will later
    # be joined to the intersection point feature class

    ap.Statistics_analysis("Int_Traffic", r"in_memory\SumTraffic", 
                            [["AADT", "SUM"]], "ID")

    ap.Delete_management("Int_Traffic")

    # Speed limits over 70 in the geometric table are recalculated to null

    ap.MakeTableView_management(geometrics, "geo_view", "SPD_LMT > 70")
    ap.CalculateField_management(geometrics, "SPD_LMT", "None", "PYTHON3")
    ap.Delete_management("geo_view")
    # Overlay intersection route table with geometrics table
    ap.AddMessage("check speed and lane nulls")
    ap.OverlayRouteEvents_lr(
        int_roads, "ID_NUMBER POINT IS_LOG_MLE", geometrics, 
        "ID_NUMBER LINE RD_BEG_LOG_MLE RD_END_LOG_MLE", 
        "INTERSECT", "Int_Geo", "ID_NUMBER POINT LOG_MLE")

    # As with the traffic overlay, not all intersection routes will have known 
    # speed limits or lane counts, and they must be identified
    CheckNulls(int_fc, int_roads, "Int_Geo", "SPD_LMT", "AllSpeed")
    CheckNulls(int_fc, int_roads, "Int_Geo", "THRU_LANES", "AllLanes")
    # Summary statistics are used to calculate mean speed limit and total 
    # entering travel lanes for each intersection
    # These two tables will be used later to calculate the infrastructure
    # score
    ap.AddMessage("Get speed and lanes")
    ap.Statistics_analysis("Int_Geo", r"in_memory\MeanSpeed", 
                            [["SPD_LMT", "MEAN"]], "ID")

    ap.Statistics_analysis("Int_Geo", r"in_memory\SumLanes", 
                            [["THRU_LANES", "SUM"]], "ID")

    # Intersections are ranked by level of control, in order from most to least: 
    # signal, flashing red, flashing yellow, all-way stop, 2-way stop, 
    # 1-way stop, no control

    ap.AddField_management(inventory, "ctrl_raw", "DOUBLE")
    ap.AddMessage("get control scores")
    codeblock = [
        # This function is used to calculate control scores for each control type
    """def cScore(control):
        if control == 1:
            return 6
        elif control == 2:
            return 3
        elif control == 3:
            return 2
        elif control == 4:
            return 1
        elif control == 5:
            return 5
        elif control == 6:
            return 4""",
        # General function used when calculating final scores. Replaces nulls 
        # with zeros
    """def NoNulls(field):
        if field == None:
            return 0 
        else: return field"""
        ]

    ap.CalculateField_management(
        inventory, "ctrl_raw", "cScore(!ITM_CDE!)", 
        "PYTHON3", codeblock[0])

    ap.Statistics_analysis(inventory, r"in_memory\Int_ctrl", 
                            [["ctrl_raw", "MAX"]], "ID")    

    # The UorR field is added to identify intersections as either urban or rural.
    # The field is populated through a select by location

    ap.AddField_management(int_fc, "UorR", "TEXT")
    
    ap.MakeFeatureLayer_management(int_fc, "int_lyr")

    ap.SelectLayerByLocation_management(
        "int_lyr", "INTERSECT", urban, "", "NEW_SELECTION")
    ap.CalculateField_management("int_lyr", "UorR", "'Urban'", "PYTHON3")

    ap.SelectLayerByLocation_management(
        "int_lyr", "INTERSECT", urban, "", "NEW_SELECTION", "INVERT")
    ap.CalculateField_management("int_lyr", "UorR", "'Rural'")

    # Statistics tables for traffic, speed, lanes, and control are joined to 
    # the intersection feature class, and infrastructure score is calculated 
    # as the average of those 4 scores. Rural and urban intersections are 
    # scored separately

    inf_fields = [["SumTraffic", "traffic", "SUM_AADT"], 
    ["SumLanes", "lanes", "SUM_THRU_LANES"], 
    ["MeanSpeed", "speed", "MEAN_SPD_LMT"], 
    ["Int_ctrl", "control", "MAX_ctrl_raw"]]

    ap.AddMessage("Get final scores")
    for field in inf_fields:
        ap.AddField_management("int_lyr", field[1], "DOUBLE")
        ap.AddJoin_management("int_lyr", "MSLINK", 
                                r"in_memory\\" + field[0], "ID")
        ap.CalculateField_management(
            "int_lyr", field[1], 
            "NoNulls(!{}.{}!)".format(field[0], field[2]), 
            "PYTHON3", codeblock[1])
        ap.RemoveJoin_management("int_lyr")

        ap.MakeFeatureLayer_management("int_lyr", "int_urban", "UorR = 'Urban'")
        Rescale("int_urban", field[1], "{}_rescaled".format(field[1]))
        ap.Delete_management("int_urban")

        ap.MakeFeatureLayer_management("int_lyr", "int_rural", "UorR = 'Rural'")
        Rescale("int_rural", field[1], "{}_rescaled".format(field[1]))
        ap.Delete_management("int_rural")

        ap.Delete_management(r"in_memory\\" + field[0])

    ap.AddField_management(int_fc, "InfScore", "DOUBLE")
    ap.CalculateField_management(
        int_fc, "InfScore", 
        """(!traffic_rescaled!+!lanes_rescaled!
            +!speed_rescaled!+!control_rescaled!)/4""", "PYTHON3")    
arcpy.LocateFeaturesAlongRoutes_lr(CTPS_Model_Links, Selected_LRSN_Route,
                                   "route_id", "40 Meters", links_event_table,
                                   links_event_table_properties, "FIRST",
                                   "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON")
# Be sure to retain "LENGTH" field - the length of the ENTIRE model link

arcpy.AddMessage("Generating overlay.")
#
# HERE: tmc_event_table and links_event_table have been generated.
#       Generate overlay #1.
# Overlay Route Events: inputs: tmc_events, links_events
#                       output: overlay_events
overlay_event_table_properties = "route_id LINE from_meas to_meas"
arcpy.OverlayRouteEvents_lr(tmc_event_table, "route_id LINE from_meas to_meas",
                            links_event_table,
                            "route_id LINE from_meas to_meas", "UNION",
                            overlay_events, overlay_event_table_properties,
                            "NO_ZERO", "FIELDS", "INDEX")

# Rename two fields in the overlay table to make their meanings clearer:
#   lenmiles ==> tmc_lenmiles  (length, in miles, of the ENTIRE TMC)
#   LENGTH   ==> link_lenmiles (length, in miles, of the ENTIRE model link)
arcpy.AlterField_management(overlay_events, 'lenmiles', 'tmc_lenmiles')
arcpy.AlterField_management(overlay_events, 'LENGTH', 'link_lenmiles')

# Make Table View of overlay_events
arcpy.MakeTableView_management(overlay_events, overlay_events_View)

# Roads and Highways allows (among other things) events with measure values < 0. In particular, we are concerned with from_measure values < 0.
# Clean these up by setting the relevant from_measures to 0.
#
Exemplo n.º 5
0
                             "POINT")
arcpy.MakeRouteEventLayer_lr(clrs, "LRS_KEY", "Maint_tview",
                             "LRSKEY LINE BEGMILEPOST END_MP",
                             "Maint_Events_ln", "#", "ERROR_FIELD",
                             "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT",
                             "POINT")

arcpy.MakeRouteEventLayer_lr(clrs, "LRS_KEY", "GIS_DEV.CCL_Extents",
                             "LRS_KEY LINE BEG_CMP END_CMP", "GIS_CCL", "#",
                             "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL",
                             "ANGLE", "LEFT", "POINT")

arcpy.OverlayRouteEvents_lr(
    devpath + "GIS_DEV.CCL_Resolution",
    "LRS_KEY LINE BEG_CNTY_LOGMILE END_CNTY_LOGMILE", devpath + "LNCL_EVENT",
    "LRS_KEY LINE BEG_CNTY_LOGMILE END_CNTY_LOGMILE", "INTERSECT",
    r"Database Connections/SDEDEV_GISDEV.sde/GIS_DEV.CCL_Lanes",
    "LRS_KEY LINE BEG_CNTY_LOGMILE END_CNTY_LOGMILE", "NO_ZERO", "FIELDS",
    "INDEX")

arcpy.MakeRouteEventLayer_lr(clrs, "LRS_KEY", devpath + "CCL_Resolution",
                             "LRS_KEY LINE BEG_CNTY_LOGMILE END_CNTY_LOGMILE",
                             "CCL_Resolution_Events", "#", "ERROR_FIELD",
                             "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT",
                             "POINT")
arcpy.FeatureClassToGeodatabase_conversion("CCL_Resolution_Events",
                                           devpath + "KDOT_CCL_WORKSPACE")
arcpy.SplitLine_management(
    "Database Connections\SDEDEV.sde\SDE.KDOT_CCL_WORKSPACE\SDE.CCL_Resolution_Events",
    "Database Connections\SDEDEV.sde\SDE.KDOT_CCL_WORKSPACE\CCL_LN_SPEC")
#locate resolution mileage along state route to cross counties
                                   "DISTANCE", "NO_ZERO", "FIELDS",
                                   "M_DIRECTON")

# Delete un-needed fields from town_event_table
arcpy.DeleteField_management(town_event_table, "shape_leng;boundary_link_id")

arcpy.AddMessage("Generating overlay #1.")

# HERE: tmc_event_table and town_event_table have been generated.
#       Generate overlay #1.
# Overlay Route Events: inputs: overlay tmc_events, town_events
#                       output: overlay_events_1
overlay_event_table_1_properties = "route_id LINE from_meas to_meas"
arcpy.OverlayRouteEvents_lr(tmc_event_table, "route_id LINE from_meas to_meas",
                            town_event_table,
                            "route_id LINE from_meas to_meas", "UNION",
                            overlay_events_1, overlay_event_table_1_properties,
                            "NO_ZERO", "FIELDS", "INDEX")

# Make Feature Layer "Speed_Limit_Layer":
arcpy.MakeFeatureLayer_management(
    LRSE_Speed_Limit, Speed_Limit_Layer, "to_date IS NULL", "",
    "objectid objectid HIDDEN NONE;from_date from_date HIDDEN NONE;to_date to_date HIDDEN NONE;event_id event_id HIDDEN NONE;route_id route_id VISIBLE NONE;from_measure from_measure VISIBLE NONE;to_measure to_measure VISIBLE NONE;speed_lim speed_lim VISIBLE NONE;op_dir_sl op_dir_sl VISIBLE NONE;created_by created_by HIDDEN NONE;date_created date_created HIDDEN NONE;edited_by edited_by HIDDEN NONE;date_edited date_edited HIDDEN NONE;locerror locerror HIDDEN NONE;globalid globalid HIDDEN NONE;regulation regulation HIDDEN NONE;amendment amendment HIDDEN NONE;time_per time_per HIDDEN NONE;shape shape HIDDEN NONE;st_length(shape) st_length(shape) HIDDEN NONE"
)

# Select Layer By Location: from Speed_Limit_Layer, select records that lie WITHIN the Selected_LRSN_Route
arcpy.SelectLayerByLocation_management(Speed_Limit_Layer, "WITHIN",
                                       Selected_LRSN_Route, "",
                                       "NEW_SELECTION", "NOT_INVERT")
#
# Attribute-based selection to replace the above spatial selection, if needed
Exemplo n.º 7
0
                             "POINT")
arcpy.MakeRouteEventLayer_lr(clrs, "LRS_KEY", "Maint_tview",
                             "LRSKEY LINE BEGMILEPOST END_MP",
                             "Maint_Events_ln", "#", "ERROR_FIELD",
                             "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT",
                             "POINT")

arcpy.MakeRouteEventLayer_lr(clrs, "LRS_KEY", "SDE.GIS_CCL_Extents",
                             "LRS_KEY LINE BEG_CMP END_CMP", "GIS_CCL", "#",
                             "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL",
                             "ANGLE", "LEFT", "POINT")

arcpy.OverlayRouteEvents_lr("SDE.CCL_Resolution",
                            "LRS_KEY LINE BEG_CNTY_LOGMILE END_CNTY_LOGMILE",
                            "Database Connections\SDEDEV.sde\SDE.LNCL_EVENT",
                            "LRS_KEY LINE Beg_Cnty_Logmile End_Cnty_Logmile",
                            "INTERSECT", wsouttbl + "//CCL_LANES",
                            "LRS_KEY LINE BEG_CNTY_LOGMILE END_CNTY_LOGMILE",
                            "NO_ZERO", "FIELDS", "INDEX")
arcpy.OverlayRouteEvents_lr(
    "Database Connections/SDEDEV.sde/SDE.CCL_Resolution",
    "LRS_KEY LINE BEG_CNTY_LOGMILE END_CNTY_LOGMILE",
    "Database Connections/SDEDEV.sde/SDE.LNCL_EVENT",
    "LRS_KEY LINE BEG_CNTY_LOGMILE END_CNTY_LOGMILE", "INTERSECT",
    "Database Connections/SDEDEV.sde/SDE.CCL_Lanes",
    "LRS_KEY LINE BEG_CNTY_LOGMILE END_CNTY_LOGMILE", "NO_ZERO", "FIELDS",
    "INDEX")
#create Route Layer specific to City Connecting Link locations
ws = r"\\gisdata\arcgis\GISdata\KDOT\BTP\Projects\CCL"
tempdb = "LyonCCL2013_1_10.gdb"
CCLRS = "LRS_KEY" + "CITY"