Beispiel #1
0
def CreateNUSYSLocal():
    MakeFeatureLayer_management(
        NonState, "NonState",
        "(LRS_KEY LIKE '%C%' OR LRS_ROUTE_PREFIX = 'C') AND (MILEAGE_COUNTED = -1 OR SURFACE = 'Propose')"
    )

    #NonState System has unique IDS that are also the non_persistent Object ID's
    #To force persistence on the Unique IDS, perform an intersect to the state boundary layer
    print "buffering the state boundary"
    Buffer_analysis(
        r"Database Connections/SDEPROD_SHARED.sde/SHARED.STATE_BOUNDARY",
        r"C:/temp/Nusys_Check.gdb/State_Boundary_1Mile", "5280 Feet", "FULL",
        "ROUND", "NONE", "", "PLANAR")
    print "intersecting non_state system to the state boundary to preserve Object ID's and eliminate non-spatial segments"
    MakeFeatureLayer_management(
        r"C:/temp/Nusys_Check.gdb/State_Boundary_1Mile", "StateBnd")
    Intersect_analysis("NonState #;StateBnd #",
                       r"C:/temp/Nusys_Check.gdb/Non_State_Classified", "ALL",
                       "-1 Unknown", "LINE")
    print "adding layers to gp workflow or MXD"
    NonState_fx = r'C:/temp/Nusys_Check.gdb/Non_State_Classified'

    MakeFeatureLayer_management(NUSYS, "Nusys_Extract",
                                "NSEC_SUB_CLASS <> 'R'")
    MakeFeatureLayer_management(NonState_fx, "Non_State_Classified")
Beispiel #2
0
def NONSTATE_INT():
    print "add intersection points where state routes intersect non-state routes"
    MakeFeatureLayer_management(nonstate, 'NON_STATE_SYSTEM',
                                "CITYNUMBER IS NOT NULL AND CITYNUMBER<999")
    MakeFeatureLayer_management(connection1 + NewRoute, NewRoute)
    Intersect_analysis(
        "CCL_LRS_ROUTE #;'NON_STATE_SYSTEM' #",
        connection1 + "Intersect_NONSTATE", "ALL", "5 Feet", "POINT"
    )  #this doesnt reference the newroute variable, its easier that way
    MakeFeatureLayer_management(connection1 + "Intersect_NONSTATE", "NSI")
    LocateFeaturesAlongRoutes_lr("NSI", "CCL_LRS_ROUTE", NewRouteKey, "5 Feet",
                                 connection1 + "INTR_CCL_NS",
                                 "CCL_LRS POINT MEASURE", "ALL", "DISTANCE",
                                 "ZERO", "FIELDS", "M_DIRECTON")
    MakeRouteEventLayer_lr("CCL_LRS_ROUTE", NewRouteKey,
                           connection1 + "INTR_CCL_NS",
                           "CCL_LRS POINT MEASURE", "INTR_CCL_NS Events", "#",
                           "ERROR_FIELD", "ANGLE_FIELD", "NORMAL", "ANGLE",
                           "LEFT", "POINT")
    AddField_management("INTR_CCL_NS Events", "CITY", "TEXT", "#", "#", "100")
    AddJoin_management("INTR_CCL_NS Events", "CITYNUMBER", citylimits,
                       "CITYNUMBER")
    #CalculateField_management("INTR_CCL_NS Events", schema+"INTR_CCL_NS_Features.CITY", "!GIS_DEV.CITY_LIMITS.CITY!", "PYTHON_9.3") #Preupdate
    CalculateField_management("INTR_CCL_NS Events",
                              schema + "INTR_CCL_NS_Features.CITY",
                              "!GIS.CITY_LIMITS.CITY!", "PYTHON_9.3")
    RemoveJoin_management("INTR_CCL_NS Events", "#")
    print "NonState_Int completed successfully."
Beispiel #3
0
def CrashOffsetPoints(gdb):
    #buffer and intersect the crash location to an offset distance, and select the points that hit the "on Road"
    from arcpy import SelectLayerByAttribute_management, AddJoin_management, Intersect_analysis, Buffer_analysis
    Buffer_analysis(
        in_features="Geocoding Result: Geocoding_Result_9",
        out_feature_class=
        "//gisdata/arcgis/GISdata/Accident Geocode/GC_OFFSET_20150210.gdb/Geocoding_Result_9_Buffer",
        buffer_distance_or_field="AT_ROAD_KDOT_DIST_FEET",
        line_side="FULL",
        line_end_type="ROUND",
        dissolve_option="NONE",
        dissolve_field="",
        method="PLANAR")
    AddJoin_management(in_layer_or_view="RoadCenterline",
                       in_field="SEGID",
                       join_table="RoadAlias",
                       join_field="RoadAlias.SEGID",
                       join_type="KEEP_ALL")
    Intersect_analysis(
        in_features="Geocoding_Result_9_Buffer #;RoadCenterline #",
        out_feature_class=
        "//gisdata/arcgis/GISdata/Accident Geocode/GC_OFFSET_20150210.gdb/Geocoding_Result_9_Buffer_In",
        join_attributes="ALL",
        cluster_tolerance="-1 Unknown",
        output_type="POINT")
    SelectLayerByAttribute_management(
        in_layer_or_view="Geocoding_Result_9_Buffer_In",
        selection_type="NEW_SELECTION",
        where_clause=
        "ON_ROAD_KDOT_NAME like RoadAlias_KDOT_ROUTENAME OR ON_ROAD_KDOT_NAME like RoadCenterline_RD"
    )
Beispiel #4
0
def CreateRuralRMLocal():
    MakeFeatureLayer_management(NonState, "NonStateRM", "((LRS_KEY LIKE '%R%' OR LRS_ROUTE_PREFIX = 'R') OR (LRS_KEY LIKE '%M%' OR LRS_ROUTE_PREFIX = 'M')) AND (MILEAGE_COUNTED = -1 OR SURFACE = 'Propose')")
    print "buffering the state boundary"
    Buffer_analysis(r"Database Connections/SDEPROD_SHARED.sde/SHARED.STATE_BOUNDARY", r"C:/temp/Nusys_Check.gdb/State_Boundary_1Mile", "5280 Feet", "FULL", "ROUND", "NONE", "", "PLANAR")
    print "intersecting non_state system to the state boundary to preserve Object ID's and eliminate non-spatial segments"
    MakeFeatureLayer_management(r"C:/temp/Nusys_Check.gdb/State_Boundary_1Mile", "StateBnd" )
    Intersect_analysis("NonStateRM #;StateBnd #", r"C:/temp/Nusys_Check.gdb/Non_State_RuralClass", "ALL", "-1 Unknown", "LINE")
    print "adding layers to gp workflow or MXD"
    NonState_fx = r'C:/temp/Nusys_Check.gdb/Non_State_RuralClass'
    
    #MakeFeatureLayer_management(NUSYS, "Nusys_Extract", "NSEC_SUB_CLASS <> 'R'" )
    MakeFeatureLayer_management(NonState_fx, "Non_State_RuralClass" )
Beispiel #5
0
def Create_CCL_Calibration_Points():
    # Intersect GIS.City_Limits with SMLRS to obtain points layer
    # write to file geodatabase.
    MakeFeatureLayer_management(stateroutelyr, "smlrs_d")
    MakeFeatureLayer_management(citylimits, "citylimits_d",
                                "TYPE IN ( 'CS', 'ON')")
    intersectFeaures = ["smlrs_d", "citylimits_d"]
    print "Intersecting State Routes and City Limits"
    Intersect_analysis(intersectFeaures,
                       r"D:\workspaces\pythontests.gdb\cal_points_multi",
                       "NO_FID", "", "point")

    # Split the multipoint features into single points and place in another layer.
    print "Splitting multipart points into single points."
    MultipartToSinglepart_management(
        r"D:\workspaces\pythontests.gdb\cal_points_multi",
        r"D:\workspaces\pythontests.gdb\cal_points_simple")

    # Clean the simple points layer by removing extraneous fields.

    # Locate the created points layer along the SMLRS routes to
    # generate a table with measurements.
    print "Locating the edge of city boundary points along the state system."
    reloc_properties = "point_LRS POINT point_Loc"

    #fieldList = ListFields("smlrs_d")
    #for field in fieldList:
    #print str(field.name)

    LocateFeaturesAlongRoutes_lr(
        r"D:\workspaces\pythontests.gdb\cal_points_simple", "smlrs_d",
        "LRS_ROUTE", "10 Feet",
        r"D:\workspaces\pythontests.gdb\cal_points_reloc", reloc_properties,
        "FIRST", "NO_DISTANCE", "NO_ZERO", "NO_FIELDS")

    point_Properties = "point_LRS POINT point_Loc"
    MakeRouteEventLayer_lr("smlrs_d", "LRS_ROUTE",
                           r"D:\workspaces\pythontests.gdb\cal_points_reloc",
                           point_Properties, "new_point_locations")

    CopyFeatures_management(
        "new_point_locations",
        r"D:\workspaces\pythontests.gdb\CCL_Point_Calibrators")

    # Use this set of points as the calibration points for the
    # CCL_LRS_ROUTE layer's calibration.

    # Add the measure values to the points layer so that it can be
    # used to calibrate the measures of the CCL_LRS routes.
    print "Calibration Points created."
Beispiel #6
0
def Non_State_Centerpoint_Check():
    MakeFeatureLayer_management(in_features="Database Connections/SDEPROD_SHARED.sde/SHARED.NON_STATE_SYSTEM", out_layer="C_Routes", where_clause="LRS_KEY like '%C%' OR  LRS_ROUTE_PREFIX = 'C'")
    FeatureToPoint_management(NonState_fx, "C_Routes_Point", "INSIDE")
    #LocateFeaturesAlongRoutes_lr(NonState_fx, NUSYS, "ROUTE", "50 Feet", "Nonstate_Point_LFAR", "RID LINE FMEAS TMEAS", "FIRST", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON")
    Intersect_analysis("Nusys_Extract #;C_Routes #", out_feature_class="C:/temp/Nusys_Check.gdb/C_Routes_Point_Int5", join_attributes="ALL", cluster_tolerance="5 Feet", output_type="POINT")
    
    Dissolve_management("C_Routes_Point_Int5", out_feature_class="C:/temp/Nusys_Check.gdb/C_Routes_Point_Int_Route_Mileage_5D", dissolve_field="ROUTE;DIVIDED_UNDIVIDED;LRS_KEY", statistics_fields="COUNTY_BEGIN_MP MIN;COUNTY_END_MP MAX;LRS_BEG_CNTY_LOGMILE MIN;LRS_END_CNTY_LOGMILE MAX", multi_part="MULTI_PART", unsplit_lines="DISSOLVE_LINES")

    AddField_management(in_table="C_Routes_Point_Int_Route_Mileage_5D", field_name="Check_LRS", field_type="TEXT", field_precision="", field_scale="", field_length="15", field_alias="", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="")
    CalculateField_management(in_table="C_Routes_Point_Int_Route_Mileage_5D", field="Check_LRS", expression="!LRS_KEY![:11]", expression_type="PYTHON_9.3", code_block="")
    
    AddField_management(in_table="C_Routes_Point_Int_Route_Mileage_5D", field_name="Check_Route", field_type="TEXT", field_precision="", field_scale="", field_length="15", field_alias="", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="")
    CalculateField_management(in_table="C_Routes_Point_Int_Route_Mileage_5D", field="Check_Route", expression="!Route![:11]", expression_type="PYTHON_9.3", code_block="")    
    
    MakeFeatureLayer_management("C_Routes_Point_Int_Route_Mileage_5D", out_layer="C_Routes_Check_Del", where_clause="Check_Route <> Check_LRS OR Check_Route is null OR Check_LRS is null")
    DeleteFeatures_management("C_Routes_Check_Del")
