2

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'

#lines
transLayer='C:\Topo_Check_Tess_V5.gdb\Transmission'

#points
ppLayer='C:\Topo_Check_Tess_V5.gdb\PP'


#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", 
pp_trans_GUJoin,'JOIN_ONE_TO_ONE','KEEP_ALL','WITHIN_A_DISTANCE',.000002) 
3

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:

field_mapping:'WITHIN_A_DISTANCE'

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! – Tess Gardner Apr 11 '17 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. – coneypylon Apr 11 '17 at 18:34

Your Answer

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

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