1

In this example from ESRI, the MergeRule is set to "Mean" and the values from two fields from two different feature classes are averaged and written to a new field.

 # Set the merge rule to mean and then replace the old fieldmap in the mappings object
 # with the updated one
 fieldmap.MergeRule = "mean"
 fieldmappings.ReplaceFieldMap(fieldmappings.FindFieldMapIndex("POP1990"), fieldmap)

In the context of executing a Spatial Join (assuming I've already called my input and target feature classes' field maps), how would I rewrite this bit of code to set the MergeRule to "Join" multiple features' attributes of the same field into the same field in the output feature class using "; " as a delimiter?

So the attributes of FieldA of my target features' that intersect my target features all get written to FieldA in the output spatially joined feature class. For example, in the image below the purple feature (originally my target feature) in my output feature class would have FieldA = "brown; orange".

enter image description here

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Oct 22, 2013 at 18:17
4
  • It seems to me you should just be able to set the two properties you mentioned and it should work. Have you tried it? Commented Oct 23, 2013 at 7:25
  • That's what I'm asking how to do. Is it just: fieldmap.MergeRule = "join", joinDelimiter"; " Commented Oct 23, 2013 at 13:23
  • Basically, how do I write the code to include using a delimiter? Commented Oct 23, 2013 at 20:43
  • Got it: fieldmap.mergeRule = "Join" fieldmap.joinDelimiter = "; " fieldmappings.replaceFieldMap(SubBasinFieldIndex, fieldmap) Commented Oct 23, 2013 at 22:18

1 Answer 1

2

Set one property on one line and the other property on another line. Setting properties is done with the single equals sign, as in fieldmap.mergeRule = 'join'. The other property would be fieldmap.joinDelimiter = ';'.

This is very basic Python syntax fundamentals, so if you are struggling with that, I suggest going through the Python tutorial (IMO, a must even for intermediate programmers).

Also note that the case of the property names has apparently changed since the 9.3 and 10.0 (e.g., MergeRule is now mergeRule). See the FieldMap (10.0) documentation.

answered Oct 23, 2013 at 21:19
1
  • Thanks. Yes, I'm just beginning to learn python. Trying to learn by solving a particular problem Commented Oct 23, 2013 at 22:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.