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– blah2382013年10月23日 07:25:05 +00:00Commented Oct 23, 2013 at 7:25
-
That's what I'm asking how to do. Is it just: fieldmap.MergeRule = "join", joinDelimiter"; "geominded– geominded2013年10月23日 13:23:08 +00:00Commented Oct 23, 2013 at 13:23
-
Basically, how do I write the code to include using a delimiter?geominded– geominded2013年10月23日 20:43:22 +00:00Commented Oct 23, 2013 at 20:43
-
Got it: fieldmap.mergeRule = "Join" fieldmap.joinDelimiter = "; " fieldmappings.replaceFieldMap(SubBasinFieldIndex, fieldmap)geominded– geominded2013年10月23日 22:18:42 +00:00Commented Oct 23, 2013 at 22:18
1 Answer 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 problemgeominded– geominded2013年10月23日 22:19:31 +00:00Commented Oct 23, 2013 at 22:19
Explore related questions
See similar questions with these tags.