0

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

  • It seems to me you should just be able to set the two properties you mentioned and it should work. Have you tried it? – blah238 Oct 23 '13 at 7:25
  • That's what I'm asking how to do. Is it just: fieldmap.MergeRule = "join", joinDelimiter"; " – geominded Oct 23 '13 at 13:23
  • Basically, how do I write the code to include using a delimiter? – geominded Oct 23 '13 at 20:43
  • Got it: fieldmap.mergeRule = "Join" fieldmap.joinDelimiter = "; " fieldmappings.replaceFieldMap(SubBasinFieldIndex, fieldmap) – geominded Oct 23 '13 at 22:18
1

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.

  • Thanks. Yes, I'm just beginning to learn python. Trying to learn by solving a particular problem – geominded Oct 23 '13 at 22:19

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.