Ejemplo n.º 1
0
def PostProcLRS():
    MResolution = 0.0005
    MTolerance = 0.001
    env.MTolerance = MTolerance
    env.MResolution = MResolution
    LRM_NAMES = ["CMLRS", "SMLRS"]
    FeatureClassToFeatureClass_conversion(
        admin_workspace + "/GIS_CANSYS.DBO.V_LRSNETS", admin_workspace,
        "SMLRS", "DIRECTION in (1, 2)", "#", "#")
    ChangePrivileges_management(admin_workspace + "/GIS_CANSYS.DBO.SMLRS",
                                "readonly", "GRANT", "AS_IS")
    FeatureClassToFeatureClass_conversion(
        admin_workspace + "/GIS_CANSYS.DBO.V_LRSNETC", admin_workspace,
        "CMLRS", "DIRECTION in (1, 2)", "#", "#")
    ChangePrivileges_management(admin_workspace + "/GIS_CANSYS.DBO.CMLRS",
                                "readonly", "GRANT", "AS_IS")
    for LRM in LRM_NAMES:
        print "converting " + LRM + " to point features " + str(
            datetime.datetime.now())
        FeatureVerticesToPoints_management(
            admin_workspace + "/GIS_CANSYS.DBO." + LRM,
            admin_workspace + "/GIS_CANSYS.DBO." + LRM + "_Point", "ALL")
        print "adding calibration values to " + LRM + " point features " + str(
            datetime.datetime.now())
        AddXY_management(admin_workspace + "/GIS_CANSYS.DBO." + LRM + "_Point")
        print "finished " + LRM + " LRM processing " + str(
            datetime.datetime.now())
        ChangePrivileges_management(
            admin_workspace + "/GIS_CANSYS.DBO." + LRM + "_Point", "readonly",
            "GRANT", "AS_IS")
def FindOverlapsSausages():
    '''KDOT Checks are already simplifying lines
    technically this is an unnecessary step 
    and it is a time consuming, resource intensive process
    KDOT will run this script on lines that have already been simplified
    Data stewards are encouraged to simplify lines to improve their data quality and system performance
    using a tool or the following command, which is commented out'''
    #SimplifyLine_cartography(inroadcenterlines, ", algorithm="POINT_REMOVE", tolerance="3 Feet", error_resolving_option="RESOLVE_ERRORS", collapsed_point_option="NO_KEEP", error_checking_option="CHECK")
    
    #Check to Make sure that Shape_Length is the appropriate geometry column length in all geodatabases
    MakeFeatureLayer_management(roadcenterlines, "RoadCenterlinesS3_L10", "Shape_Length>=10")
    #test overlapping with a centerline midpoint
    FeatureVerticesToPoints_management("RoadCenterlinesS3_L10", "in_memory/RoadCenterlinesS3_L10_Mid", point_location="MID")
    #Get the count of roads within a distance of the centerline midpoint
    SpatialJoin_analysis("RoadCenterlinesS3_L10_Mid", roadcenterlines, "in_memory/ValidateOverlaps2", "JOIN_ONE_TO_ONE", "KEEP_ALL", '#', "INTERSECT", "2 Feet", "Distance")
    #return the midpoints with a count greater than 1 - indicating possible overlaps
    #output this next line into validation geodatabase and add to arcmap for user interface
    FeatureClassToFeatureClass_conversion("in_memory/ValidateOverlaps2", r"C:\temp\New File Geodatabase (2).gdb", "ValidateOverlaps",""""Join_Count" > 1""")
    #may need to dev code to test for endpoints
    #clean up in memory artifact
    Delete_management("ValidateOverlaps2")
    #In aggregated data, county boundary overlaps are expected.  It's also assumed that county bound left right should be coded correctly.  
    #the following feature layer are the most important overlaps for review
    MakeFeatureLayer_management("ValidateOverlaps", "ValidateOverlaps_Non_County_Boundary", "COUNTY_L = COUNTY_R")
    #now using same midpoints look for sausages, midpoints less than 60 feet apart, might explore different distances under 60 feet
    #it might help and also hurt to lengthen the minimum segment length to longer than 10 feet for this, test a little more
    SpatialJoin_analysis("RoadCenterlinesS3_L10_Mid", roadcenterlines, "in_memory/ValidateSausages60", "JOIN_ONE_TO_ONE", "KEEP_ALL", '#', "INTERSECT", "120 Feet", "Distance")
    
    FeatureClassToFeatureClass_conversion("in_memory/ValidateSausages60", r"C:\temp\New File Geodatabase (2).gdb", "ValidateSausages_60ft",""""Join_Count" > 1""")
    Delete_management("ValidateSausages60")
    MakeFeatureLayer_management("ValidateSausages_60ft", "ValidateSausages_Non_County_Boundary", "COUNTY_L = COUNTY_R")
Ejemplo n.º 3
0
def DirectionalUrbanClass():
    #do the same as for State Sys but for Non State Urban Classified Highways (Nusys)
    FeatureVerticesToPoints_management("RoadCenterlinesC",
                                       "in_memory/UrbanPoints", "MID")
    FeatureClassToFeatureClass_conversion(
        NSND,
        "in_memory",
        "NSND_NPD",
        where_clause="NETWORK_DIRECTION IN ( 'SB' , 'WB' )")
    LocateFeaturesAlongRoutes_lr("UrbanPoints", "NSND_NPD", "NE_UNIQUE",
                                 "200 Feet", "in_memory/UrbanPointsMeasures",
                                 "RID POINT MEAS", "ALL", "DISTANCE", "ZERO",
                                 "FIELDS", "M_DIRECTON")
    Delete_management("UrbanPoints")
    #is the query stil valid for non state system?  Explore hte NE Unique.  State System did not use the county number prefix

    SelectLayerByAttribute_management(
        "UrbanPointsMeasures", "NEW_SELECTION",
        """SUBSTRING( "RID", 4, 7) NOT  LIKE SUBSTRING("NON_State_System_LRSKey" ,4, 7)"""
    )

    DeleteRows_management(in_rows="UrbanPointsMeasures")
    MakeRouteEventLayer_lr("NSND_NPD",
                           "NE_UNIQUE",
                           "UrbanPointsMeasures",
                           "rid POINT MEAS",
                           "UrbanPointEvents",
                           offset_field="Distance",
                           add_error_field="ERROR_FIELD",
                           add_angle_field="ANGLE_FIELD",
                           angle_type="NORMAL",
                           complement_angle="ANGLE",
                           offset_direction="RIGHT",
                           point_event_type="POINT")
    MakeFeatureLayer_management("UrbanPointEvents", "UNPD_ID",
                                """"Distance">=0""")
    SelectLayerByLocation_management("UNPD_ID", "INTERSECT",
                                     "RoadCenterlinesC", "1 Feet",
                                     "NEW_SELECTION")

    #at this point, there are a lot of false positives, places with single carriagway roads and nusys divided
    #we need to incorporate the check overlap process to identify where their are single and dual carriagways here
    #starting with the technique to find sausages or dual carraigeways
    #SpatialJoin_analysis("UNPD_ID", "RoadCenterlinesC", "in_memory/ValidateSausages120", "JOIN_ONE_TO_ONE", "KEEP_ALL", '#', "INTERSECT", "120 Feet", "Distance")

    #this Spatial Join step is improving the results, removing most false positives.  It still shows overlapping segments
    #it would be improved even more, potentially, by testing the non-primary direction against dissolve somehow.
    #except, the calculate method is by segment to the source, a dissolve would complicate the process of calculating back to the source data
    #we are looking for count grater than 0 of the offset point to hte segment, so a dissolved segment should work
    import EliminateOverlaps
    from EliminateOverlaps import CollectorDissolve
    #set the roadcenterline input and dissolve output for RoadCenterline dissolve for this subroutine
    roadcenterlines = "RoadCenterlinesC"
    ClassOutput = r"in_memory/RMC2"
    CollectorDissolve()
    SpatialJoin_analysis("UNPD_ID", "RMC2dissolve",
                         "in_memory/ValidateSausages120", "JOIN_ONE_TO_ONE",
                         "KEEP_ALL", '#', "INTERSECT", "120 Feet", "Distance")
