I am trying to perform a spatial join to join attributes from a point feature layer to the attributes of a line feature layer where the points are within a specified distance of the lines (so that these attributes can later be used in an update cursor). Currently, I am receiving a '000561: Relationship invalid for selected layers' error while trying to run this piece in Visual Studio. A spatial join based on distance between point and line features appears to work without a hitch in ArcMap and ModelBuilder. I would like to avoid field mapping if possible, but maybe that is something I may need to add in.

What am I missing?

import arcpy
from arcpy import env

arcpy.env.OverwriteOutput = True

defaultGdbPath = 'C:\Topo_Check_Tess_V5.gdb'



#Make feature layer
arcpy.MakeFeatureLayer_management(ppLayer, "ppLayerGU")

#Make feature layer
arcpy.MakeFeatureLayer_management(transLayer, "transLayerGU")

#output join fc
pp_trans_GUJoin ='C:\Topo_Check_Tess_V5.gdb\pp_trans_GU_SpatialJoin'

#spatial join of feature layers
arcpy.SpatialJoin_analysis ("transLayerGU", "ppLayerGU", 

1 Answer 1


In theory you shouldn't have to use field mappings. There is a typo in your code, however.

Remember that the format for SpatialJoin is

SpatialJoin_analysis (target_features, join_features, out_feature_class, {join_operation}, {join_type}, {field_mapping}, {match_option}, {search_radius}, {distance_field_name}),

The error is coming from the software parsing your options as:


match_option: .000002

Since .000002 is clearly not a valid match option, the code fails. ArcGIS Pro help notes that using "#" or "" is how you skip over the optional arguments if you don't need them, or referencing the optional arguments by name. Link

You may still require field mappings if there are multiple points to be joined to each line, however.

Refs: Spatial Join: http://pro.arcgis.com/en/pro-app/tool-reference/analysis/spatial-join.htm

Tools in ArcPy: http://pro.arcgis.com/en/pro-app/arcpy/geoprocessing_and_python/using-tools-in-python.htm

  • I'm using Python 2.7 and 10.4 and '#' works beautifully. Thanks a bunch! Commented Apr 11, 2017 at 18:33
  • No problem! I use 10.4 most of the time, but the code samples and guides in the Pro websites are excellent.
    – nboyko
    Commented Apr 11, 2017 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.