I am trying to iterate through a set of polygons and for each polygon select the points in another feature class which fall within. Once those points are selected I want sum the values of one of the point attributes and add that sum to an attribute field in the polygon. Everything seems to work except if no point falls within the polygon instead of 0 the field in the polygon attribute is filling to 1. I have tried various preconditions and the field value Null is set to 0 but this keeps occurring. Attached is a copy of the current model.
Solved! Go to Solution.
you may accidentally have a selection on a layer?
Should be One to one not one to Many? that seems like the issue.
If doesn't work, just try with all the defaults, and don't add a new field or change anything except for changing the merge rule.
Can you not achieve the same without a model and use a Spatial Join, with a field mapping merge rule set to 'SUM' of that particular field?
I'm looking to total an attribute field in the selected point feature class which has a count number in it, so not just summing the number of points that fall within the polygon. For instance there may be two points within the polygon, one with a count of 1 and one with a count of 3. I want to fill in the polygon attribute with the value of 4. This model successfully does that but when there are no points within the polygon it is filling in the attribute field as 1 instead of 0.
Yes, you can control how a field is mapped in the spatial join. As you say, the default would be to return a JOIN_COUNT, JOIN_FID etc. and the other fields you have specified in the field mapping.
Of those other fields, you would have the attribute of the first coincident point found, BUT you can control how this is done.
Look at the field map parameter in the tool, and the merge rule dropdown.
from the link I supplied:
Merge rules specified in the Field Map of Join Features parameter only apply to attributes from the join features and when more than one feature is matched to a target feature (when Join_Count > 1). For example, if three features with DEPTH attribute values of 15.5, 2.5, and 3.3 are joined, and a merge rule of Mean is applied, the output field will have a value of 6.1. Null values in join fields are ignored for statistic calculation. For example, 15.5, <null>, and 2.5 will result in 9.0 for Mean and 2 for Count.
I see what you mean, so:
Target Features: Polygon
Join Features: Point
Output fields: Polygon attribute field selected
Source: Merge Rule=Sum, Point attribute field to sum selected
This configuration gives me all NULL values in the polygon field.
can you screenshot the tool parameters and the output?
the resolution of that screenshot prevents anyone apart from the NSA reading it unfortunately.
no, forget about ART_COUNT, just use TOT_GS with a SUM merge rule, otherwise a field map is created of the sum of ART_COUNT instead of TOT_GS (which is NULL + NULL + ...).