Beispiel #7
0
def FIMS_GIS(FMIS_ADD):
    #arcpy.MakeFeatureLayer_management(CPMSlyr, 'CPMS', ProjectSelect)
    #only process the new rows in FMIS_ADD

    MakeFeatureLayer_management(CPMSlyr, 'CPMS')
    MakeFeatureLayer_management(CountyLyr, 'County')
    MakeFeatureLayer_management(HPMSlyr, 'HPMS')
    MakeFeatureLayer_management(MPOLyr, 'MPO')
    MakeFeatureLayer_management(CONGDistlyr, 'CONG')
    MakeFeatureLayer_management(ws + "/Polygons", 'Polygons')
    #make the polygon analysis layer for Districts, Counties, and MPOs
    #arcpy.Union_analysis("CONG #;MPO #;County #",ws+"/Polygons","ALL","1 feet","GAPS")

    MakeTableView_management(FMIS_ADD, 'CPMS_STAGING_TMP')
    AddJoin_management("CPMS", "PROJECT_ID", "CPMS_STAGING_TMP",
                       "PROJECT_NUMBER", "KEEP_COMMON")

    Output_Event_Table_Properties = 'RID LINE CNTY_BEG CNTY_END'

    outtblP = ws + "/FIMS_EventTableAreas"
    outtblH = ws + "/FIMS_EventTableLines"

    if Exists(outtblP):
        Delete_management(outtblP)

    #consider/testing running "in memory"
    LocateFeaturesAlongRoutes_lr('CPMS', 'HPMS', "Route_ID", "30 Feet",
                                 outtblH, Output_Event_Table_Properties,
                                 "FIRST", "DISTANCE", "NO_ZERO", "FIELDS",
                                 "M_DIRECTON")
    MakeRouteEventLayer_lr("HPMS", "Route_ID", "FIMS_EventTableLines",
                           "rid LINE CNTY_BEG CNTY_END",
                           "FIMS_EventTableLineLyr", "#", "ERROR_FIELD",
                           "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT",
                           "POINT")
    Intersect_analysis("FIMS_EventTableLineLyr #;HPMS #;Polygons #",
                       ws + "/FMIS_Data", "ALL", "#", "LINE")

    Dissolve_management(
        "FMIS_Data", ws + r"/HPMS_Data",
        "PROJECT_ID;F_SYSTEM_V;NHS_VN;DISTRICT_1;COUNTY_NUMBER;ID_1", "#",
        "MULTI_PART", "UNSPLIT_LINES")
    # 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
    LocateFeaturesAlongRoutes_lr("HPMS_Data", "HPMS", "Route_ID", "0 Feet",
                                 ws + "/FIMS_EventTable",
                                 "RID LINE CNTY_BEG CNTY_END", "FIRST",
                                 "DISTANCE", "NO_ZERO", "FIELDS", "M_DIRECTON")
Beispiel #8
0
def calibrationCCL():
    
    print "deriving CCL LRS starting points and calibrations"
    CCLEnd = "!"+schema+"CITY_CONNECTING_LINK_STATE.MAX_END_STATE_LOGMILE!- !"+schema+"CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!"
    CCLBeg = "!"+schema+"CITY_CONNECTING_LINK_STATE.MIN_BEG_STATE_LOGMILE! - !"+schema+"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"
    statecalpoints = stateroutelyr+"_Point"
    print statecalpoints
    MakeFeatureLayer_management(statecalpoints, "smlrs_pt")
    print connection1+"CITY_CONNECTING_LINK_STATE_D"
    MakeFeatureLayer_management(connection1+"CITY_CONNECTING_LINK_STATE_D", "dissolved_res_sects")
    intersects = ["dissolved_res_sects", "smlrs_pt"]
    Intersect_analysis(intersects,connection0+"CALIBRATION_POINTS_CCL","ALL","#","POINT")
    print connection1+"CALIBRATION_POINTS_CCL"
    MakeFeatureLayer_management(connection1+"CALIBRATION_POINTS_CCL", "Calibrators")
    querystr = "Substring( CCL_LRS,4, 12)<> LRS_ROUTE"  
    SelectLayerByAttribute_management("Calibrators","NEW_SELECTION",querystr)
    DeleteRows_management("Calibrators")
    MakeFeatureLayer_management(connection1+"CITY_CONNECTING_LINK_STATE", "CCL_sections")
    DeleteIdentical_management("Calibrators","LRS_KEY;POINT_X;POINT_Y;POINT_M","#","0")
    AddField_management("CCL_sections","CCL_BEGIN","DOUBLE","#","#","#","#","NULLABLE","NON_REQUIRED","#")
    AddField_management("CCL_sections","CCL_BEGIN","DOUBLE","#","#","#","#","NULLABLE","NON_REQUIRED","#")
    AddJoin_management("CCL_sections","CCL_LRS","dissolved_res_sects","CCL_LRS","KEEP_ALL")
    CalculateField_management("CCL_sections",schema+"CITY_CONNECTING_LINK_STATE.CCL_BEGIN","!"+schema+"CITY_CONNECTING_LINK_STATE.MIN_BEG_STATE_LOGMILE!- !"+schema+"CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!","PYTHON","#")
    CalculateField_management("CCL_sections",schema+"CITY_CONNECTING_LINK_STATE.CCL_END","!"+schema+"CITY_CONNECTING_LINK_STATE.MAX_END_STATE_LOGMILE!- !"+schema+"CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!","PYTHON","#")
    AddField_management(connection1+"CALIBRATION_POINTS_CCL","CCL_MEASURE", "DOUBLE", 12, 3)
    CalculateField_management("Calibrators","CCL_MEASURE","!POINT_M!- !MIN_BEG_STATE_LOGMILE!","PYTHON","#")
    CreateRoutes_lr(LineFeatureClass,NewRouteKey,connection1+NewRoute+"base","TWO_FIELDS",NewBeg, NewEnd,"UPPER_LEFT","1","0","IGNORE","INDEX")
    CalibrateRoutes_lr(connection0+"/"+schema+"CCL_LRS_ROUTEbase","CCL_LRS",connection1+"CALIBRATION_POINTS_CCL","CCL_LRS","CCL_MEASURE",connection1+"CCL_LRS_ROUTE","DISTANCE","1 Feet","BETWEEN","NO_BEFORE","NO_AFTER","IGNORE","KEEP","INDEX")
    AddField_management(connection1+NewRoute, "NETWORKDATE", "DATE")
    CalculateField_management(connection1+NewRoute,"NETWORKDATE","datetime.datetime.now( )","PYTHON_9.3","#")
    MakeFeatureLayer_management(connection1+"CCL_LRS_ROUTE", NewRoute)
Beispiel #9
0
#generate set of obstacles for circular cover 
clip_obs_shp = [x.intersection(cover_shp) for x in obstacles_shp]
clip_obs_shp = [x for x in clip_obs_shp if not x.is_empty]
init_clip_obs_shp = [x for x in clip_obs_shp if not x.is_empty]

terminate = False
#begin main loop 
dealt_obs = []

while terminate == False:
    #first loop: generate 
    #For each iteration, list of obstacles is updated using updated coverage. 
    #Remove obstacles that cannot be covered with the updated coverage 
    clip_obs_shp = [x for x in clip_obs_shp if not x in dealt_obs]
    saveShp(clip_obs_shp, 'polygon', path, 'clip_obs.shp')
    Intersect_analysis(['cover_shp.shp', 'clip_obs.shp'], 'clip_obs_inter.shp')
    clip_obs_multi = file2Shp('clip_obs_inter.shp')
    
    #clip_obs_shp = [x.intersection(cover_shp) for x in clip_obs_shp]
    #clip_obs_shp = [x for x in clip_obs_shp if not x.is_empty]    
    
    #convex hulls for clipped obstacles
    #sort them as distance between facility and centorids 
    cent_clip_obs = [(x.centroid, x) for x in clip_obs_shp]
    cent_dist_clip_obs = [(x[0].distance(facil_shp[0]), x[1]) for x in cent_clip_obs]
    cent_dist_clip_obs.sort()
    dealt_obs.append(cent_dist_clip_obs[0][1])
    saveShp([cent_dist_clip_obs[0][1]], 'polygon', path, 'dealtobs.shp')
    chs = [(createConvexhull(x[1], facil_coords), x[1]) for x in cent_dist_clip_obs]
    #pick closest one to facility 
    ch_vertices = list(chs[0][0].exterior.coords)
Beispiel #10
0
def bufferCrashLocationAndIntersectWithRoads(crashObject, roadsLayer,
                                             outputIncrementInt,
                                             bufferAndIntersectSR,
                                             useParseMatchAddr):
    #pointToBufferXY = list(crashObject.initialShapeXY)
    #print("The crashObject.initialShapeXY is " + str(crashObject.initialShapeXY) + " and the pointToBufferXY is " + str(pointToBufferXY) + ".")
    ##pointToBufferWithoutGeometry = Point(pointToBufferXY)
    ##pointToBuffer = PointGeometry(pointToBufferXY, bufferAndIntersectSR)
    pointToBuffer = crashObject.initialShape
    offsetDistance = crashObject.offsetDistance

    # Perform layer selection here, then
    # intersect the buffer with the selected roads.

    roadNameColumns = crashObject.roadNameColumns

    accidentClusterTolerance = 2

    print(
        "Attempting to buffer and offset the crashObject with a unique key of: "
        + str(crashObject.uniqueKey) + ".")
    print("Using the roadNameColumns of: " + str(roadNameColumns) + ".")

    singlePartOffsetFeaturesList = list()

    try:
        if offsetDistance >= 5:
            ## Was previously failing here due to not having the name for intermediateAccidentBuffer
            offsetDistanceString = str(offsetDistance) + " Feet"
            Buffer_analysis(pointToBuffer, intermediateAccidentBuffer,
                            offsetDistanceString, "", "", "", "", "PLANAR")

            if debugOutputValue == True:
                # Save the buffer here. Call it bufferOutput_001 to start with, and increment from there. Get the number
                # from the calling script.
                bufferOutputLocation = bufferOutputLocationBase + "_" + str(
                    outputIncrementInt).zfill(4)
                copyFCToTempLocation(intermediateAccidentBuffer,
                                     bufferOutputLocation)
            else:
                pass

            firstRoadName = str(crashObject.onRoad)
            firstRoadName = firstRoadName.upper()

            roadNameValues = [firstRoadName]

            if useParseMatchAddr == True:
                parsedRoadNamesList = ParseMatchAddr(crashObject.matchAddress)
                secondRoadName = " "
                try:
                    secondRoadName = parsedRoadNamesList[0]
                    secondRoadName = secondRoadName.upper()
                except:
                    pass
                thirdRoadName = " "
                try:
                    thirdRoadName = parsedRoadNamesList[1]
                    thirdRoadName = thirdRoadName.upper()
                except:
                    pass

                roadNameValues = [firstRoadName, secondRoadName, thirdRoadName]
            else:
                pass

            streetWhereClause = generateWhereClause(roadNameColumns,
                                                    roadNameValues)
            print("The generated whereClause is: " + str(streetWhereClause) +
                  ".")
            SelectLayerByAttribute_management(roadsLayer, "NEW_SELECTION",
                                              streetWhereClause)

            selectionCount = str(GetCount_management(roadsLayer))

            if Exists(intermediateAccidentIntersect):
                try:
                    Delete_management(intermediateAccidentIntersect)
                except:
                    pass
            else:
                pass

            if int(selectionCount) != 0:
                featuresToIntersect = [roadsLayer, intermediateAccidentBuffer]
                Intersect_analysis(featuresToIntersect,
                                   intermediateAccidentIntersect, "ALL",
                                   accidentClusterTolerance, "POINT")

                time.sleep(0.25)
                # Wait a moment for the FC to settle.
                # And yes, it is ridiculous that the Intersect_analysis function would return without
                # its output being there and ready to use, but... *ahem*.
                # If it doesn't exist despite having been just created, then skip to the next record.
                if not (Exists(intermediateAccidentIntersect)):
                    print("There was no output from Intersect_analysis.")
                    crashObject.singlePartOffsetFeaturesList = None
                    return crashObject
                else:
                    pass

                if debugOutputValue == True:
                    # Save the intersect FC here. Call it intersectOutput_001 to start with, and increment from there. Get the number
                    # from the calling script.
                    intersectOutputLocation = intersectOutputLocationBase + "_" + str(
                        outputIncrementInt).zfill(4)
                    copyFCToTempLocation(intermediateAccidentIntersect,
                                         intersectOutputLocation)
                else:
                    pass

                # GetCount_management is not particularly Pythonic.
                countResult = GetCount_management(
                    intermediateAccidentIntersect)
                if int(countResult.getOutput(0)) > 0:
                    MultipartToSinglepart_management(
                        intermediateAccidentIntersect,
                        intermediateAccidentIntersectSinglePart)

                    # Maybe add a feature class to contain all of the single part points that get generated in multipart to singlepart.
                    singlePartsCursor = daSearchCursor(
                        intermediateAccidentIntersectSinglePart,
                        ['SHAPE@', 'SHAPE@XY'])
                    for singlePartRow in singlePartsCursor:
                        ##KDOTXYFieldsList = ['OBJECTID', 'STATUS', 'POINT_X', 'POINT_Y', 'ACCIDENT_KEY', 'ON_ROAD_KDOT_NAME',
                        ##                      'AT_ROAD_KDOT_DIRECTION', 'AT_ROAD_KDOT_DIST_FEET', 'AT_ROAD_KDOT_NAME',
                        ##                       'Match_addr']
                        print("The singlePartRow value is: " +
                              str(singlePartRow) + ".")
                        print(
                            "The singlePartRow[1][0] and singlePartRow[1][1] values are: "
                            + str(singlePartRow[1][0]) + " and " +
                            str(singlePartRow[1][1]) + ".")
                        print(
                            "The crashObject.initialShapeXY[0] and crashObject.initialShapeXY[1] values are: "
                            + str(crashObject.initialShapeXY[0]) + " and " +
                            str(crashObject.initialShapeXY[1]) + ".")
                        singlePartListItem = [
                            crashObject.initialShapeXY[0],
                            crashObject.initialShapeXY[1], singlePartRow[1][0],
                            singlePartRow[1][1], singlePartRow[0]
                        ]
                        #Previously used, but no longer necessary = , geocodedAccident[0]]
                        singlePartOffsetFeaturesList.append(singlePartListItem)

                    try:
                        del singlePartsCursor
                    except:
                        pass
                else:
                    print(
                        "There were zero output features counted in the intermediateAccidentIntersect feature class."
                    )
                    crashObject.singlePartOffsetFeaturesList = None
                    return crashObject
            else:
                pass  # Zero road segments selected. Will not attempt to offset.
        else:
            print(
                "This should have been caught by the lowOrZeroDistanceOffsetCheck function, but the accidentDistanceOffset is not >= 5."
            )
    except:
        print "WARNING:"
        print "An error occurred which prevented the crash point with Acc_Key: " + str(
            crashObject.uniqueKey)
        print "from being buffered and/or offset properly."
        print(traceback.format_exc())

    crashObject.singlePartOffsetFeaturesList = singlePartOffsetFeaturesList

    return crashObject