Ejemplo n.º 4
0
def PostProcCalibPts():
    #this will create the calibrated network LRMs and the calibration points which are useful for other referential methods
    # It turns out these calibration points aren't reliable to calibrate routes due to the source geometry having non-increasing measures, also due to the ESRI calibrate routes tools:
    # http://support.esri.com/en/bugs/nimbus/TklNMDkwOTk5
    # http://search.esri.com/results/index.cfm?do=support&searchview=all&q=Calibrate%20Routes%20&filterid=2&requiredfields=(search-category:bugs/nimbus)&filter=p
    MResolution = 0.0005
    MTolerance = 0.001
    env.MTolerance = MTolerance
    env.MResolution = MResolution

    LRM_NAMES = ["SMLRS", "CMLRS"]
    try:
        for LRM in LRM_NAMES:
            print "converting " + LRM + " to point features " + str(
                datetime.datetime.now())
            #this is rather expensive
            FeatureVerticesToPoints_management(
                owner_workspace + "/GIS_CANSYS.SHARED." + LRM,
                owner_workspace + "/GIS_CANSYS.SHARED." + LRM + "_Point",
                "ALL")
            print "adding calibration values to " + LRM + " point features " + str(
                datetime.datetime.now())
            #this is VERY expensive and should be replaced by a da cursor that calculates SHAPE@M
            #for now this is easy and convenient to attribute the M value at every point
            AddXY_management(owner_workspace + "/GIS_CANSYS.SHARED." + LRM +
                             "_Point")
            #AddXY might take an hour total for both LRMS
            print "finished " + LRM + " LRM processing " + str(
                datetime.datetime.now())
            ChangePrivileges_management(
                admin_workspace + "/GIS_CANSYS.SHARED." + LRM + "_Point",
                "readonly", "GRANT", "AS_IS")
    except:
        endingTime = datetime.datetime.now()
        #ScriptStatusLogging('CANP_LRS_EXPORT.py', 'PostProcCalibPts Function failed while attempting to calibrate ' + str(LRM),
        #                    scriptFailure, startingTime,
        #                    endingTime, GetMessages(2))

        pass
Ejemplo n.º 5
0
def PostProcCalibPts():
    #this will create the calibrated network LRMs and the calibration points which are useful for other referential methods
    MResolution = 0.0005
    MTolerance = 0.001
    env.MTolerance = MTolerance
    env.MResolution = MResolution

    LRM_NAMES = ["SMLRS", "CMLRS"]
    try:
        for LRM in LRM_NAMES:
            print "converting " + LRM + " to point features " + str(
                datetime.datetime.now())
            #this is rather expensive
            FeatureVerticesToPoints_management(
                admin_workspace + "/GIS_CANSYS.DBO." + LRM,
                admin_workspace + "/GIS_CANSYS.DBO." + LRM + "_Point", "ALL")
            print "adding calibration values to " + LRM + " point features " + str(
                datetime.datetime.now())
            #this is VERY expensive and should be replaced by a da cursor that calculates SHAPE@M
            #for now this is easy and convenient to attribute the M value at every point
            AddXY_management(admin_workspace + "/GIS_CANSYS.DBO." + LRM +
                             "_Point")
            #AddXY might take an hour total for both LRMS
            print "finished " + LRM + " LRM processing " + str(
                datetime.datetime.now())
            ChangePrivileges_management(
                admin_workspace + "/GIS_CANSYS.DBO." + LRM + "_Point",
                "readonly", "GRANT", "AS_IS")
    except:
        endingTime = datetime.datetime.now()
        ScriptStatusLogging(
            'CANP_LRS_EXPORT.py',
            'PostProcCalibPts Function failed while attempting to calibrate ' +
            str(LRM), scriptFailure, startingTime, endingTime, GetMessages(2))

        pass
