Trying to get to the bottom of an unusual behaviour which I am seeing in a join. Background as follows:

  1. I have a feature class of centroids which have been located on the network.

  2. I have a solved OD Cost Matrix layer.

  3. I now want to join the OD lines sub-layer to the centroids so that I can access the centroid snap-distance.

  4. The join works in one direction just fine and returns values from the left and right tables.

  5. However when the order of the join is reveresed, while the join still returns results, only values from the left table are included but not the right. I am wondering as to why this is the case?

        # Create a temporary feature layer to allow us to add a join to the selected centroids.
        centroid_layer_temp = arcpy.MakeFeatureLayer_management(selected_centroids,'centroids_layer_temp')
        lyr_desc = arcpy.Describe(centroid_layer_temp)
        #(1) This join works and returns joined rows as expected. Values from both left and right tables are included.
        matched_centroids = arcpy.AddJoin_management(centroid_layer_temp, "OBJECTID", od_line_layer, "OriginID", "KEEP_COMMON")
        #(2) This join works i.e. it returns rows but only values from the left table are included in the result...why?
        matched_centroids = arcpy.AddJoin_management(od_line_layer, "OriginID", centroid_layer_temp, "OBJECTID", "KEEP_COMMON")
        # Get centroid data and store for later use.
        # This throws an error for (2) above because no fields from the right table are included in the result.
        grid_centroids = []
        centroid_search_fields = ['{}.OBJECTID'.format(lyr_desc.name), '{}.Distance'.format(lyr_desc.name)]
        with arcpy.da.SearchCursor(matched_centroids, centroid_search_fields) as search_cursor:
            for row in search_cursor:
        # notify is a convenience method to log and output to UI at same time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.