def createShortGradiculeLinesForEachCounty():
    # Get/use the same projection as the one used for the county roads.
    spatialReferenceProjection = Describe(
        sharedNonStateSystem).spatialReference

    env.workspace = sqlGdbLocation

    inputCountyGradicule = countyCountyGradicule
    bufferedCounties = 'bufferedCounties'
    countiesToCopy = 'countiesToCopy'
    gradiculeToCopy = 'gradiculeToCopy'
    loadedGradiculeCopy = 'loadedGradiculeCopy'
    loadedTempGradicule = 'loadedTempGradicule'
    #unBufferedCounties = 'unBufferedCounties'
    # Using the miniBuffered process changes it from
    # 1457 total output features to 1481 (at 2.1k)
    # total output features.
    miniBufferedCounties = 'miniBufferedCounties'
    loadedOutputGradicule = 'loadedOutputGradicule'
    tempCounties = r'in_memory\tempCounties'
    tempCountyGradicule = r'in_memory\tempCountyGradicule'
    tempCountyGradiculePostErase = r'in_memory\tempCountyGradiculePostErase'
    tempCountyGradiculeSinglePart = r'in_memory\tempCountyGradiculeSinglePart'
    bufferCursorFields = ["OBJECTID", "COUNTY_NAME"]

    MakeFeatureLayer_management(sharedCounties, countiesToCopy)

    MakeFeatureLayer_management(countyCountyGradicule, gradiculeToCopy)
    CopyFeatures_management(gradiculeToCopy, countyGradiculeCopied)
    MakeFeatureLayer_management(countyGradiculeCopied, loadedGradiculeCopy)

    # Might be worth dissolving based on COORD & County_Name prior
    # to removing the County_Name field, if that's a possibility.

    # Or better yet, just make it so that the Gradicule lines for
    # a particular county are eligible for intersecting and
    # erasing with that same county's polygon's.  All we're
    # trying to do here is make it so that the county's original
    # gradicule lines are about half of their original size.
    # Don't need to find out which gradicule lines are close to
    # the county or anything else like that. Just need to reduce
    # the size of the lines and keep the parts that are nearest
    # the county that they go with.

    # Remove the County_Name field so that the intersect can add it
    # back and populate it only where the county buffer actually
    # intersects the lines.
    #DeleteField_management(countyGradiculeCopied, "County_Name")

    # Elaine requested that this be 1000 Feet shorter.
    # I made it 2000 feet shorter, because it still seemed too big.
    Buffer_analysis(sharedCounties, countiesBuffered, "8000 Feet")
    Buffer_analysis(sharedCounties, countiesMiniBuffered, "1500 Feet")

    bufferedCountyPolygonList = list()
    outputFeatureList = list()

    # 1st SearchCursor
    newCursor = daSearchCursor(countiesBuffered, bufferCursorFields)
    for newRow in newCursor:
        bufferedCountyPolygonList.append(list(newRow))

    if 'newCursor' in locals():
        del newCursor
    else:
        pass

    MakeFeatureLayer_management(countiesBuffered, bufferedCounties)
    MakeFeatureLayer_management(countiesMiniBuffered, miniBufferedCounties)

    loadedCountiesFields = ListFields(bufferedCounties)

    for loadedCountiesField in loadedCountiesFields:
        print "A loadedCountiesField was found: " + str(
            loadedCountiesField.name)

    countyGradiculeFields = ListFields(loadedGradiculeCopy)

    for countyGradiculeField in countyGradiculeFields:
        print "A countyGradiculeField was found: " + str(
            countyGradiculeField.name)

    for listedRow in bufferedCountyPolygonList:
        print str(listedRow)
        selectCounty = listedRow[1]

        whereClause = """ "COUNTY_NAME" = '""" + str(selectCounty) + """' """
        print "The whereClause is " + str(whereClause)
        SelectLayerByAttribute_management(bufferedCounties, "NEW_SELECTION",
                                          whereClause)

        SelectLayerByAttribute_management(loadedGradiculeCopy, "NEW_SELECTION",
                                          whereClause)

        Intersect_analysis([loadedGradiculeCopy, bufferedCounties],
                           tempCountyGradicule, "ALL")

        MultipartToSinglepart_management(tempCountyGradicule,
                                         tempCountyGradiculeSinglePart)

        # Selects the same county as the other Select, but does it from the miniBufferedCounties
        # so that the lines which lay inside of the county and running just along its edges
        # are erased, as they should only exist as gradicules for the counties adjoining this
        # one, but not for this one itself.
        SelectLayerByAttribute_management(miniBufferedCounties,
                                          "NEW_SELECTION", whereClause)

        MakeFeatureLayer_management(tempCountyGradiculeSinglePart,
                                    loadedTempGradicule)

        SelectLayerByAttribute_management(loadedTempGradicule, "NEW_SELECTION",
                                          whereClause)

        secVerGradiculeFields = ListFields(loadedTempGradicule)

        #for secVerGradiculeField in secVerGradiculeFields:
        #    print "A secVerGradiculeField was found: " + str(secVerGradiculeField.name)

        Erase_analysis(loadedTempGradicule, miniBufferedCounties,
                       tempCountyGradiculePostErase, xyToleranceVal)

        fieldsToCopy = [
            "SHAPE@", "County_Number", "County_Name", "DIRECTION", "COORD"
        ]

        # 2nd SearchCursor
        newCursor = daSearchCursor(tempCountyGradiculePostErase, fieldsToCopy)
        for newRow in newCursor:
            outputFeatureList.append(newRow)

        if 'newCursor' in locals():
            del newCursor
        else:
            pass

    try:
        Delete_management(countyGradiculeShortWithUser)
    except:
        pass

    CreateFeatureclass_management(sqlGdbLocation, countyGradiculeShortNoPath,
                                  "POLYLINE", "", "", "",
                                  spatialReferenceProjection)

    AddField_management(countyGradiculeShortNoPath, "County_Number", "DOUBLE",
                        "", "", "")

    AddField_management(countyGradiculeShortNoPath, "County_Name", "TEXT", "",
                        "", "55")

    AddField_management(countyGradiculeShortNoPath, "DIRECTION", "TEXT", "",
                        "", "5")

    AddField_management(countyGradiculeShortNoPath, "COORD", "TEXT", "", "",
                        "30")

    print "First Intersected County Gradicule Row: " + str(
        outputFeatureList[0])

    newCursor = daInsertCursor(countyGradiculeShortPath, fieldsToCopy)
    counter = 1
    for outputFeature in outputFeatureList:
        rowToInsert = ([outputFeature])

        insertedOID = newCursor.insertRow(outputFeature)

        counter += 1

        print "Inserted Row with Object ID of " + str(insertedOID)

    # Load the feature class. Remove anything shorter than 850 feet.
    MakeFeatureLayer_management(countyGradiculeShortPath,
                                loadedOutputGradicule)

    # Select the rows that have geometry which is shorter than 850 feet.
    ## Note that Shape.STLength() returns units in the projection
    ## or coordinate system that it the feature class is stored in.
    whereClause = """ Shape.STLength() <  850 """
    print "The whereClause is " + str(whereClause)
    SelectLayerByAttribute_management(loadedOutputGradicule, "NEW_SELECTION",
                                      whereClause)

    # If there is at least one row selected, delete each selected row.
    if int(GetCount_management(loadedOutputGradicule).getOutput(0)) > 0:
        print str(GetCount_management(loadedOutputGradicule).getOutput(
            0)) + "rows selected."
        DeleteRows_management(loadedOutputGradicule)
    else:
        print "No rows were selected to delete."

    if 'newCursor' in locals():
        del newCursor
    else:
        pass