def routeCreation():
    env.workspace = returnGDBOrSDEPath(createRoutesOutputFC)
    env.overwriteOutput = 1
    '''
    # Need to match what Transcend used. -- Done.
    routeId = 'SourceRouteId'
    measureSource = 'TWO_FIELDS'
    fMeasureField = 'SourceFromMeasure'
    tMeasureField = 'SourceToMeasure'
    coordinatePriority = 'UPPER_LEFT'
    measureFactor = 1
    measureOffset = 0
    ignoreGaps = True
    buildIndex = True
    '''
    # Modifications for County Target Network.
    routeId = 'TargetCountyLRSKey'
    measureSource = 'Shapelength'
    #fMeasureField = 'SourceFromMeasure'
    #tMeasureField = 'SourceToMeasure'
    coordinatePriority = 'LOWER_LEFT'
    measureFactor = 1
    measureOffset = 0
    ignoreGaps = True
    buildIndex = True

    routesOutputGDB = returnGDBOrSDEPath(createRoutesOutputFC)
    routesOutputGDBName = returnGDBOrSDEName(routesOutputGDB)
    # Need to implement a new path function to get the GDB's folder.
    routesOutputGDBFolder = mainFolder
    if Exists(routesOutputGDB):
        Delete_management(routesOutputGDB)
    else:
        pass
    CreateFileGDB_management(routesOutputGDBFolder, routesOutputGDBName)

    # Checking to see if the copy for routes output exists.
    # If so, remove it.
    #if Exists(createRoutesOutputFC):
    #    Delete_management(createRoutesOutputFC)
    #else:
    #    pass

    print("Creating the lrs routes.")
    # CreateRoutes_lr GP Tool
    CreateRoutes_lr(createRoutesInputFC, routeId, createRoutesOutputFC,
                    measureSource, fMeasureField, tMeasureField,
                    coordinatePriority, measureFactor, measureOffset,
                    ignoreGaps, buildIndex)

    print("Adding date fields to " + returnFeatureClass(createRoutesOutputFC) +
          ".")
    #Addfields:
    AddField_management(createRoutesOutputFC, "F_Date", "DATE", "", "", "",
                        "F_Date", nullable)
    pyDateExpression = '''def pyFindTheDate():
        import time
        return time.strftime("%Y/%m/%d")'''

    CalculateField_management(createRoutesOutputFC, "F_Date",
                              "pyFindTheDate()", "PYTHON_9.3",
                              pyDateExpression)
    # T_Date (Date)
    AddField_management(createRoutesOutputFC, "T_Date", "DATE", "", "", "",
                        "T_Date", nullable)

    # ---- Add route calibration point creation steps for Start & End points. ----
    MakeFeatureLayer_management(createRoutesInputFC, 'tempFeatureLayer')

    # Checking to see if the output already exists.
    # If so, remove it so that it can be recreated.
    if Exists(startCalibrationPoints):
        Delete_management(startCalibrationPoints)
    else:
        pass
    if Exists(endCalibrationPoints):
        Delete_management(endCalibrationPoints)
    else:
        pass

    # Create 2 fieldInfo objects. Turn off all the fields in each one.
    featureDesc = Describe('tempFeatureLayer')
    if featureDesc.dataType == "FeatureLayer":
        fieldInfo_For_Start_CP_Fields = featureDesc.fieldInfo
        fieldInfo_For_End_CP_Fields = featureDesc.fieldInfo
        # Use the count property to iterate through all the fields
        for index in range(0, fieldInfo_For_Start_CP_Fields.count):
            fieldInfo_For_Start_CP_Fields.setVisible(index, 'HIDDEN')
            fieldInfo_For_End_CP_Fields.setVisible(index, 'HIDDEN')

    # Turn on the needed fields.
    visibile_Fields_For_Start_CP_Layer = [routeId, 'SourceFromMeasure']
    for visibile_Field in visibile_Fields_For_Start_CP_Layer:
        tempIndex = fieldInfo_For_Start_CP_Fields.findFieldByName(
            visibile_Field)
        fieldInfo_For_Start_CP_Fields.setVisible(tempIndex, 'VISIBLE')
    # Create a feature layer that only shows the needed fields.
    MakeFeatureLayer_management(createRoutesInputFC,
                                featureLayerCL_For_Start_CP, "", "",
                                fieldInfo_For_Start_CP_Fields)
    # Use that feature layer to create the 1st calibration point set.
    FeatureVerticesToPoints_management(featureLayerCL_For_Start_CP,
                                       startCalibrationPoints, "START")

    # Turn on the needed fields.
    visibile_Fields_For_End_CP_Layer = [routeId, 'SourceToMeasure']
    for visibile_Field in visibile_Fields_For_End_CP_Layer:
        tempIndex = fieldInfo_For_End_CP_Fields.findFieldByName(visibile_Field)
        fieldInfo_For_End_CP_Fields.setVisible(tempIndex, 'VISIBLE')
    # Create a feature layer that only shows the needed fields.
    MakeFeatureLayer_management(createRoutesInputFC, featureLayerCL_For_End_CP,
                                "", "", fieldInfo_For_End_CP_Fields)
    # Use that feature layer to create the 2nd calibration point set.
    FeatureVerticesToPoints_management(featureLayerCL_For_End_CP,
                                       endCalibrationPoints, "END")

    # ---- Merge the Start & End calibration points. ----
    # Checking to see if the output already exists.
    # If so, remove it so that it can be recreated.
    if Exists(mergedCalibrationPoints):
        Delete_management(mergedCalibrationPoints)
    else:
        pass
    # RoutesSource_Start_CP.SourceRouteId to CalPts_Merge.RouteId
    # RoutesSource_End_CP.SourceRouteId to CalPts_Merge.RouteId
    mcp_Field1 = FieldMap()
    mcp_Field1.addInputField(startCalibrationPoints, routeId)
    mcp_Field1.addInputField(endCalibrationPoints, routeId)
    mcp_Field1_OutField = mcp_Field1.outputField
    mcp_Field1_OutField.name = 'RouteId'
    mcp_Field1_OutField.aliasName = 'RouteId'
    mcp_Field1_OutField.type = 'String'
    mcp_Field1_OutField.length = 50
    mcp_Field1.outputField = mcp_Field1_OutField

    # RoutesSource_Start_CP.SourceFromMeasure to CalPts_Merge.Measure
    mcp_Field2 = FieldMap()
    mcp_Field2.addInputField(startCalibrationPoints, 'SourceFromMeasure')
    mcp_Field2.addInputField(endCalibrationPoints, 'SourceToMeasure')
    mcp_Field2_OutField = mcp_Field2.outputField
    mcp_Field2_OutField.name = 'Measure'
    mcp_Field2_OutField.aliasName = 'Measure'
    mcp_Field2_OutField.type = 'Double'
    mcp_Field2.outputField = mcp_Field2_OutField

    # Create a fieldMappings object for the layer merge.
    calibrationPointsMappings = FieldMappings()
    calibrationPointsMappings.addFieldMap(mcp_Field1)
    calibrationPointsMappings.addFieldMap(mcp_Field2)

    #Merge the points together into a single feature class.
    inputMergeLayers = [startCalibrationPoints, endCalibrationPoints]
    Merge_management(inputMergeLayers, mergedCalibrationPoints,
                     calibrationPointsMappings)

    MakeFeatureLayer_management(mergedCalibrationPoints, 'tempMergedPoints')

    dissolveFields = ["RouteId", "Measure"]
    print('Dissolving points.')
    Dissolve_management('tempMergedPoints', dissolvedCalibrationPoints,
                        dissolveFields, "#", "SINGLE_PART")
Ejemplo n.º 7
0
FeatureClassToFeatureClass_conversion("NM_SECT", STAGEDB, "SECT" )

#Remove the CANP Prod layers
for df in mapping.ListDataFrames(mxd):
    for lyr in mapping.ListLayers(mxd, "", df):
        mapping.RemoveLayer(df, lyr)
RefreshActiveView()

#Start the processing to rebuild layers
MakeFeatureLayer_management(STAGEDB+r"\SRND", "SRND")
SRNDelem = "NE_NT_TYPE = 'SRND' AND NE_VERSION_NO in ('EB', 'NB')"
MakeTableView_management(STAGEDB+r"\ELEMENTS_ALL", "SRND_ELEM", SRNDelem)
AddJoin_management("SRND", "NE_ID", "SRND_ELEM", "NE_ID", "KEEP_COMMON")

#Create the vertices for calibration points
FeatureVerticesToPoints_management("SRND", STAGEDB+"/Calibration_Points_SRND","ALL")
AddXY_management("GIS_CANSYS.DBO.Calibration_Points_SRND")
'''
LocateFeaturesAlongRoutes_lr(ws+"\\"+tempgdb+"/Calibration_Points",ws+"\\"+tempgdb+"/SRND","NE_UNIQUE","0.001 Feet",ws+"\\"+tempgdb+"/CP_SRND","STATE_MILE POINT SR_MEAS","ALL","DISTANCE","ZERO","FIELDS","M_DIRECTON")
AddJoin_management("SECT","RSE_HE_ID","Elements","NE_ID","KEEP_COMMON")

FeatureClassToFeatureClass_conversion("SECT",STAGEDB,"CANSYS_SECTIONS", "#", "#"  )

pathloc = ws+"\\"+tempgdb
routelyr = ws+"\\"+tempgdb+"\\"+route
inlyr2 = ws+"\\"+tempgdb+"/STATE_SYSTEM"

inlyr1 = ws+"\\"+tempgdb+"/Calibration_Points"
'''

Ejemplo n.º 8
0
                                      "GIS_STATE_SYSTEM",
                                      "LOC_ERROR = 'NO ERROR'")

#Copy State System to SDEDEV... problem with Geomedia ability to connect
FeatureClassToFeatureClass_conversion("MapExtractSRNDEvents", SDEDEV_SHARED,
                                      "STATE_SYSTEM", "LOC_ERROR = 'NO ERROR'")

#copy state systen to GISTEST
FeatureClassToFeatureClass_conversion("MapExtractSRNDEvents",
                                      "Database Connections/GISTEST.sde",
                                      "STATE_SYSTEM", "#", "#", "SDO_GEOMETRY")

#Save the Primary Route Skeleton Layer

#Create the vertices for calibration points
FeatureVerticesToPoints_management(STAGEDB + "/GIS_STATE_SYSTEM",
                                   STAGEDB + "/Calibration_Points", "ALL")
DeleteIdentical_management("GIS_CANSYS.DBO.Calibration_Points",
                           "LRS_KEY;POINT_X;POINT_Y;POINT_M", "#", "0")
CreateRoutes_lr(STAGEDB + "/GIS_STATE_SYSTEM", "LRS_ROUTE",
                STAGEDB + "/GIS_STATE_ROUTES", "TWO_FIELDS",
                "BEG_STATE_LOGMILE", "END_STATE_LOGMILE", "UPPER_LEFT", "1",
                "0", "IGNORE", "INDEX")
CalibrateRoutes_lr(STAGEDB + "/GIS_STATE_ROUTES", "LRS_ROUTE",
                   STAGEDB + "/Calibration_Points", "LRS_ROUTE", "POINT_M",
                   STAGEDB + "/SMLRS", "MEASURES", "5 feet", "BETWEEN",
                   "BEFORE", "AFTER", "IGNORE", "KEEP", "INDEX")

