2

I am currently spatial joining two feature classes like this

arcpy.SpatialJoin_analysis(target_features,join_features,output_features,
                       join_operation="JOIN_ONE_TO_ONE",
                       join_type="KEEP_ALL",
                       match_option="CLOSEST")

I need to access the object ID of each join feature that was joined to the target feature. However, in spatial joins, arcpy only adds "JOIN_FID" in one-to-many joins. In a one-to-one join I only get "TARGET_FID" (which seems pretty useless as I knew that already).

How can I access (programatically) the feature ID of the joined feature from the output feature class?

  • 1
    Why can't you use a one-to-many join, to access the JOIN_FID? – Aaron Jun 25 '14 at 16:40
  • Doesn't one-to-many only join features which intersect? – Sideshow Bob Jun 26 '14 at 9:31
3

Very interesting! I think the simplest way of doing this is to create a brand new field in your joining featureclass, copy the object ID's into it and do the one to one spatial join.

As you are doing a closest join a more complex approach would be run a one to many spatial join but make sure you set the optional distance field name to something. Then the output table can be run through a summary statistics tool filtering for the minimum distance and the case field being the FID. This way get your JOIN_FID field but this not an efficient approach if you have thousands of features to join to and from.

  • This is what I did in the end (copying the object IDs). Seems odd that Arc doesn't provide the JOIN_FID, but stranger things have happened before. – Sideshow Bob Jun 26 '14 at 9:32

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.