def extendAndIntersectRoadFeatures(
    quarterOrHalf
):  # Place the operations that extend each road line segment by a certain distance here.
    # Should extend all the features that exist in the post-erase dataset. Might be more difficult
    # to calculate the angle of these lines accurately, but it should be easier to figure out
    # than trying to get the lines to split correctly with the buggy SplitLineAtPoint tool.

    if quarterOrHalf.lower() == "quarter":
        extensionLinesTextName = "createdExtensionLines_Q"
        createdExtensionLines = createdExtensionLines_Q
        # 9000 ft increase for _Q version.
        # Must be larger than the county bufferDistance (20000)
        extensionDistance = 31176
        extensionLinesTextName = "createdExtensionLines_Q"
        countyRoadNameRosette = countyRoadNameRosette_Q
        rosetteTextName = "countyRoadNameRosette_Q"
        tempRoadNameRosette = tempRoadNameRosette_Q
        tempRosetteTextName = "tempRoadNameRosette_Q"
        tempRoadNameRosetteSP = tempRoadNameRosetteSinglePoint_Q
        tempRosetteSPTextName = "tempRoadNameRosetteSinglePoint_Q"
        countyBorderFeature = countyBorderFeature_Q
    elif quarterOrHalf.lower() == "half":
        extensionLinesTextName = "createdExtensionLines_H"
        createdExtensionLines = createdExtensionLines_H
        # Must be larger than the county bufferDistance (11000)
        extensionDistance = 22176
        extensionLinesTextName = "createdExtensionLines_H"
        countyRoadNameRosette = countyRoadNameRosette_H
        rosetteTextName = "countyRoadNameRosette_H"
        tempRoadNameRosette = tempRoadNameRosette_H
        tempRosetteTextName = "tempRoadNameRosette_H"
        tempRoadNameRosetteSP = tempRoadNameRosetteSinglePoint_H
        tempRosetteSPTextName = "tempRoadNameRosetteSinglePoint_H"
        countyBorderFeature = countyBorderFeature_H
    else:
        print "quarterOrHalf variable not correctly defined."
        raise (Exception("quarterOrHalf value error."))

    print "Starting to extend and intersect road features."

    if Exists(createdExtensionLines):
        Delete_management(createdExtensionLines)
    else:
        pass

    CreateFeatureclass_management(inMemGDB, extensionLinesTextName, "POLYLINE",
                                  "", "", "", spatialReferenceProjection)

    # Add a column for roadname called roadNameForSplit.
    AddField_management(createdExtensionLines, "roadNameForSplit", "TEXT", "",
                        "", "55")

    # Add a column which stores the angle to display a label called called LabelAngle.
    AddField_management(createdExtensionLines, "LabelAngle", "DOUBLE", "", "",
                        "")  # Change to double.

    # Add a column which stores the County Number.
    AddField_management(createdExtensionLines, "County_Number", "DOUBLE", "",
                        "", "")

    roadLinesToInsertList = list()

    roadLinesList = getRoadLinesList()

    for roadLinesItem in roadLinesList:

        roadNameToUse = roadLinesItem[2]
        countyNumber = roadLinesItem[3]

        linePointsArray = ArcgisArray()

        firstPointTuple = (roadLinesItem[1].firstPoint.X,
                           roadLinesItem[1].firstPoint.Y)
        lastPointTuple = (roadLinesItem[1].lastPoint.X,
                          roadLinesItem[1].lastPoint.Y)

        # Make this a two-step process.
        # Might be as simple as
        # adding _1 to the end of the first set of variables,
        # adding _2 to the end of the second set of variables,
        # then making the extensions in both directions
        # and creating a new line that has the endpoints
        # from both sides as it's first and last point.
        # if necessary, could add the other points in between
        # but probably not necessary just for generating
        # an intersection point.

        yValue_1 = -(lastPointTuple[1] - firstPointTuple[1]
                     )  # made y value negative
        xValue_1 = lastPointTuple[0] - firstPointTuple[0]

        lineDirectionAngle_1 = math.degrees(math.atan2(
            xValue_1, yValue_1))  # reversed x and y

        lineDirectionAngle_1 = -(((lineDirectionAngle_1 + 180) % 360) - 180
                                 )  # correction for certain quadrants
        #print "lineDirectionAngle: " + str(lineDirectionAngle_1)

        origin_x_1 = firstPointTuple[0]
        origin_y_1 = firstPointTuple[1]

        yValue_2 = -(firstPointTuple[1] - lastPointTuple[1]
                     )  # made y value negative
        xValue_2 = firstPointTuple[0] - lastPointTuple[0]

        lineDirectionAngle_2 = math.degrees(math.atan2(
            xValue_2, yValue_2))  # reversed x and y

        lineDirectionAngle_2 = -(((lineDirectionAngle_2 + 180) % 360) - 180
                                 )  # correction for certain quadrants
        #print "lineDirectionAngle: " + str(lineDirectionAngle_2)

        origin_x_2 = lastPointTuple[0]
        origin_y_2 = lastPointTuple[1]

        (disp_x_1, disp_y_1) = (extensionDistance *
                                math.sin(math.radians(lineDirectionAngle_1)),
                                extensionDistance *
                                math.cos(math.radians(lineDirectionAngle_1)))

        (end_x_1, end_y_1) = (origin_x_1 + disp_x_1, origin_y_1 + disp_y_1)

        (disp_x_2, disp_y_2) = (extensionDistance *
                                math.sin(math.radians(lineDirectionAngle_2)),
                                extensionDistance *
                                math.cos(math.radians(lineDirectionAngle_2)))

        (end_x_2, end_y_2) = (origin_x_2 + disp_x_2, origin_y_2 + disp_y_2)

        startPoint = ArcgisPoint()
        endPoint = ArcgisPoint()

        startPoint.ID = 0
        startPoint.X = end_x_1
        startPoint.Y = end_y_1

        endPoint.ID = 1
        endPoint.X = end_x_2
        endPoint.Y = end_y_2

        linePointsArray.add(startPoint)
        linePointsArray.add(endPoint)

        newLineFeature = ArcgisPolyLine(linePointsArray)

        # Need to create an extension for both ends of the line and add them
        # to the array.

        #newLineFeature = createdExtensionLinesCursor.newRow()

        #newLineFeature.SHAPE = linePointsArray

        lineDirectionOutput = "0"

        if lineDirectionAngle_1 > 0:
            lineDirectionOutput = lineDirectionAngle_1
        elif lineDirectionAngle_2 > 0:
            lineDirectionOutput = lineDirectionAngle_2
        else:
            pass

        roadLinesToInsertList.append(
            [newLineFeature, roadNameToUse, lineDirectionOutput, countyNumber])

        #createdExtensionLinesCursor.insertRow([newLineFeature, roadNameToUse, lineDirectionOutput])

        if "newLineFeature" in locals():
            del newLineFeature
        else:
            pass

    # Consider building this as a separate list and then just looping
    # through the list to put it into the cursor instead
    # of doing logic and inserting into the cursor at the same place.

    #start editing session
    #newEditingSession = daEditor(sqlGdbLocation)
    #newEditingSession.startEditing()
    #newEditingSession.startOperation()

    createdExtensionLinesCursor = daInsertCursor(
        createdExtensionLines,
        ["SHAPE@", "roadNameForSplit", "LabelAngle", "County_Number"])

    for roadLinesToInsertItem in roadLinesToInsertList:
        createdExtensionLinesCursor.insertRow(roadLinesToInsertItem)

    # End editing session
    #newEditingSession.stopOperation()
    #newEditingSession.stopEditing(True)

    if "createdExtensionLinesCursor" in locals():
        del createdExtensionLinesCursor
    else:
        pass

    # Remove the previous countyRoadNameRosette so that it can be recreated.
    if Exists(rosetteTextName):
        Delete_management(rosetteTextName)
    else:
        pass

    CreateFeatureclass_management(sqlGdbLocation, rosetteTextName, "POINT", "",
                                  "", "", spatialReferenceProjection)

    AddField_management(countyRoadNameRosette, "roadNameForSplit", "TEXT", "",
                        "", "55")

    AddField_management(countyRoadNameRosette, "LabelAngle", "DOUBLE", "", "",
                        "")  # Change to double.

    AddField_management(countyRoadNameRosette, "County_Number", "DOUBLE", "",
                        "", "")

    AddField_management(countyRoadNameRosette, "COUNTY_NAME", "TEXT", "", "",
                        "55")

    # Now then, need to check for the existence
    # of and delete the point intersection layer
    # if it exists.

    # Then, recreate it and the proper fields.

    inMemoryCountyBorderExtension = "aCountyBorderExtensionBuffer"
    inMemoryExtensionLines = "aLoadedExtensionLines"

    try:
        Delete_management(inMemoryCountyBorderExtension)
    except:
        pass

    try:
        Delete_management(inMemoryExtensionLines)
    except:
        pass

    # Temporary layer, use CopyFeatures_management to persist to disk.
    MakeFeatureLayer_management(
        countyBorderFeature,
        inMemoryCountyBorderExtension)  # County Border extension feature

    # Temporary layer, use CopyFeatures_management to persist to disk.
    MakeFeatureLayer_management(
        createdExtensionLines,
        inMemoryExtensionLines)  # Line extension feature

    borderFeatureList = getBorderFeatureList(quarterOrHalf)

    borderFeatureList = sorted(borderFeatureList,
                               key=lambda feature: feature[3])

    for borderFeature in borderFeatureList:
        borderFeatureName = borderFeature[2]
        borderFeatureNumber = borderFeature[3]
        print "borderFeatureName: " + str(
            borderFeatureName) + " & borderFeatureNumber: " + str(
                int(borderFeatureNumber))

        countyBorderWhereClause = ' "COUNTY_NUMBER" = ' + str(
            int(borderFeatureNumber)) + ' '

        SelectLayerByAttribute_management(inMemoryCountyBorderExtension,
                                          "NEW_SELECTION",
                                          countyBorderWhereClause)

        countyBorderSelectionCount = GetCount_management(
            inMemoryCountyBorderExtension)

        print "County Borders Selected: " + str(countyBorderSelectionCount)

        # Had to single-quote the borderFeatureNumber because it is stored as a string in the table.
        # Unsingle quoted because it was changed to a float.
        extensionLinesWhereClause = ' "COUNTY_NUMBER" = ' + str(
            int(borderFeatureNumber)) + ' '

        SelectLayerByAttribute_management(inMemoryExtensionLines,
                                          "NEW_SELECTION",
                                          extensionLinesWhereClause)

        extensionLineSelectionCount = GetCount_management(
            inMemoryExtensionLines)

        print "Extension Lines Selected: " + str(extensionLineSelectionCount)

        if Exists(tempRosetteTextName):
            Delete_management(tempRosetteTextName)
        else:
            pass

        if Exists(tempRosetteSPTextName):
            Delete_management(tempRosetteSPTextName)
        else:
            pass

        Intersect_analysis(
            [inMemoryCountyBorderExtension, inMemoryExtensionLines],
            tempRoadNameRosette, "ALL", "", "POINT")

        # Intersect to an output temp layer.

        # Next, need to loop through all of the counties.

        # Get the county number and use it to select
        # a county extension buffer in the county
        # extension buffers layer.

        # Then, use the county number to select
        # all of the lines for that county
        # in the extension lines layer.

        # Then, export those to a temp layer in the fgdb.

        # Change multipoint to singlepoint.

        # Was working until I moved from gisprod to sdedev for the data source.
        # not sure why. Check to make sure projections match.
        # ^ Fixed.

        try:

            # Run the tool to create a new fc with only singlepart features
            MultipartToSinglepart_management(tempRoadNameRosette,
                                             tempRoadNameRosetteSP)

            # Check if there is a different number of features in the output
            #   than there was in the input
            inCount = int(
                GetCount_management(tempRoadNameRosette).getOutput(0))
            outCount = int(
                GetCount_management(tempRoadNameRosetteSP).getOutput(0))

            if inCount != outCount:
                print "Found " + str(outCount -
                                     inCount) + " multipart features."
                #print "inCount, including multipart = " + str(inCount)
                #print "outCount, singlepart only = " + str(outCount)

            else:
                print "No multipart features were found"

        except ExecuteError:
            print GetMessages()
        except Exception as e:
            print e

        print "Appending the temp point layer to the county point intersection layer."

        Append_management([tempRoadNameRosetteSP], countyRoadNameRosette,
                          "NO_TEST")

        # K, worked correctly. Just need to change LabelAngle to a float and it might be what
        # I want.

        print "Done adding points to the countyRoadNameRosette feature class."