#Rider Routes
CreateRoutes_lr(STAGEDB + "/GIS_STATE_SYSTEM", "SRND_KEY",
                STAGEDB + "/SRND_PRIMARY_ROUTE", "TWO_FIELDS",
                "BEG_STATE_LOGMILE", "END_STATE_LOGMILE", "UPPER_LEFT", "1",
Ejemplo n.º 9
0
print "loading state highway system road centerlines loaded to in memory workspace"
FeatureClassToFeatureClass_conversion(Roads, "in_memory", "RoadCenterlines",
                                      "StateKey1 IS NOT NULL ")
#FeatureClassToFeatureClass_conversion(Roads, "in_memory", "RoadCenterlines", "StateKey1 IS NOT NULL ")
print "road centerlines loaded to in memory workspace"

#these are the two linear referencing networks we're going to use to calibrate the state highway system
Lrm_Dict = {'STATE': Smlrs, 'COUNTY': Cmlrs}

#and this is the beginning and end of a line, for which we are going to create a vertex point
End_List = ['START', 'END']

# First, lets create points at the beginning of each centerline segment using Vertices to Points.
for end in End_List:
    i_end_output = "in_memory/CalibrationPoint" + str(end)
    FeatureVerticesToPoints_management("in_memory/RoadCenterlines",
                                       i_end_output, str(end))

#Iterate through the LRMs to bring them into memory and do the processing for each segment begin and end point!
for key, value in Lrm_Dict.items():
    FeatureClassToFeatureClass_conversion(value, "in_memory", "LRM" + str(key))
    for end in End_List:
        outtable = "in_memory/" + str(end) + "_" + str(key)
        outstore = ConflationDatabase + r"/" + str(end) + "_" + str(key)
        outproperties = str(key) + "_LRS POINT MEAS_" + str(key)
        if key == "STATE":
            lrskey = str(key) + "_NQR_DESCRIPTION"
        else:
            lrskey = "NQR_DESCRIPTION"
        LocateFeaturesAlongRoutes_lr("in_memory/CalibrationPoint" + str(end),
                                     "in_memory/LRM" + str(key), lrskey,
                                     "500 Feet", outtable, outproperties,
Ejemplo n.º 10
0
def StateHighwayCalibrate(theStateHighwaySegments):
    #theStateHighwaySegments is defined as the roadway segments intended for calibration to the EXOR measures
    #this function is being called by

    #here are the GIS routes with measures extracted regularly from EXOR using the FME extraction and python route reference tools from DT00ar60
    #these routes contain the current exor measures
    #Smlrs = r'Database Connections\RO@sqlgisprod_GIS_cansys.sde\GIS_CANSYS.SHARED.SMLRS'

    #need to define a route source represntative of the correct network year, about 2015
    #should have K-10 on 23rd street still

    Cmlrs = r'Database Connections\RO@sqlgisprod_GIS_cansys.sde\GIS_CANSYS.SHARED.CMLRS_2015'

    from arcpy import FeatureClassToFeatureClass_conversion, FeatureVerticesToPoints_management, LocateFeaturesAlongRoutes_lr, CalculateField_management
    from arcpy import env, MakeFeatureLayer_management, SelectLayerByAttribute_management, DeleteRows_management, AddJoin_management, AddField_management, RemoveJoin_management
    env.overwriteOutput = 1
    # Start by loading NG911 aggregated, conflated road centerlines to an in-memory feature class

    #FeatureClassToFeatureClass_conversion(Roads, "in_memory", "RoadCenterlines", "StateKey1 IS NOT NULL ")
    #FeatureClassToFeatureClass_conversion(Roads, "in_memory", "RoadCenterlines", "StateKey1 IS NOT NULL ")

    MakeFeatureLayer_management(theStateHighwaySegments,
                                "CalibrateRoadCenterlines")
    RoadCenterlines = "CalibrateRoadCenterlines"
    #these are the two linear referencing networks we're going to use to calibrate the state highway system
    #for iteration 2, no source data should refer to the state LRM, so we're only doing the County LRM
    Lrm_Dict = {'COUNTY': Cmlrs}

    #and this is the beginning and end of a line, for which we are going to create a vertex point
    End_List = ['START', 'END']

    # First,  create points at the begin and end of each road centerline segment using Vertices to Points.
    for end in End_List:
        i_end_output = "in_memory/CalibrationPoint" + str(end)
        FeatureVerticesToPoints_management(RoadCenterlines, i_end_output,
                                           str(end))

    #Iterate through the LRMs to bring them into memory and do the processing for each segment begin and end point!
    for key, value in Lrm_Dict.items():
        FeatureClassToFeatureClass_conversion(value, "in_memory",
                                              "LRM" + str(key))
        for end in End_List:
            outtable = "in_memory/" + str(end) + "_" + str(key)
            outstore = spampathfd + r"/" + str(end) + "_" + str(key)
            outproperties = str(key) + "_LRS POINT MEAS_" + str(key)
            if key == "STATE":
                lrskey = str(key) + "_NQR_DESCRIPTION"
            else:
                lrskey = "NQR_DESCRIPTION"
            LocateFeaturesAlongRoutes_lr(
                "in_memory/CalibrationPoint" + str(end),
                "in_memory/LRM" + str(key), lrskey, "500 Feet", outtable,
                outproperties, "ALL", "DISTANCE", "ZERO", "FIELDS",
                "M_DIRECTON")

            #that LFAR function located begin/end segment points to ALL ROUTES within 500 feet of the segment endpoint

            #for calibrating, we are only interested in the points and LFAR Results that where this query is NOT true:
            qNotThisRoad = '"COUNTY_LRS" <> "KDOT_LRS_KEY"'
            #so we will delete the records where this query is trye
            SelectLayerByAttribute_management(
                str(end) + "_" + str(key), "NEW_SELECTION", qNotThisRoad)
            DeleteRows_management(str(end) + "_" + str(key))
            #DeleteField_management(outtable, "Mileage_Length;Mileage_Logmile;ROUTE_PREFIX_TARGET;LRS_ROUTE_NUM_TARGET;LRS_UNIQUE_TARGET;Non_State_System_OBJECTID;LRS_BACKWARD;F_CNTY_2;T_CNTY_2;F_STAT_2;T_STAT_2;CountyKey2;MileFlipCheck;InLine_FID;SimLnFLag")

            #TableToTable_conversion(outtable, ConflationDatabase, outstore)
            #One Method, if using SQL Server, is to use table to table conversion to export to SQL server, then run these query in #CalcUsingSQLserver()
            #If not using SQL server this will suffice, although if there are multiple orig FID's to the original data source FID, there's no logic or handling to discern between the many to one relationship.
            #In the case of hte many to one, or duplicate Orig_FID in the measure table, it might be desirable to choose the closest result
            #A few of the duplicates I reviewed had identical measure values, if that's always the case, then handling the duplicates is unnecessary
            measfield = str(end) + "_" + str(key) + "_meas"
            try:
                AddField_management(theStateHighwaySegments, measfield,
                                    "DOUBLE", "", "", "", "", "NULLABLE",
                                    "NON_REQUIRED")
            except:
                print "could not add the field for calibrated measures"
            jointable = str(end) + "_" + str(key)
            AddJoin_management(theStateHighwaySegments, "OBJECTID", jointable,
                               "ORIG_FID", "KEEP_ALL")
            exp = "!" + jointable + ".MEAS_" + str(key) + "!"
            measfieldcalc = theStateHighwaySegments + "." + measfield
            CalculateField_management(theStateHighwaySegments, measfieldcalc,
                                      exp, "PYTHON")
            RemoveJoin_management(theStateHighwaySegments)

        # NEed to now test for direction again based on begin < end, handle flipping and assemble the routes
    from arcpy import CreateRoutes_lr
    CreateRoutes_lr("CalibrateRoadCenterlines", "KDOT_LRS_KEY",
                    "in_memory/Simplified_CreateRoutes_test1", "TWO_FIELDS",
                    "START_COUNTY_meas", "END_COUNTY_meas", "UPPER_LEFT", "1",
                    "0", "IGNORE", "INDEX")
Ejemplo n.º 11
0
def StateHighwayCalibrate():
    import datetime
    startDateTime = datetime.datetime.now()
    print("starting SHS calibration at " + str(startDateTime) +
          ", it should take about 15 minutes to calibrate state system routes")
    #Calibration process completed in 0:03:36.252839 hours, minutes, seconds
    from KhubCode25.KhubCode25Config import devorprod, dbname, dbownername, localProFileGDBWorkspace, KDOTConnections, Cmlrs, prodDataSourceSDE, devDataSourceSDE
    fileformatDateStr = startDateTime.strftime("%Y%m%d")
    #theStateHighwaySegments is defined as the roadway segments intended for calibration to the EXOR measures
    if devorprod == 'prod':
        database = prodDataSourceSDE

        print("running on " + devorprod)
    else:
        database = devDataSourceSDE

        print("running on " + devorprod)
    from arcpy import FeatureClassToFeatureClass_conversion, Delete_management, FeatureVerticesToPoints_management, LocateFeaturesAlongRoutes_lr, CreateFileGDB_management, env, MakeFeatureLayer_management, SelectLayerByAttribute_management, DeleteRows_management, MakeTableView_management
    env.overwriteOutput = 1
    try:
        CreateFileGDB_management(localProFileGDBWorkspace,
                                 "KhubRoadCenterlinesTemp" + fileformatDateStr,
                                 "CURRENT")
    except:
        Delete_management(localProFileGDBWorkspace,
                          "KhubRoadCenterlinesTemp" + fileformatDateStr)
        CreateFileGDB_management(localProFileGDBWorkspace,
                                 "KhubRoadCenterlinesTemp" + fileformatDateStr,
                                 "CURRENT")

    #stopped using in_memory after the upgrade to arcgis pro, it doesn't work like it used to do.
    #consider using in memory for not in non-pro script environment, but for this process, probably will not make much difference

    localfilegdb = localProFileGDBWorkspace + '\\' + 'KhubRoadCenterlinesTemp' + fileformatDateStr + '.gdb'
    sdegdb = KDOTConnections + r'\\' + database + r'\\' + dbname + "." + dbownername
    firstCut = sdegdb + ".All_Road_Centerlines"
    NextIter = "_D1"
    nextCut = firstCut + NextIter
    RoadsToCalibrate = [firstCut, nextCut]

    CMLRS = sdegdb + "." + Cmlrs
    Lrm_Dict = {'COUNTY': CMLRS}
    for sderoads in RoadsToCalibrate:
        if sderoads[-3:] == "_D1":
            MakeFeatureLayer_management(
                sderoads, "lyrStateSystemSource" + NextIter,
                "LRS_ROUTE_PREFIX IN ('I', 'U', 'K') And LRS_ROUTE_SUFFIX NOT IN ('Z', 'G')",
                None, "")
            RoadCenterlines = localfilegdb + "/lyrStateSystemSource" + NextIter
            End_List = ['START', 'END']
            # First,  create points at the begin and end of each road centerline segment using Vertices to Points.
            for end in End_List:
                end_name = end + NextIter
                i_end_output = localfilegdb + "/CalibrationPoint" + end_name
                try:
                    FeatureVerticesToPoints_management(RoadCenterlines,
                                                       i_end_output, str(end))
                    #this works in Pro
                except:
                    FeatureVerticesToPoints_management(
                        "lyrStateSystemSource" + NextIter, i_end_output,
                        str(end))
        #and this is the beginning and end of a line, for which we are going to create a vertex point
        #Iterate through the LRMs to bring them into memory and do the processing for each segment begin and end point!
                for key, value in Lrm_Dict.items():
                    FeatureClassToFeatureClass_conversion(
                        value, localfilegdb, "LRM" + str(key))
                    for end in End_List:
                        outtable = localfilegdb + r"/" + str(
                            end_name) + "_" + str(key)
                        outproperties = str(key) + "_LRS POINT MEAS_" + str(
                            key)
                        if key == "STATE":
                            lrskey = str(key) + "_NQR_DESCRIPTION"
                        else:
                            lrskey = "NQR_DESCRIPTION"
                        try:
                            LocateFeaturesAlongRoutes_lr(
                                localfilegdb + r"/CalibrationPoint" +
                                str(end_name), "LRM" + str(key), lrskey,
                                "500 Feet", outtable, outproperties, "ALL",
                                "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON")
                            #this works in Pro
                        except:
                            LocateFeaturesAlongRoutes_lr(
                                localfilegdb + "/CalibrationPoint" +
                                str(end_name),
                                localfilegdb + r"/LRM" + str(key), lrskey,
                                "500 Feet", outtable, outproperties, "ALL",
                                "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON")
                            #this works in non-Pro script environment

                        #that LFAR function located begin/end segment points to ALL ROUTES within 500 feet of the segment endpoint

                        #for calibrating, we are only interested in the points and LFAR Results that where this query is NOT true:
                        qNotThisRoad = 'SUBSTRING("COUNTY_LRS",0,10) <> SUBSTRING("KDOT_LRS_KEY",0,10)'
                        #so we will delete the records where this query is trye
                        try:
                            SelectLayerByAttribute_management(
                                str(end_name) + "_" + str(key),
                                "NEW_SELECTION", qNotThisRoad)
                            DeleteRows_management(
                                str(end_name) + "_" + str(key))
                            #this works in Pro Environment
                        except:
                            #SelectLayerByAttribute_management(localfilegdb+"/"+str(end)+"_"+str(key), "NEW_SELECTION", qNotThisRoad)
                            MakeTableView_management(
                                localfilegdb + "/" + str(end_name) + "_" +
                                str(key), "deleterows", qNotThisRoad, None, "")
                            DeleteRows_management("deleterows")
                            #this works in non-Pro script environment
                #this works in non-Pro script environment
        else:
            MakeFeatureLayer_management(
                sderoads, "lyrStateSystemSource",
                "LRS_ROUTE_PREFIX IN ('I', 'U', 'K') And LRS_ROUTE_SUFFIX NOT IN ('Z', 'G')",
                None, "")
            RoadCenterlines = localfilegdb + "/lyrStateSystemSource"
            End_List = ['START', 'END']
            for end in End_List:
                end_name = end
                print(end_name)
                i_end_output = localfilegdb + "/CalibrationPoint" + str(end)
                try:
                    FeatureVerticesToPoints_management(RoadCenterlines,
                                                       i_end_output, str(end))
                    #this works in Pro
                except:
                    FeatureVerticesToPoints_management("lyrStateSystemSource",
                                                       i_end_output, str(end))
        #and this is the beginning and end of a line, for which we are going to create a vertex point
        #Iterate through the LRMs to bring them into memory and do the processing for each segment begin and end point!
                for key, value in Lrm_Dict.items():
                    FeatureClassToFeatureClass_conversion(
                        value, localfilegdb, "LRM" + str(key))
                    for end in End_List:
                        outtable = localfilegdb + r"/" + str(
                            end_name) + "_" + str(key)
                        outproperties = str(key) + "_LRS POINT MEAS_" + str(
                            key)
                        if key == "STATE":
                            lrskey = str(key) + "_NQR_DESCRIPTION"
                        else:
                            lrskey = "NQR_DESCRIPTION"
                        try:
                            LocateFeaturesAlongRoutes_lr(
                                localfilegdb + r"/CalibrationPoint" +
                                str(end_name), "LRM" + str(key), lrskey,
                                "500 Feet", outtable, outproperties, "ALL",
                                "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON")
                            #this works in Pro
                        except:
                            LocateFeaturesAlongRoutes_lr(
                                localfilegdb + "/CalibrationPoint" +
                                str(end_name),
                                localfilegdb + r"/LRM" + str(key), lrskey,
                                "500 Feet", outtable, outproperties, "ALL",
                                "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON")
                            #this works in non-Pro script environment

                        #that LFAR function located begin/end segment points to ALL ROUTES within 500 feet of the segment endpoint

                        #for calibrating, we are only interested in the points and LFAR Results that where this query is NOT true:
                        qNotThisRoad = 'SUBSTRING("COUNTY_LRS",0,10) <> SUBSTRING("KDOT_LRS_KEY",0,10)'
                        #so we will delete the records where this query is true
                        #It is possible that there will be multiple rows where this query is true, this result
                        #will calculate one value, not conditional on distance, min/max, just takes the first true result I guess
                        #in situations where there are multiple results, consider dissolving these points and keeping some stats
                        #then review stats to determine appropriate value, probably the closest result
                        try:
                            SelectLayerByAttribute_management(
                                str(end_name) + "_" + str(key),
                                "NEW_SELECTION", qNotThisRoad)
                            DeleteRows_management(
                                str(end_name) + "_" + str(key))
                            #this works in Pro Environment
                        except:
                            #SelectLayerByAttribute_management(localfilegdb+"/"+str(end)+"_"+str(key), "NEW_SELECTION", qNotThisRoad)
                            MakeTableView_management(
                                localfilegdb + "/" + str(end_name) + "_" +
                                str(key), "deleterows", qNotThisRoad, None, "")
                            DeleteRows_management("deleterows")
                            #this works in non-Pro script environment
    print(
        'Calibration process completed in {} hours, minutes, seconds.'.format(
            datetime.datetime.now() - startDateTime))
Ejemplo n.º 12
0
def SecondaryDirectionFinder():
    #make a point at the center of each line segment for a highway
    #No way currently to do this for RML highways,  NUSYS provides the directional layer for C highwyas
    #FeatureToPoint_management("State Highways", "in_memory/HighwayPoints", "INSIDE")
    #maybe two ways to do this, this time, I'm using midpoint from feature to point - catch
    FeatureVerticesToPoints_management(
        "RoadCenterlines",
        out_feature_class="in_memory/HighwayPoints",
        point_location="MID")
    #FeatureToPoint_management(Roads, "in_memory/HighwayPoints", "INSIDE")
    FeatureClassToFeatureClass_conversion(
        SRND,
        "in_memory",
        "SRND_NPD",
        where_clause="NETWORK_DIRECTION IN ( 'SB' , 'WB' )")

    #CRND Secondary Direction is the CRND layer where "NETWORK_DIRECTION IN ( 'SB' , 'WB' )"
    #Locate Features Along Routes will calculate a +/- offset distance of the dual carriageway points from the CRND centerline
    LocateFeaturesAlongRoutes_lr("HighwayPoints", "SRND_NPD", "NE_UNIQUE",
                                 "500 Feet", "in_memory/HighwayPointsMeasures",
                                 "RID POINT MEAS", "ALL", "DISTANCE", "ZERO",
                                 "FIELDS", "M_DIRECTON")

    #All the Highway Points are no longer needed and can be freed from memory
    Delete_management("HighwayPoints")

    #since we located along all routes instead of the nearest routes, we need to select the rows that have the correct LRS key
    #SelectLayerByAttribute_management("in_memory/HighwayPointsMeasures", "NEW_SELECTION", """SUBSTRING( "RID", 1, 7) NOT  LIKE SUBSTRING("StateKey1", 4, 7)""")

    #Using State_System_LRSKey from Conflation just in case the StateKey1 has not yet been added or calculated.
    SelectLayerByAttribute_management(
        "HighwayPointsMeasures", "NEW_SELECTION",
        """SUBSTRING( "RID", 1, 7) NOT  LIKE SUBSTRING("State_System_LRSKey" ,4, 7)"""
    )
    DeleteRows_management(in_rows="HighwayPointsMeasures")
    # point events are located along the routes that KDOT says are divided on the dual carriageway
    MakeRouteEventLayer_lr("SRND_NPD",
                           "NE_UNIQUE",
                           "HighwayPointsMeasures",
                           "rid POINT MEAS",
                           "HighwayPointEvents",
                           offset_field="Distance",
                           add_error_field="ERROR_FIELD",
                           add_angle_field="ANGLE_FIELD",
                           angle_type="NORMAL",
                           complement_angle="ANGLE",
                           offset_direction="RIGHT",
                           point_event_type="POINT")

    #select the secondary direction points based on the offset direction
    MakeFeatureLayer_management("HighwayPointEvents", "NPD_ID",
                                """"Distance">=0""")

    # some random points, due to the 500 ft buffer I think, are getting included.  Select the event points that do not intersect a state highway road centerline feature
    #
    SelectLayerByLocation_management("NPD_ID", "INTERSECT", "RoadCenterlines",
                                     "1 Feet", "NEW_SELECTION")

    #sometimes (center turn lanes, left turn lanes, painted medians, median terminus locations)
    #there is a difference between what KDOT says is Divided and the dual carriagway geometry.
    #Consider this and determine how to handle divided highways in the route Keys/route structures.
    #this next step will only factor in the

    FeatureClassToFeatureClass_conversion(
        "NPD_ID",
        ConflationDatabase + "\\" + GeodatabaseName + ".SDE.KANSAS_DOT",
        "Non_Primary_Divided_Highway", '"Distance">=0')
Ejemplo n.º 13
0
from arcpy import mapping, env, FeatureVerticesToPoints_management, LocateFeaturesAlongRoutes_lr, MakeTableView_management, MakeRouteEventLayer_lr, FeatureClassToFeatureClass_conversion
from arcpy import DeleteIdentical_management, CreateRoutes_lr, CalibrateRoutes_lr, AddField_management, CalculateField_management
from CONFIG import ws, tempgdb, nowish, MTolerance, MResolution
mxd = mapping.MapDocument(
    r"\\GISDATA\ArcGIS\GISDATA\MXD\NewGISNetworkSeed.mxd")
df = mapping.ListDataFrames(mxd, "Layers")[0]
env.MTolerance = MTolerance
env.MResolution = MResolution

route = "SRND"
pathloc = ws + "\\" + tempgdb
routelyr = ws + "\\" + tempgdb + "\\" + route
inlyr2 = ws + "\\" + tempgdb + "/STATE_SYSTEM"
FeatureVerticesToPoints_management(ws + "\\" + tempgdb + "/STATE_SYSTEM",
                                   ws + "\\" + tempgdb + "/Calibration_Points",
                                   "ALL")
inlyr1 = ws + "\\" + tempgdb + "/Calibration_Points"

LocateFeaturesAlongRoutes_lr(ws + "\\" + tempgdb + "/Calibration_Points",
                             ws + "\\" + tempgdb + "/SRND", "NE_UNIQUE",
                             "0.001 Feet", ws + "\\" + tempgdb + "/CP_SRND",
                             "STATE_MILE POINT SR_MEAS", "ALL", "DISTANCE",
                             "ZERO", "FIELDS", "M_DIRECTON")
MakeTableView_management(ws + "\\" + tempgdb + "/CP_SRND", "Calibration_SR",
                         '"STATE_MILE" = "SRND"', ws + "\\" + tempgdb, "#")
MakeRouteEventLayer_lr(routelyr, "NE_UNIQUE", "Calibration_SR",
                       "STATE_MILE POINT SR_MEAS", "SR_Calibration_Events",
                       "#", "ERROR_FIELD", "NO_ANGLE_FIELD", "NORMAL", "ANGLE",
                       "LEFT", "POINT")
FeatureClassToFeatureClass_conversion("SR_Calibration_Events",
Ejemplo n.º 14
0
CCLBeg = "!CCL.DBO.CITY_CONNECTING_LINK_STATE.MIN_BEG_STATE_LOGMILE! - !CCL.DBO.CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!"

MakeFeatureLayer_management(LineFeatureClass, "CITY_CONNECTING_LINK_RESET")
resln = "CITY_CONNECTING_LINK_RESET"
AddField_management(resln, "CCL_BEGIN", "DOUBLE", 12, 3)
AddField_management(resln, "CCL_END", "DOUBLE", 12, 3)

AddJoin_management("CITY_CONNECTING_LINK_RESET", "CCL_LRS",
                   connection1 + "CITY_CONNECTING_LINK_STATE_D", "CCL_LRS",
                   "KEEP_ALL")

CalculateField_management(resln, "CCL_BEGIN", CCLBeg, "PYTHON")
CalculateField_management(resln, "CCL_END", CCLEnd, "PYTHON")

print "calibrating LRS - point calibration method"
FeatureVerticesToPoints_management(LineFeatureClass,
                                   connection1 + "CALIBRATION_POINTS", "ALL")
LocateFeaturesAlongRoutes_lr(connection1 + "CALIBRATION_POINTS",
                             ReferenceRoute, ReferenceRouteKey, "1 Feet",
                             connection1 + "CP_MEAS", "RefKey POINT MEASURE",
                             "ALL", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON")
querystr = str("RefKey = " + ReferenceRouteKey)
MakeTableView_management(connection1 + "CP_MEAS", "CalibrationEvents",
                         querystr, "#")
delfields = NewRouteKey + ";MEASURE"
DeleteIdentical_management("CalibrationEvents", delfields)
inprops = str(ReferenceRouteKey + " POINT MEASURE")
MakeRouteEventLayer_lr(ReferenceRoute, ReferenceRouteKey, "CalibrationEvents",
                       inprops, "Calibration_Event_lyr", "#", "ERROR_FIELD",
                       "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT", "POINT")
FeatureClassToFeatureClass_conversion("Calibration_Event_lyr", connection0,
                                      "Calibration_Points" + NewRoute, "#",
Ejemplo n.º 15
0
def RM_Calibrate():
    import datetime
    startDateTime = datetime.datetime.now()
    print(
        "starting SHS calibration at " + str(startDateTime) +
        ", it should take about 20 minutes to calibrate non-state system urban and rural classified routes"
    )

    from KhubCode25.KhubCode25Config import devorprod, dbname, dbownername, localProFileGDBWorkspace, KDOTConnections, prodDataSourceSDE, devDataSourceSDE, RuralClassifiedRoutes, UrbanClassifiedRoutes

    if devorprod == 'prod':
        database = prodDataSourceSDE

        print("running on " + devorprod)
    else:
        database = devDataSourceSDE

        print("running on " + devorprod)
    fileformatDateStr = startDateTime.strftime("%Y%m%d")
    from arcpy import (MakeFeatureLayer_management,
                       FeatureVerticesToPoints_management,
                       LocateFeaturesAlongRoutes_lr, MakeRouteEventLayer_lr,
                       Dissolve_management, Exists)

    localfilegdb = localProFileGDBWorkspace + '\\' + 'KhubRoadCenterlinesTemp' + fileformatDateStr + '.gdb'
    print(localfilegdb)
    sdegdb = KDOTConnections + r'\\' + database + r'\\' + dbname + "." + dbownername
    CalibrateD1 = sdegdb + ".All_Road_Centerlines_D1"
    RMRoute = sdegdb + "." + RuralClassifiedRoutes
    Croutes = sdegdb + "." + UrbanClassifiedRoutes
    FeatureClassToFeatureClass(RMRoute, localfilegdb, "RM_Routes")
    nusysprimary = "DIRECTION IN ('EB', 'NB') Or (DIVIDED_UNDIVIDED = 'U' And DIRECTION IN ('SB', 'WB'))"
    FeatureClassToFeatureClass(Croutes, localfilegdb, "C_Routes", nusysprimary)

    RMRoute = localfilegdb + "." + r"/RM_Routes"
    Croutes = localfilegdb + "." + r"/C_Routes"

    MakeFeatureLayer_management(CalibrateD1, "D1_NUSYS",
                                "LRS_ROUTE_PREFIX = 'C'", None, "#")
    MakeFeatureLayer_management(CalibrateD1, "D1_RM",
                                "LRS_ROUTE_PREFIX IN ('M', 'R')", None, "")

    print("making endpoints for nusys")
    FeatureVerticesToPoints_management("D1_NUSYS",
                                       localfilegdb + r"\Nusys_END", "END")
    FeatureVerticesToPoints_management("D1_NUSYS",
                                       localfilegdb + r"\Nusys_START", "START")
    print("making endpoints for rural")
    FeatureVerticesToPoints_management("D1_RM", localfilegdb + r"\RM_END",
                                       "END")
    FeatureVerticesToPoints_management("D1_RM", localfilegdb + r"\RM_START",
                                       "START")

    print("Exporting rural event tables")
    LocateFeaturesAlongRoutes_lr(localfilegdb + r"\RM_START", RMRoute,
                                 "LRS_KEY", "250 Feet",
                                 localfilegdb + r"\START_D1_RM",
                                 "LRS_KEY Point RM_MEAS", "ALL", "DISTANCE",
                                 "ZERO", "FIELDS", "M_DIRECTON")
    LocateFeaturesAlongRoutes_lr(localfilegdb + r"\RM_END", RMRoute, "LRS_KEY",
                                 "250 Feet", localfilegdb + r"\END_D1_RM",
                                 "LRS_KEY Point RM_MEAS", "ALL", "DISTANCE",
                                 "ZERO", "FIELDS", "M_DIRECTON")
    print("Exporting urban event tables")

    print("starting start c")

    LocateFeaturesAlongRoutes_lr(localfilegdb + r"\Nusys_START", Croutes,
                                 "Route", "250 Feet",
                                 localfilegdb + r"\START_D1_C",
                                 "LRS_KEY Point C_MEAS", "ALL", "DISTANCE",
                                 "ZERO", "FIELDS", "M_DIRECTON")
    print("starting end c")
    LocateFeaturesAlongRoutes_lr(localfilegdb + r"\Nusys_END", Croutes,
                                 "Route", "250 Feet",
                                 localfilegdb + r"\END_D1_C",
                                 "LRS_KEY Point C_MEAS", "ALL", "DISTANCE",
                                 "ZERO", "FIELDS", "M_DIRECTON")

    MakeRouteEventLayer_lr(RMRoute, "LRS_KEY", localfilegdb + r"\START_D1_RM",
                           "LRS_KEY Point RM_MEAS", "START_D1_RM Events", None,
                           "ERROR_FIELD", "ANGLE_FIELD", "NORMAL",
                           "COMPLEMENT", "LEFT", "POINT")
    MakeRouteEventLayer_lr(RMRoute, "LRS_KEY", localfilegdb + r"\END_D1_RM",
                           "LRS_KEY Point RM_MEAS", "END_D1_RM Events", None,
                           "ERROR_FIELD", "ANGLE_FIELD", "NORMAL",
                           "COMPLEMENT", "LEFT", "POINT")

    MakeRouteEventLayer_lr(Croutes, "Route", localfilegdb + r"\START_D1_C",
                           "LRS_KEY Point C_MEAS", "START_D1_C Events", None,
                           "ERROR_FIELD", "ANGLE_FIELD", "NORMAL",
                           "COMPLEMENT", "LEFT", "POINT")
    MakeRouteEventLayer_lr(Croutes, "Route", localfilegdb + r"\END_D1_C",
                           "LRS_KEY Point C_MEAS", "END_D1_C Events", None,
                           "ERROR_FIELD", "ANGLE_FIELD", "NORMAL",
                           "COMPLEMENT", "LEFT", "POINT")

    Dissolve_management(
        "START_D1_RM Events", localfilegdb + r"\START_D1_RM_DX",
        "LRS_KEY;RM_MEAS;KDOT_LRS_KEY",
        "Distance MIN;Distance MAX;KDOT_STATIC_ID2 FIRST;OBJECTID COUNT;RM_MEAS MIN;RM_MEAS MAX",
        "MULTI_PART", "DISSOLVE_LINES")
    FeatureClassToFeatureClass(localfilegdb + r"\START_D1_RM_DX", localfilegdb,
                               "START_D1_RM_D", "KDOT_LRS_KEY = LRS_KEY", "#")
    print("START_D1_RM_D")

    Dissolve_management(
        "END_D1_RM Events", localfilegdb + r"\END_D1_RM_DX",
        "LRS_KEY;RM_MEAS;KDOT_LRS_KEY",
        "Distance MIN;Distance MAX;KDOT_STATIC_ID2 FIRST;OBJECTID COUNT;RM_MEAS MIN;RM_MEAS MAX",
        "MULTI_PART", "DISSOLVE_LINES")
    FeatureClassToFeatureClass(localfilegdb + r"\END_D1_RM_DX", localfilegdb,
                               "END_D1_RM_D", "KDOT_LRS_KEY = LRS_KEY", "#")
    print("END_D1_RM_D")

    Dissolve_management(
        "START_D1_C Events", localfilegdb + r"\START_D1_C_DX",
        "LRS_KEY;C_MEAS;KDOT_LRS_KEY",
        "Distance MIN;Distance MAX;KDOT_STATIC_ID2 FIRST;OBJECTID COUNT;C_MEAS MIN;C_MEAS MAX",
        "MULTI_PART", "DISSOLVE_LINES")
    FeatureClassToFeatureClass(
        localfilegdb + r"\START_D1_C_DX", localfilegdb, "START_D1_C_D",
        "SUBSTRING(KDOT_LRS_KEY,0, 9) = SUBSTRING(LRS_KEY,0,9)", "#")
    print("START_D1_C_D")

    Dissolve_management(
        "END_D1_C Events", localfilegdb + r"\END_D1_C_DX",
        "LRS_KEY;C_MEAS;KDOT_LRS_KEY",
        "Distance MIN;Distance MAX;KDOT_STATIC_ID2 FIRST;OBJECTID COUNT;C_MEAS MIN;C_MEAS MAX",
        "MULTI_PART", "DISSOLVE_LINES")
    FeatureClassToFeatureClass(
        localfilegdb + r"\END_D1_C_DX", localfilegdb, "END_D1_C_D",
        "SUBSTRING(KDOT_LRS_KEY,0, 9) = SUBSTRING(LRS_KEY,0,9)", "#")
    print("END_D1_C_D")

    print(
        'Calibration process completed in {} hours, minutes, seconds.'.format(
            datetime.datetime.now() - startDateTime))
Ejemplo n.º 16
0
def SecondaryDirectionFinder():
    #make a point at the center of each line segment for a highway
    #No way currently to do this for RML highways,  NUSYS provides the directional layer for C highwyas
    #FeatureToPoint_management("State Highways", "in_memory/HighwayPoints", "INSIDE")
    #maybe two ways to do this, this time, I'm using midpoint from feature to point - catch
    FeatureVerticesToPoints_management(
        in_features="RoadCenterlines",
        out_feature_class="in_memory/HighwayPoints",
        point_location="MID")

    FeatureClassToFeatureClass_conversion(
        SRND,
        "in_memory",
        "SRND_NPD",
        where_clause="NETWORK_DIRECTION IN ( 'SB' , 'WB' )")

    #CRND SEcondary Direction is the CRND layer where "NETWORK_DIRECTION IN ( 'SB' , 'WB' )"
    #Locate Features Along Routes will calculate a +/- offset distance of the dual carriageway points from the CRND centerline
    LocateFeaturesAlongRoutes_lr("HighwayPoints", "SRND_NPD", "NE_UNIQUE",
                                 "500 Feet", "in_memory/HighwayPointsMeasures",
                                 "RID POINT MEAS", "ALL", "DISTANCE", "ZERO",
                                 "FIELDS", "M_DIRECTON")
    # Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script
    # The following inputs are layers or table views: "HighwayPointsMeasures"
    SelectLayerByAttribute_management(
        in_layer_or_view="HighwayPointsMeasures",
        selection_type="NEW_SELECTION",
        where_clause=
        """SUBSTRING( "RID", 1, 7) NOT  LIKE SUBSTRING("StateKey1", 1, 7)""")

    DeleteRows_management(in_rows="HighwayPointsMeasures")

    MakeRouteEventLayer_lr("SRND_NPD",
                           "NE_UNIQUE",
                           "HighwayPointsMeasures",
                           "rid POINT MEAS",
                           "HighwayPointEvents",
                           offset_field="Distance",
                           add_error_field="ERROR_FIELD",
                           add_angle_field="ANGLE_FIELD",
                           angle_type="NORMAL",
                           complement_angle="ANGLE",
                           offset_direction="RIGHT",
                           point_event_type="POINT")

    #select the secondary direction points
    MakeFeatureLayer_management("HighwayPointEvents", "NPD_ID",
                                """"Distance">=0""")

    # some random points, due to the 500 ft buffer I think, are getting included.  Select the event points that do not intersect a state highway road centerline feature
    #
    SelectLayerByLocation_management(in_layer="NPD_ID",
                                     overlap_type="INTERSECT",
                                     select_features="RoadCenterlines",
                                     search_distance="1 Feet",
                                     selection_type="NEW_SELECTION",
                                     invert_spatial_relationship="INVERT")

    FeatureClassToFeatureClass_conversion(
        "NPD_ID",
        "Database Connections/Conflation2012_sde.sde/Conflation.SDE.KANSAS_DOT",
        "Non_Primary_Divided_Highway", '"Distance">=0')
Ejemplo n.º 17
0
                                      "NE_UNIQUE LIKE 'U%'", "#")

routelyr = outws + "/USroutes"
rows = SearchCursor(routelyr)

for row in rows:
    print(row.getValue(IDfield))
    idc = str(row.getValue(IDfield)).replace("-", "_")
    print idc
    rfcx = str(row.getValue(IDfield)) + "_SRND"
    rfc = str(rfcx).replace("-", "_")
    print str(rfc)
    MakeFeatureLayer_management(
        routelyr, rfc, IDfield + " LIKE '" + row.getValue(IDfield) + "'")
    FeatureClassToGeodatabase_conversion(rfc, outws)
    FeatureVerticesToPoints_management(rfc, outws + "/" + idc + "_VP", "ALL")
    LocateFeaturesAlongRoutes_lr(outws + "/" + idc + "_VP", rfc, IDfield,
                                 "0 DecimalDegrees",
                                 outws + "/" + idc + "_CPT",
                                 "NE_UNIQUE POINT AASHTO_MEAS", "FIRST",
                                 "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON")
    DeleteIdentical_management(outws + "/" + idc + "_CPT",
                               "NE_UNIQUE;AASHTO_MEAS", "#", "0")
    Statistics_analysis(outws + "/" + idc + "_CPT",
                        outws + "/" + idc + "_ENDS",
                        "AASHTO_MEAS MIN;AASHTO_MEAS MAX", "NE_UNIQUE")
    AddJoin_management(idc + "_SRND", IDfield, outws + "/" + idc + "_ENDS",
                       IDfield, "KEEP_ALL")
    CreateRoutes_lr(idc + "_SRND", IDfield, outws + "/" + idc, "TWO_FIELDS",
                    idc + "_ENDS.MAX_AASHTO_MEAS",
                    idc + "_ENDS.MIN_AASHTO_MEAS", "UPPER_LEFT", "1", "0",