Beispiel #13
0
def FIMS_GIS():
    #arcpy.MakeFeatureLayer_management(CPMSlyr, 'CPMS', ProjectSelect)

    MakeFeatureLayer_management(CPMSlyr, 'CPMS')
    MakeFeatureLayer_management(CountyLyr, 'County')
    MakeFeatureLayer_management(HPMSlyr, 'HPMS')
    MakeFeatureLayer_management(MPOLyr, 'MPO')
    MakeFeatureLayer_management(CONGDistlyr, 'CONG')
    MakeFeatureLayer_management(ws + "/Polygons", 'Polygons')
    MakeTableView_management(deltbl, 'DeleteView')
    MakeTableView_management(newtbl, 'InsertView')
    #make the polygon analysis layer for Districts, Counties, and MPOs
    #arcpy.Union_analysis("CONG #;MPO #;County #",ws+"/Polygons","ALL","1 feet","GAPS")
    # 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: "CPMS", "CPMS.CPMS_STAGING_TMP"
    MakeTableView_management(FMIS_PROJ, "CPMS_STAGING_TMP")
    AddJoin_management("CPMS", "PROJECT_ID", "InsertView", "PROJECT_NUMBER",
                       "KEEP_COMMON")

    Output_Event_Table_Properties = 'RID LINE CNTY_BEG CNTY_END'

    outtblH = ws + "/FIMS_EventTableLines"

    if Exists(outtblH):
        Delete_management(outtblH)

    print "locating CPMS to HPMS route"
    LocateFeaturesAlongRoutes_lr('CPMS', 'HPMS', "Route_ID", "0 miles",
                                 outtblH, Output_Event_Table_Properties,
                                 "FIRST", "DISTANCE", "NO_ZERO", "FIELDS",
                                 "M_DIRECTON")
    #the 30 foot tolerance we allowed here also created a bunch of 30' segments at project intersections.  Those should be handled.
    #...Or the locate tolerance changed to 0
    #cleansel = "RID <> CRND_RTE" #is thisnot the right way to handle this, because it will delete the short segments crossing the GIS county boundary?  not really
    #selection statement deleted non-state highway system might be better
    #MakeTableView_management(outtblH, "cleanup", cleansel)
    #DeleteRows_management("cleanup")

    MakeRouteEventLayer_lr("HPMS", "Route_ID", ws + "/FIMS_EventTableLines",
                           "rid LINE CNTY_BEG CNTY_END",
                           "FIMS_EventTableLineLyr", "#", "ERROR_FIELD",
                           "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT",
                           "POINT")

    print "Intersection routes to areas"
    Intersect_analysis("FIMS_EventTableLineLyr #;HPMS #;Polygons #",
                       ws + "/FMIS_Data", "ALL", "#", "LINE")

    if Exists(ws + "/HPMS_DataD"):
        Delete_management(ws + "/HPMS_DataD")

    Dissolve_management(
        ws + "/FMIS_Data", ws + "/HPMS_DataD",
        "PROJECT_ID;F_SYSTEM_V;NHS_VN;DISTRICT_1;COUNTY_NUMBER;ID_1", "#",
        "MULTI_PART", "UNSPLIT_LINES")
    # 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
    print "locating processed data to HPMS mileage"

    if Exists(ws + "/FIMS_EventTable"):
        Delete_management(ws + "/FIMS_EventTable")

    LocateFeaturesAlongRoutes_lr(ws + "/HPMS_DataD", "HPMS", "Route_ID",
                                 "0 miles", ws + "/FIMS_EventTable",
                                 "RID LINE CNTY_BEG CNTY_END", "FIRST",
                                 "DISTANCE", "NO_ZERO", "FIELDS", "M_DIRECTON")
    #MaleTableView(ws+"/FIMS_EventTable", )

    Append_management(
        ws + "/FIMS_EventTable", FMIS_LOAD, "NO_TEST",
        """ROUTE_ID "ROUTE_ID" true true false 14 Text 0 0 ,First,#,FIMS_EventTable,RID,-1,-1;BEG_CNTY_MP "BEG_CNTY_MP" true true false 8 Double 10 38 ,First,#,FIMS_EventTable,CNTY_BEG,-1,-1;END_CNTY_MP "END_CNTY_MP" true true false 8 Double 10 38 ,First,#,FIMS_EventTable,CNTY_END,-1,-1;CONGRESSIONAL_DISTRICT "CONGRESSIONAL_DISTRICT" true true false 50 Text 0 0 ,First,#,FIMS_EventTable,DISTRICT_1,-1,-1;URBAN_ID "URBAN_ID" true true false 10 Text 0 0 ,First,#,FIMS_EventTable,ID_1,-1,-1;FUN_CLASS "FUN_CLASS" true true false 3 Text 0 0 ,First,#,FIMS_EventTable,F_SYSTEM_V,-1,-1;SYSTEM_CODE "SYSTEM_CODE" true true false 10 Text 0 0 ,First,#,FIMS_EventTable,NHS_VN,-1,-1;PROJECT_NUMBER "PROJECT_NUMBER" true true false 15 Text 0 0 ,First,#,FIMS_EventTable,PROJECT_ID,-1,-1;COUNTY "COUNTY" true true false 3 Text 0 0 ,First,#,FIMS_EventTable,COUNTY_NUMBER,-1,-1""",
        "#")

    print "Rows appended to CPMS Load Table CPMS_HPMS_FMIS_DATA"
Beispiel #14
0
def OffsetDirectionMatrix2(offsetOptions):
    """Update the accidentDataWithOffsetOutput geometry with data from geocodedFeatures.
    
    Keyword arguments to be included in the options class:
    gdbLocation -- The gdb where the outputWithOffsetLocations feature class resides.
    accidentDataAtIntersections -- A point feature class containing geocoded accident information.
    accidentDataWithOffsetOutput -- A point feature class with the same structure as the 
        geocodedFeatuers AND an "isOffset" row of type "TEXT" with length of at least 5.
    whereClauseInUse -- Whether or not the script will use a where clause. Boolean value.
    roadsFeaturesLocation -- The path to the local roads centerline feature class.
    aliasTable -- The path to the roads alias table for the roads centerline feature class.
    maxDegreesDifference -- The number of degrees that a potentially matching accident
        offset location can be from the direction specified. If this is set to -1, the check
        will be skipped and no matching accident offset locations will be rejected, even if
        they are in the opposite direction from where the accident record says they should
        be. I.e. the accident could be offset to the North when the accident record says that
        it should be South of the intersection when this check is skipped.
    XYFieldList -- The list of fields to use from the copy of the geocoded accidents feature
        class after that copy has had POINT_X and POINT_Y fields added and calculated.
    """
    
    ###########################################################################
    ## Function overview:
    ## For each row in the feature class of accidents that have been geolocated
    ## to an intersection:
    ###########################################################################
    # Make sure that the Status for the point is not 'U' -- Unlocated.
    # Might take care of test for 'U' points before getting to this
    # step in the process, but if not, be sure to test for it here.
    # Create/calculate intersection X & Y field named POINT_X and POINT_Y.
    # Then, calculate those fields.
    # Then, create a buffer.
    # Then, select the On_Road in the roads layer.
    # Then, intersect the buffer with the roads layer to create an offset
    # points layer.
    # Then, split the offset points from potential multipart points to
    # singlepart points.
    ###########################################################################
    # Then, use the "SHAPE@XY" token to access the X & Y of the individual
    # offset points and compare them to the X & Y values in the POINT_X and
    # POINT_Y fields, which hold the values for the related roads' intersection
    # that the accidents were geolocated to.
    # Then, test the intersected points to find the best one for the given
    # direction.
    ###########################################################################
    # Then, append the information for that point into a list.
    # Then, delete the buffer and intersection layer.
    # Repeat for each other row...
    ###########################################################################
    # When all the rows are finished,
    # Append the attribute information for the
    # related accident into each offset point's row.
    # Lastly, write the data for all the offset point rows
    # into the output layer.
    ###########################################################################
    # Maximum angle difference code confirmed to be working. -- 2015-03-18
    # 771/771 manually checked look good (for the information given) using
    # UpdateKdotNameInCenterline(), Where Clause for selection, and
    # Maximum Angle Difference.
    # Locates 771/862 non-'U' points without the modified versions of 
    # ON_ROAD_NAME/AT_ROAD/AT_ROAD_DIRECTION/AT_ROAD_DIST_FEET labeled fields
    # and 803/862 with them. 
    ###########################################################################
    
    AddMessage("The value of the useKDOTFields option is: " + str(offsetOptions.useKDOTFields))
    
    roadsToIntersect = offsetOptions.roadsFeaturesLocation
    roadsAliasTable = offsetOptions.aliasTable
    geocodedFeatures = offsetOptions.accidentDataAtIntersections
    outputWithOffsetLocations = offsetOptions.accidentDataWithOffsetOutput
    whereClauseFlag = offsetOptions.whereClauseInUse
    maximumDegreesDifference = offsetOptions.maxDegreesDifference
    KDOTFieldUse = offsetOptions.useKDOTFields
    
    AddMessage("The value for KDOTFieldUse is: " + str(KDOTFieldUse))
    
    if str(KDOTFieldUse).lower() == 'false':
        featuresWithXYFieldList = offsetOptions.NonKDOTXYFieldList
        AddMessage("Using nonKDOTXYFieldList.")
    else:
        featuresWithXYFieldList = offsetOptions.KDOTXYFieldList
    
    geodatabaseLocation = getGDBLocationFromFC(outputWithOffsetLocations)
    
    env.workspace = geodatabaseLocation
    env.overwriteOutput = True
    geocodedWhereClause = "STATUS <> 'U'"
    featuresWithXY = 'geocodedWithXY'
    geocodedLocXY = r'in_memory\geocodedFeatures_Loc_XY' # Changed this to an in_memory location also.
    
    # Scratch data locations
    intermediateAccidentBuffer = r'in_memory\intermediateAccidentBuffer'
    intermediateAccidentIntersect = r'in_memory\intermediateAccidentIntersect'
    intermediateAccidentIntersectSinglePart = r'in_memory\intermediateAccidentIntersectSinglePart'
    # Added 2016-09-06 after the Wichita Area points started processing. Slowly.
    intermediateRoadsToIntersect = r'in_memory\roadsToIntersect'
    intermediateRoadsAliasTable = r'in_memory\roadsAliasTable'
    
    descSpatialReference = Describe(geocodedFeatures).spatialReference
    
    # Make a feature layer of geocodedFeatures using a where clause to restrict to those points
    # which have been located to an intersection, then add XY to it.
    MakeFeatureLayer_management(geocodedFeatures, featuresWithXY, geocodedWhereClause)
    CopyFeatures_management(featuresWithXY, geocodedLocXY)
    AddXY_management(geocodedLocXY)
    
    roadsAsFeatureLayer = 'ConflatedRoadsFeatureLayer'
    
    # Roads copied to memory.
    CopyFeatures_management(roadsToIntersect, intermediateRoadsToIntersect)
    
    MakeFeatureLayer_management(intermediateRoadsToIntersect, roadsAsFeatureLayer)
    
    # Use Point_X & Point_Y for the geolocated intersection location.
    # Use shape tokens for the x & y of the points which
    # result from intersecting the buffer & road geometries.    
    
    geocodedAccidentsList = list()
    singlePartOffsetAccidentsList = list()
    
    print "The path of the geocodedFeatures used is: " + geocodedFeatures
    
    #AddMessage("The field names used in the search cursor are:")
    #for fieldListItem in featuresWithXYFieldList:
    #    AddMessage(fieldListItem)
    
    accidentsCursor = SearchCursor(geocodedLocXY, featuresWithXYFieldList)
    
    for accidentRow in accidentsCursor:
        geocodedAccidentsList.append(accidentRow)
    
    try:
        del accidentsCursor
    except:
        pass
    
    print 'whereClauseFlag is: ' + str(whereClauseFlag)
    print 'Starting the offset process...'
    
    accCounter = -1
    
    env.outputCoordinateSystem = descSpatialReference
    
    if whereClauseFlag == True:
        
        # Don't need to create a relate or a join.
        # Just need to do a select on the would-be joined/related table
        # to get the SEGIDs, then use those to do a select
        # for the GCIDs the conflation roads.
        
        # Try using table to table here instead of copy features.
        # For some reason, arcpy doesn't like this table when it's in the
        # ar63 FGDBs.
        TableToTable_conversion(roadsAliasTable, 'in_memory', 'roadsAliasTable') # == intermediateRoadsAliasTable
        #CopyFeatures_management(roadsAliasTable, intermediateRoadsAliasTable)
        
        roadsAliasTableView = MakeTableView_management(intermediateRoadsAliasTable, 'roadsAliasTableView')
        
        for geocodedAccident in geocodedAccidentsList:
            accCounter += 1
            print 'Working on geocodedAccident #' + str(accCounter)
            # Create a point here with the x & y from the geocodedAccident,
            # add the coordinate system, OBJECTID, and AccidentID
            # from the geocodedAccident layer.
            # Then, create a buffer with it.
            
            #if geocodedAccident[2] is not None and geocodedAccident[3] is not None:
            tempPoint = Point(geocodedAccident[2], geocodedAccident[3])
            #print "\t " + str(tempPoint.X) + ", " + str(tempPoint.Y)
            tempPointGeometry = PointGeometry(tempPoint, descSpatialReference)
            accidentDistanceOffset = geocodedAccident[7]
            accidentClusterTolerance = 1
            
            
            try:
                #####################
                # Offsetting while using a WhereClause follows:
                #####################
                if accidentDistanceOffset is not None: # In Python it's None, whereas in an ArcGIS table it's <null>
                    
                    accidentDistanceOffset = int(accidentDistanceOffset)
                    
                    if accidentDistanceOffset != 0:
                        
                        Buffer_analysis(tempPointGeometry, intermediateAccidentBuffer, accidentDistanceOffset)
                        
                        firstRoadName = str(geocodedAccident[5])
                        if firstRoadName is not None:
                            firstRoadName = firstRoadName.upper()
                        else:
                            firstRoadName = 'NotAValidRoad'
                        
                        secondRoadName = str(geocodedAccident[8])
                        if secondRoadName is not None:
                            secondRoadName = secondRoadName.upper()
                        else:
                            secondRoadName = 'NotAValidRoad'
                        
                        thirdRoadName = ParseMatchAddr(geocodedAccident[9])
                        if thirdRoadName is not None:
                            thirdRoadName = thirdRoadName.upper()
                        else:
                            thirdRoadName = 'NotAValidRoad'
                        
                        roadNamesList = [firstRoadName, secondRoadName, thirdRoadName]
                        
                        aliasIDsList = getAliasIDs(roadNamesList, roadsAliasTableView)
                        
                        aliasIDsLength = len(aliasIDsList)
                        
                        if aliasIDsLength != 0:
                            aliasIDsString = """("""
                            for x in xrange(aliasIDsLength):
                                if (x != (aliasIDsLength - 1)):
                                    aliasIDsString += """'""" + aliasIDsList[x] + """',"""
                                else:
                                    aliasIDsString += """'""" + aliasIDsList[x] + """')"""
                            
                            streetWhereClause = (""" "RD" = '""" + firstRoadName  + """'""" + """ OR """ +
                                                """ "LABEL" = '""" + firstRoadName + """'""" + """ OR """ +
                                                """ "RD" = '""" + secondRoadName  + """'""" + """ OR """ +
                                                """ "LABEL" = '""" + secondRoadName + """'""" + """ OR """ +
                                                """ "RD" = '""" + thirdRoadName  + """'""" + """ OR """ +
                                                """ "LABEL" = '""" + thirdRoadName + """'""" +
                                                """ OR GCID IN """ + aliasIDsString)
                        else:
                            #Without the aliasIDs.
                            streetWhereClause = (""" "RD" = '""" + firstRoadName  + """'""" + """ OR """ +
                                                """ "LABEL" = '""" + firstRoadName + """'""" + """ OR """ +
                                                """ "RD" = '""" + secondRoadName  + """'""" + """ OR """ +
                                                """ "LABEL" = '""" + secondRoadName + """'""" + """ OR """ +
                                                """ "RD" = '""" + thirdRoadName  + """'""" + """ OR """ +
                                                """ "LABEL" = '""" + thirdRoadName + """'""")
                        
                        
                        SelectLayerByAttribute_management(roadsAsFeatureLayer, "NEW_SELECTION", streetWhereClause)
                        
                        selectionCount = str(int(GetCount_management(roadsAsFeatureLayer).getOutput(0)))
                        
                        if int(selectionCount) != 0:
                            featuresToIntersect = [roadsAsFeatureLayer, intermediateAccidentBuffer]
                            Intersect_analysis(featuresToIntersect, intermediateAccidentIntersect, "ALL", "", "POINT")
                            
                            if  int(str(GetCount_management(intermediateAccidentIntersect))) > 0:
                                MultipartToSinglepart_management(intermediateAccidentIntersect, intermediateAccidentIntersectSinglePart)
                                
                                singlePartsCursor = SearchCursor(intermediateAccidentIntersectSinglePart, ['SHAPE@XY'])
                                for singlePart in singlePartsCursor:
                                    singlePartListItem = [singlePart[0], geocodedAccident[2], geocodedAccident[3], geocodedAccident[4],
                                                               geocodedAccident[6], geocodedAccident[0]]
                                    singlePartOffsetAccidentsList.append(singlePartListItem)
                                
                                try:
                                    del singlePartsCursor
                                except:
                                    pass
                            else:
                                pass
                            try:
                                del intermediateAccidentIntersect
                            except:
                                pass
                        else:
                            pass
                            #print 'Zero road segments selected. Will not attempt to offset.'
                    else:
                        pass
                        #print 'AT_ROAD_DIST_FEET is 0. Will not attempt to offset.
                else:
                    pass
                    #print 'AT_ROAD_DIST_FEET is null. Will not attempt to offset.'
                
            except:
                # Need to log the warnings with details so that I know what's wrong with them.
                print "WARNING:"
                print "An error occurred which prevented the accident point with Acc_Key: " + str(geocodedAccident[4])
                print "from being buffered and/or offset properly."
                errorItem = sys.exc_info()[1]
                errorStatement = str(errorItem.args[0])
                print errorStatement
                
                try:
                    del errorItem
                except:
                    pass
    
    
    elif whereClauseFlag == False:
        for geocodedAccident in geocodedAccidentsList:
            
            # Create a point here with the x & y from the geocodedAccident,
            # add the coordinate system, OBJECTID, and AccidentID
            # from the geocodedAccident layer.
            # Then, create a buffer with it.
            
            #if geocodedAccident[2] is not None and geocodedAccident[3] is not None:
            tempPoint = Point(geocodedAccident[2], geocodedAccident[3])
            #print "\t " + str(tempPoint.X) + ", " + str(tempPoint.Y)
            tempPointGeometry = PointGeometry(tempPoint, descSpatialReference)
            accidentDistanceOffset = geocodedAccident[7]
            ##accidentClusterTolerance = 2
            
            try:
                #####################
                # Offsetting while not using a WhereClause follows:
                #####################
                
                if accidentDistanceOffset is not None:
                    if int(accidentDistanceOffset) != 0:
                        accidentDistanceOffset = int(accidentDistanceOffset)
                        
                        Buffer_analysis(tempPointGeometry, intermediateAccidentBuffer, accidentDistanceOffset)
                        
                        featuresToIntersect = [roadsAsFeatureLayer, intermediateAccidentBuffer]
                        Intersect_analysis(featuresToIntersect, intermediateAccidentIntersect, "ALL", "", "POINT")
                        if  int(str(GetCount_management(intermediateAccidentIntersect))) > 0:
                            MultipartToSinglepart_management(intermediateAccidentIntersect, intermediateAccidentIntersectSinglePart)
                            
                            singlePartsCursor = SearchCursor(intermediateAccidentIntersectSinglePart, ['SHAPE@XY'])
                            for singlePart in singlePartsCursor:
                                singlePartListItem = [singlePart[0], geocodedAccident[2], geocodedAccident[3], geocodedAccident[4],
                                                           geocodedAccident[6], geocodedAccident[0]]
                                singlePartOffsetAccidentsList.append(singlePartListItem)
                            
                            try:
                                del singlePartsCursor
                            except:
                                pass
                            try:
                                del intermediateAccidentIntersect
                            except:
                                pass
                        else:
                            pass
                    else:
                        pass
                        # Need to change this to being offset to the intersection, i.e. no movement, but
                        # considered to be correctly offset all the same.
                        #print 'AT_ROAD_DIST_FEET is 0. Will not attempt to offset.' 
                else:
                    pass
                    #print 'AT_ROAD_DIST_FEET is null. Will not attempt to offset.'
            except:
                print "WARNING:"
                print "An error occurred which prevented the accident point with Acc_Key: " + str(geocodedAccident[4])
                print "from being buffered and/or offset properly."
                errorItem = sys.exc_info()[1]
                errorStatement = str(errorItem.args[0])
                print errorStatement
                
                try:
                    del errorItem
                except:
                    pass
    
    
    else:
        print 'Please set the whereClauseFlag to either (boolean) True or False.'
        #pass
    
    offsetDictionaryByAccidentKey = dict()
    listContainer = list()
    
    # Group the rows by accident_key for further analysis,
    # and add them to the dictionary/list/list data structure.
    
    for singlePartOffsetItem in singlePartOffsetAccidentsList:
        if singlePartOffsetItem[3] in offsetDictionaryByAccidentKey.keys():
            listContainer = offsetDictionaryByAccidentKey[singlePartOffsetItem[3]]
            listContainer.append(singlePartOffsetItem)
            offsetDictionaryByAccidentKey[singlePartOffsetItem[3]] = listContainer
        else:
            listContainer = list()
            listContainer.append(singlePartOffsetItem)
            offsetDictionaryByAccidentKey[singlePartOffsetItem[3]] = listContainer
    
    updateListValues = list()
    
    for accidentKey in offsetDictionaryByAccidentKey.keys():
        # accidentKey will be a unique accident key from the table
        listContainer = offsetDictionaryByAccidentKey[accidentKey]
        updateList = [-1, -1, -1, "False"]
        try:
            # Get the AT_ROAD_KDOT_DIRECTION/AT_ROAD_DIRECTION from the first (0th) entry.
            directionToTest = listContainer[0][4] 
            if directionToTest is not None:
                directionToTest = str(directionToTest).upper()
                updateList = findTheMostInterestingRow(listContainer, directionToTest, maximumDegreesDifference)
                if updateList[0] != -1:
                    updateListValues.append(updateList)
                else:
                    # -1 is not a valid Acc_Key. Slight optimization for the next for loop that uses this list so that
                    # it doesn't have to be re-checked each time through the list for each accident in the table.
                    pass
            else:
                print 'Direction to test is null.'
        except:
            pass
    
    accidentUpdateCursorFields = ['ACCIDENT_KEY', 'Shape@XY', 'isOffset']
    
    accidentUpdateCursor = UpdateCursor(outputWithOffsetLocations, accidentUpdateCursorFields)
    for cursorItem in accidentUpdateCursor:
        for updateListItem in updateListValues:
            if cursorItem[0] == updateListItem[0]:
                if str(cursorItem[2]).upper() == 'TRUE':    # Don't make any changes if true.
                    AddMessage('The accident point with Acc_Key: ' + str(cursorItem[0]) + ' is already offset.')
                else:                                       # Otherwise, offset the point.
                    editableCursorItem = list(cursorItem)
                    #AddMessage('Found a matching cursorItem with an Accident_Key of ' + str(cursorItem[0]) + ".")
                    editableCursorItem[1] = (updateListItem[1], updateListItem[2])
                    editableCursorItem[2] = updateListItem[3]
                    #AddMessage(str(editableCursorItem))
                    accidentUpdateCursor.updateRow(editableCursorItem)
                    
            else:
                pass
Beispiel #15
0
def calibrationCCL():

    print "deriving CCL LRS starting points and calibrations"
    CCLEnd = "!CCL.DBO.CITY_CONNECTING_LINK_STATE.MAX_END_STATE_LOGMILE!- !CCL.DBO.CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!"
    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"
    statecalpoints = stateroutelyr + "_Point"
    Intersect_analysis(
        "CCL.DBO.CITY_CONNECTING_LINK_STATE_D #;'Database Connections/SQL61_GIS_CANSYS_RO.sde/GIS_CANSYS.DBO.SMLRS_Point' #",
        "Database Connections/SQL61_GEOADMIN_CCL.sde/CALIBRATION_POINTS_CCL",
        "ALL", "#", "POINT")
    querystr = "Substring( CCL_LRS,4, 12)<> LRS_ROUTE"
    SelectLayerByAttribute_management("CCL.DBO.CALIBRATION_POINTS_CCL",
                                      "NEW_SELECTION", querystr)
    DeleteRows_management("CCL.DBO.CALIBRATION_POINTS_CCL")

    DeleteIdentical_management("CCL.DBO.CALIBRATION_POINTS_CCL",
                               "LRS_KEY;POINT_X;POINT_Y;POINT_M", "#", "0")
    AddField_management("CCL.DBO.CITY_CONNECTING_LINK_STATE", "CCL_BEGIN",
                        "DOUBLE", "#", "#", "#", "#", "NULLABLE",
                        "NON_REQUIRED", "#")
    AddField_management("CCL.DBO.CITY_CONNECTING_LINK_STATE", "CCL_BEGIN",
                        "DOUBLE", "#", "#", "#", "#", "NULLABLE",
                        "NON_REQUIRED", "#")
    AddJoin_management("CCL.DBO.CITY_CONNECTING_LINK_STATE", "CCL_LRS",
                       "CCL.DBO.CITY_CONNECTING_LINK_STATE_D", "CCL_LRS",
                       "KEEP_ALL")
    CalculateField_management(
        "CCL.DBO.CITY_CONNECTING_LINK_STATE",
        "CCL.DBO.CITY_CONNECTING_LINK_STATE.CCL_BEGIN",
        "!CCL.DBO.CITY_CONNECTING_LINK_STATE.MIN_BEG_STATE_LOGMILE!- !CCL.DBO.CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!",
        "PYTHON", "#")
    CalculateField_management(
        "CCL.DBO.CITY_CONNECTING_LINK_STATE",
        "CCL.DBO.CITY_CONNECTING_LINK_STATE.CCL_END",
        "!CCL.DBO.CITY_CONNECTING_LINK_STATE.MAX_END_STATE_LOGMILE!- !CCL.DBO.CITY_CONNECTING_LINK_STATE_D.MIN_BEG_STATE_LOGMILE!",
        "PYTHON", "#")
    inprops = str(ReferenceRouteKey + " POINT MEASURE")
    AddField_management(connection1 + "CALIBRATION_POINTS_CCL", "CCL_MEASURE",
                        "DOUBLE", 12, 3)
    CalculateField_management("CCL.DBO.CALIBRATION_POINTS_CCL", "CCL_MEASURE",
                              "!POINT_M!- !MIN_BEG_STATE_LOGMILE!", "PYTHON",
                              "#")
    CreateRoutes_lr(LineFeatureClass, NewRouteKey,
                    connection1 + NewRoute + "base", "TWO_FIELDS", NewBeg,
                    NewEnd, "UPPER_LEFT", "1", "0", "IGNORE", "INDEX")
    CalibrateRoutes_lr(
        "Database Connections/SQL61_GEOADMIN_CCL.sde/CCL.DBO.CCL_LRS_ROUTEbase",
        "CCL_LRS",
        "Database Connections/SQL61_GEOADMIN_CCL.sde/CCL.DBO.CALIBRATION_POINTS_CCL",
        "CCL_LRS", "CCL_MEASURE",
        "Database Connections/SQL61_GEOADMIN_CCL.sde/CCL.DBO.CCL_LRS_ROUTE",
        "DISTANCE", "1 Feet", "BETWEEN", "NO_BEFORE", "NO_AFTER", "IGNORE",
        "KEEP", "INDEX")
    AddField_management(connection1 + NewRoute, "NETWORKDATE", "DATE")
    CalculateField_management(connection1 + NewRoute, "NETWORKDATE",
                              "datetime.datetime.now( )", "PYTHON_9.3", "#")
    MakeFeatureLayer_management(connection1 + "CCL_LRS_ROUTE", NewRoute)
def createCountyLinesForEachCounty():

    env.workspace = sqlGdbLocation

    inputCountyLines = sharedCountyLines
    inputCountyPolygons = sharedCounties
    dissolvedCountyLines = countyLinesDissolved
    loadedCounties = 'loadedCounties'
    tempCountyLines = r'in_memory\tempCountyLines'
    outputCountyLines = countyLinesIntersectedNoPath
    bufferCursorFields = ["OBJECTID"]

    # Dissolve all of those county lines into one set of lines
    # then, need to create 105 features that are are intersected
    # with the polygons from said line dissolve.

    Dissolve_management(inputCountyLines, dissolvedCountyLines)
    Buffer_analysis(inputCountyPolygons, countiesBuffered, "15500 Feet")

    bufferedCountyPolygonList = list()
    outputFeatureList = list()

    # 1st SearchCursor
    newCursor = daSearchCursor(countiesBuffered, bufferCursorFields)
    for newRow in newCursor:
        bufferedCountyPolygonList.append(list(newRow))

    if 'newCursor' in locals():
        del newCursor
    else:
        pass

    MakeFeatureLayer_management(countiesBuffered, loadedCounties)

    loadedCountiesFields = ListFields(loadedCounties)

    for loadedCountiesField in loadedCountiesFields:
        print "A loadedCountiesField was found: " + str(
            loadedCountiesField.name)

    for listedRow in bufferedCountyPolygonList:
        selectNumber = listedRow[0]

        whereClause = """ "OBJECTID" = """ + str(selectNumber)
        print "The whereClause = " + str(whereClause)
        SelectLayerByAttribute_management(loadedCounties, "NEW_SELECTION",
                                          whereClause)

        Intersect_analysis([dissolvedCountyLines, loadedCounties],
                           tempCountyLines, "ALL")

        # 2nd SearchCursor
        newCursor = daSearchCursor(tempCountyLines,
                                   ["SHAPE@", "County_Number", "County_Name"])
        for newRow in newCursor:
            outputFeatureList.append(newRow)

        if 'newCursor' in locals():
            del newCursor
        else:
            pass

    try:
        Delete_management(countyLinesIntersectedWithUser)
    except:
        pass

    CreateFeatureclass_management(sqlGdbLocation, outputCountyLines,
                                  "POLYLINE", "", "", "",
                                  spatialReferenceProjection)

    AddField_management(outputCountyLines, "County_Number", "DOUBLE", "", "",
                        "")

    AddField_management(outputCountyLines, "County_Name", "TEXT", "", "", "55")

    print "First Intersected County Row: " + str(outputFeatureList[0])

    countyLinesIntersectFields = ["SHAPE@", "County_Number", "County_Name"]

    newCursor = daInsertCursor(countyLinesIntersectedPath,
                               countyLinesIntersectFields)
    counter = 1
    for outputFeature in outputFeatureList:
        rowToInsert = ([outputFeature])

        insertedOID = newCursor.insertRow(outputFeature)

        counter += 1

        print "Inserted Row with Object ID of " + str(insertedOID)

    if 'newCursor' in locals():
        del newCursor
    else:
        pass
Beispiel #17
0
def CRB():
    print "querying the shared.NON_STATE_SYSTEM to obtain only urban classified primary C routes with mileage that should be counted and for resolution segments."
    MakeFeatureLayer_management(
        NonState, "NonStateCP",
        "((LRS_KEY LIKE '%C%' OR LRS_ROUTE_PREFIX = 'C') AND (MILEAGE_COUNTED = -1)) OR (LRS_DIR_OF_TRAVEL = 'P' and SURFACE = 'Propose')"
    )

    print "querying the shared.NON_STATE_SYSTEM to obtain only urban classified NonPrimary C routes with mileage that should be counted and for resolution segments."
    MakeFeatureLayer_management(
        NonState, "NonStateCNP",
        "(LRS_KEY LIKE '%C%' OR LRS_ROUTE_PREFIX = 'C') AND (MILEAGE_COUNTED = 0) AND (LRS_DIR_OF_TRAVEL = 'S') and (COUNTY_NUMBER <> 0)"
    )

    print "shared.Non_State_System has unique IDS that we desire to keep as persistent IDs for comparison with GeoMedia, so we are spatially intersecting the state boundary to keep them as is."
    Buffer_analysis(StateBnd, "State_Boundary_1Mile", "5280 Feet", "FULL",
                    "ROUND", "NONE", "", "PLANAR")
    MakeFeatureLayer_management("State_Boundary_1Mile", "StateBnd")
    Intersect_analysis("NonStateCP #;StateBnd #",
                       "Non_State_Classified_Primary", "ALL", "-1 Unknown",
                       "LINE")
    Intersect_analysis("NonStateCNP #;StateBnd #",
                       "Non_State_Classified_NonPrimary", "ALL", "-1 Unknown",
                       "LINE")

    NonStateCP_fx = r'Non_State_Classified_Primary'
    NonStateCNP_fx = r'Non_State_Classified_NonPrimary'

    MakeFeatureLayer_management(NonStateCP_fx, "Non_State_Classified_Primary")
    MakeFeatureLayer_management(NonStateCNP_fx,
                                "Non_State_Classified_NonPrimary")

    CP_ET = 'CP_NON_STATE_EVENTS'
    CNP_ET = 'CNP_NON_STATE_EVENTS'

    MakeFeatureLayer_management(NUSYS, "Nusys_Extract",
                                "NSEC_SUB_CLASS <> 'R'")

    print "creating primary C Non_State_Routes by the Shape Length"
    MakeFeatureLayer_management(
        "Non_State_Classified_Primary", "BackwardSegsCP",
        "LRS_BACKWARDS = -1 AND (MILEAGE_COUNTED = -1 OR (LRS_DIR_OF_TRAVEL = 'P' and SURFACE = 'Propose'))"
    )
    FlipLine_edit("BackwardSegsCP")
    Dissolve_management("Non_State_Classified_Primary", "CPRouteShapeLength",
                        "NQR_DESCRIPTION", "", "MULTI_PART", "DISSOLVE_LINES")
    AddField_management("CPRouteShapeLength", "BCM", "DOUBLE", "", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")
    CalculateField_management("CPRouteShapeLength", "BCM", "0", "VB", "")
    AddField_management("CPRouteShapeLength", "ECM", "DOUBLE", "", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")
    CalculateField_management("CPRouteShapeLength", "ECM",
                              "!Shape.length@miles!", "Python")

    CreateRoutes_lr("CPRouteShapeLength", "NQR_DESCRIPTION",
                    destdb + "\CP_ShapeLengthRoute", "TWO_FIELDS", "BCM",
                    "ECM", "UPPER_LEFT", "1", "0", "IGNORE", "INDEX")
    #Flip them back to the original direction
    FlipLine_edit(in_features="BackwardSegsCP")
    LocateFeaturesAlongRoutes_lr("Non_State_Classified_Primary",
                                 "CP_ShapeLengthRoute", "NQR_DESCRIPTION",
                                 "0 Feet", "CP_NON_STATE_EVENTS",
                                 "RID LINE FMEAS TMEAS", "FIRST", "DISTANCE",
                                 "ZERO", "FIELDS", "M_DIRECTON")
    AddField_management("CP_NON_STATE_EVENTS", "AdjBegin", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CP_NON_STATE_EVENTS", "AdjEnd", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CP_NON_STATE_EVENTS", "CHG_BEGLOG", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CP_NON_STATE_EVENTS", "CHG_ENDLOG", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CP_NON_STATE_EVENTS", "NEW_BEGLOG", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CP_NON_STATE_EVENTS", "NEW_ENDLOG", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CP_NON_STATE_EVENTS", "AdjLength", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CP_NON_STATE_EVENTS", "CHANGE", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")

    CalculateField_management("CP_NON_STATE_EVENTS",
                              "AdjBegin",
                              "round( [FMEAS] , 3 )",
                              "VB",
                              code_block="")
    CalculateField_management("CP_NON_STATE_EVENTS",
                              "AdjEnd",
                              "round( [TMEAS] , 3 )",
                              "VB",
                              code_block="")
    CalculateField_management("CP_NON_STATE_EVENTS",
                              "CHG_BEGLOG",
                              "[AdjBegin] - [LRS_BEG_CNTY_LOGMILE]",
                              "VB",
                              code_block="")
    CalculateField_management("CP_NON_STATE_EVENTS",
                              "CHG_ENDLOG",
                              "[AdjEnd] - [LRS_END_CNTY_LOGMILE]",
                              "VB",
                              code_block="")
    CalculateField_management("CP_NON_STATE_EVENTS",
                              "NEW_BEGLOG",
                              "[AdjBegin]",
                              "VB",
                              code_block="")
    CalculateField_management("CP_NON_STATE_EVENTS",
                              "NEW_ENDLOG",
                              "[AdjEnd]",
                              "VB",
                              code_block="")
    CalculateField_management("CP_NON_STATE_EVENTS",
                              "AdjLength",
                              "[AdjEnd] - [AdjBegin]",
                              "VB",
                              code_block="")
    CalculateField_management("CP_NON_STATE_EVENTS",
                              "CHANGE",
                              "abs([LENGTH] - [AdjLength])",
                              "VB",
                              code_block="")

    MakeRouteEventLayer_lr("CP_ShapeLengthRoute", "NQR_DESCRIPTION",
                           "CP_NON_STATE_EVENTS", "RID LINE FMEAS TMEAS",
                           "CP_LRS_Review_Events", "", "ERROR_FIELD",
                           "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT",
                           "POINT")
    print "CP-Rte Builder script completed successfully"

    print "creating NonPrimary C Non_State_Routes by the Shape Length"
    MakeFeatureLayer_management(
        "Non_State_Classified_NonPrimary", "BackwardSegsCNP",
        "LRS_BACKWARDS = -1 AND LRS_DIR_OF_TRAVEL = 'S' and COUNTY_NUMBER <> 0"
    )
    FlipLine_edit("BackwardSegsCNP")
    Dissolve_management("Non_State_Classified_NonPrimary",
                        "CNPRouteShapeLength", "LRS_KEY", "", "MULTI_PART",
                        "DISSOLVE_LINES")
    AddField_management("CNPRouteShapeLength", "BCM", "DOUBLE", "", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")
    CalculateField_management("CNPRouteShapeLength", "BCM", "0", "VB", "")
    AddField_management("CNPRouteShapeLength", "ECM", "DOUBLE", "", "", "", "",
                        "NULLABLE", "NON_REQUIRED", "")
    CalculateField_management("CNPRouteShapeLength", "ECM",
                              "!Shape.length@miles!", "Python")

    CreateRoutes_lr("CNPRouteShapeLength", "LRS_KEY",
                    destdb + "\CNP_ShapeLengthRoute", "TWO_FIELDS", "BCM",
                    "ECM", "UPPER_LEFT", "1", "0", "IGNORE", "INDEX")
    #Flip them back to the original direction
    FlipLine_edit(in_features="BackwardSegsCNP")
    LocateFeaturesAlongRoutes_lr("Non_State_Classified_NonPrimary",
                                 "CNP_ShapeLengthRoute", "LRS_KEY", "0 Feet",
                                 "CNP_NON_STATE_EVENTS",
                                 "RID LINE FMEAS TMEAS", "FIRST", "DISTANCE",
                                 "ZERO", "FIELDS", "M_DIRECTON")
    AddField_management("CNP_NON_STATE_EVENTS", "AdjBegin", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNP_NON_STATE_EVENTS", "AdjEnd", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNP_NON_STATE_EVENTS", "CHG_BEGLOG", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNP_NON_STATE_EVENTS", "CHG_ENDLOG", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNP_NON_STATE_EVENTS", "NEW_BEGLOG", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNP_NON_STATE_EVENTS", "NEW_ENDLOG", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNP_NON_STATE_EVENTS", "AdjLength", "DOUBLE", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNP_NON_STATE_EVENTS", "CHANGE", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")

    CalculateField_management("CNP_NON_STATE_EVENTS", "AdjBegin",
                              "round( [FMEAS] , 3 )", "VB", "")
    CalculateField_management("CNP_NON_STATE_EVENTS", "AdjEnd",
                              "round( [TMEAS] , 3 )", "VB", "")
    CalculateField_management("CNP_NON_STATE_EVENTS", "CHG_BEGLOG",
                              "[AdjBegin] - [LRS_BEG_CNTY_LOGMILE]", "VB", "")
    CalculateField_management("CNP_NON_STATE_EVENTS", "CHG_ENDLOG",
                              "[AdjEnd] - [LRS_END_CNTY_LOGMILE]", "VB", "")
    CalculateField_management("CNP_NON_STATE_EVENTS", "NEW_BEGLOG",
                              "[AdjBegin]", "VB", "")
    CalculateField_management("CNP_NON_STATE_EVENTS", "NEW_ENDLOG", "[AdjEnd]",
                              "VB", "")

    CalculateField_management("CNP_NON_STATE_EVENTS",
                              "AdjLength",
                              "[AdjEnd] - [AdjBegin]",
                              "VB",
                              code_block="")
    CalculateField_management("CNP_NON_STATE_EVENTS",
                              "CHANGE",
                              "abs([LENGTH] - [AdjLength])",
                              "VB",
                              code_block="")

    MakeRouteEventLayer_lr("CNP_ShapeLengthRoute", "LRS_KEY",
                           "CNP_NON_STATE_EVENTS", "RID LINE FMEAS TMEAS",
                           "CNP_LRS_Review_Events", "", "ERROR_FIELD",
                           "NO_ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT",
                           "POINT")
    AddField_management("CNPRouteShapeLength", "PersistentID", "LONG", "", "",
                        "", "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNPRouteShapeLength", "Pbeg", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNPRouteShapeLength", "Pend", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")

    CalculateField_management("CNPRouteShapeLength", "PersistentID", "!ID2!",
                              "PYTHON_9.3", "")
    TableToTable_conversion("CNPRouteShapeLength", "in_memory", "CNP_Events",
                            "")

    endpoints = ["beg", "end"]
    for pos in endpoints:
        out_event = "CNP_Events_" + pos
        print out_event
        out_lyr = "CNP_Events_Features_" + pos
        print out_lyr

        outfield = "P" + pos
        print outfield
        if pos == "beg":
            print "Will locate begin point"
            routesettings = "LRS_KEY POINT BCM"
        else:
            print "locating end point"
            routesettings = "LRS_KEY POINT ECM"
        MakeRouteEventLayer_lr("CNP_ShapeLengthRoute", "LRS_KEY", "CNP_Events",
                               routesettings, out_event, "", "ERROR_FIELD",
                               "ANGLE_FIELD", "NORMAL", "ANGLE", "LEFT",
                               "POINT")
        LocateFeaturesAlongRoutes_lr(out_event, "CP_ShapeLengthRoute",
                                     "NQR_DESCRIPTION", "500 Feet", out_lyr,
                                     "RID POINT MEAS", "ALL", "DISTANCE",
                                     "ZERO", "FIELDS", "M_DIRECTON")
        AddJoin_management(out_lyr, "PersistentID", "CNPRouteShapeLength",
                           "PersistentID", "KEEP_ALL")
        selexp = out_lyr + ".RID <> CNPRouteShapeLength.LRS_KEY"
        print selexp
        SelectLayerByAttribute_management(out_lyr, "NEW_SELECTION", selexp)
        DeleteRows_management(out_lyr)
        RemoveJoin_management(out_lyr)
        AddJoin_management("CNPRouteShapeLength", "PersistentID", out_lyr,
                           "PersistentID", "KEEP_ALL")
        #expression = "[CNP_Events_Features_Begin.MEAS]"
        expression = "[" + out_lyr + ".MEAS]"
        print expression
        calcfield = "CNPRouteShapeLength." + outfield
        #CNPRouteShapeLength.Pbeg
        CalculateField_management("CNPRouteShapeLength", calcfield, expression,
                                  "VB", "")
        RemoveJoin_management("CNPRouteShapeLength", "")

    #test flipped routes and calculate mileage and flip flag
    AddField_management("CNPRouteShapeLength", "FlipTest", "LONG", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNPRouteShapeLength", "Adj_Beg", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    AddField_management("CNPRouteShapeLength", "Adj_End", "DOUBLE", "", "", "",
                        "", "NULLABLE", "NON_REQUIRED", "")
    SelectLayerByAttribute_management("CNPRouteShapeLength", "NEW_SELECTION",
                                      '"Pbeg" > "Pend"')
    CalculateField_management("CNPRouteShapeLength", "FlipTest", "1", "VB", "")
    CalculateField_management("CNPRouteShapeLength", "Adj_Beg", "!Pend!",
                              "Python", "")
    CalculateField_management("CNPRouteShapeLength", "Adj_End", "!Pbeg!",
                              "Python", "")
    SelectLayerByAttribute_management("CNPRouteShapeLength", "NEW_SELECTION",
                                      '"Pbeg" < "Pend"')
    CalculateField_management("CNPRouteShapeLength", "FlipTest", "0", "VB", "")
    CalculateField_management("CNPRouteShapeLength", "Adj_Beg", "!Pbeg!",
                              "Python", "")
    CalculateField_management("CNPRouteShapeLength", "Adj_End", "!Pend!",
                              "Python", "")
    SelectLayerByAttribute_management("CNPRouteShapeLength", "NEW_SELECTION",
                                      '"Adj_Beg" <= 0.003')
    CalculateField_management("CNPRouteShapeLength", "Adj_Beg", "0", "Python",
                              "")

    print "CNP-Rte Builder script completed successfully"
Beispiel #18
0
        print "created the new geodatabase"
except:
    CreateFileGDB_management(r"C:/TEMP", "Nusys_Check.gdb")
    print "DB could not be deleted"

env.workspace = r"C:/TEMP/Nusys_Check.gdb"

MakeFeatureLayer_management(NonState, "NonState", "(LRS_KEY like '%C%' OR LRS_ROUTE_PREFIX = 'C') AND MILEAGE_COUNTED = -1")

#NonState System has unique IDS that are also the non_persistent Object ID's
#To force persistence on the Unique IDS, perform an intersect to the state boundary layer
print "buffering the state boundary"
Buffer_analysis(r"Database Connections/SDEPROD_SHARED.sde/SHARED.STATE_BOUNDARY", r"C:/temp/Nusys_Check.gdb/State_Boundary_1Mile", "5280 Feet", "FULL", "ROUND", "NONE", "", "PLANAR")
print "intersecting non_state system to the state boundary to preserve Object ID's and eliminate non-spatial segments"
MakeFeatureLayer_management(r"C:/temp/Nusys_Check.gdb/State_Boundary_1Mile", "StateBnd" )
Intersect_analysis("NonState #;StateBnd #", r"C:/temp/Nusys_Check.gdb/Non_State_Classified", "ALL", "-1 Unknown", "LINE")
print "adding layers to gp workflow or MXD"
NonState_fx = r'C:/temp/Nusys_Check.gdb/Non_State_Classified'

MakeFeatureLayer_management(NUSYS, "Nusys_Extract", "NSEC_SUB_CLASS <> 'R'" )
MakeFeatureLayer_management(NonState_fx, "Non_State_Classified" )

def LinearReferenceCheck():
    print "locating NON_STATE_SYSTEM features along the NUSYS Rotue - creates an event table with Route/begin/end mileage"
    print "the tolerance for this process is 20 feet.  Because this is not an exact process, it is for reference purposes only to compare segmentation mileage"
    print "it looks like unless calculated segment per segment, this will not ever be exact"
    LocateFeaturesAlongRoutes_lr(NonState_fx, NUSYS, "ROUTE", "20 Feet", "Nonstate_Nusys_LFAR", "RID LINE FMEAS TMEAS", "FIRST", "DISTANCE", "ZERO", "FIELDS", "M_DIRECTON")
    MakeRouteEventLayer_lr(in_routes="Nusys_Extract", route_id_field="route", in_table="Nonstate_Nusys_LFAR", in_event_properties="rid LINE fmeas tmeas", out_layer="Nonstate_Nusys_LFAR Events", offset_field="", add_error_field="ERROR_FIELD", add_angle_field="NO_ANGLE_FIELD", angle_type="NORMAL", complement_angle="ANGLE", offset_direction="LEFT", point_event_type="POINT")

def Non_State_Centerpoint_Check():
    MakeFeatureLayer_management(in_features="Database Connections/SDEPROD_SHARED.sde/SHARED.NON_STATE_SYSTEM", out_layer="C_Routes", where_clause="LRS_KEY like '%C%' OR  LRS_ROUTE_PREFIX = 'C'")