Model Builder 9.3 - Field mappings for Spatial Join

Discussion created by DanEvans83 on May 19, 2011
Latest reply on Jun 7, 2011 by DanEvans83

I'm trying to create a simple model that calculates the total length of polylines (pipes) within a set of polygons, the number of points (leakage incidents) within the polygons and also the number of points per kilometre of polylines. I've done this process 'manually' a few times and it consists of:

- Collect Events on the points.

- An intersect of the pipes and polygons so that pipes that cross over polygon boundaries are split at the boundaries.

- A spatial join of the intersected pipes to the polygons, with the field mapping set to sum the shape_length field. The other fields from the pipes feature class are not included. This gives the total length of pipes in each polygon.

- Another spatial join of the collected leakage points to the output of the previous spatial join, with the field map set to sum the icount for each point. This gives the total number of leaks for each polygon.

- Finally a new field is added and a field calculation run to calculate the number of leaks / total length of pipes in metres * 1000 = leaks per km.

I'm having some difficulty working out how to build this into a model. The attachment shows what I've got so far.

How do I deal with the field mapping for the spatial joins? The first spatial join (that gets the length of pipe per polygon) should always only include the name of the polygon and the summed length of pipe, but because the input feature classes are model parameters the spatial join doesn't yet 'know' in model builder what fields to expect. I can add a field mapping variable and expose it as a parameter but I'd rather the user not have to set up the mapping every time. Can I instead get the user to specify the field to use for the length in the pipes feature class, and somehow use that to set up the mapping?

Similarly with the other spatial joins used to sum the counts of the points in the polygons...

Is there a better tool for this than a spatial join? Unfortunately I only have an ArcView license...

I'm also a bit unclear as to how to use the Calculate Field tool - I have used the field calculator in the attribute tables lots but not the tool version. Is the VB that this tool uses the same as the VBA I have used in the other field calculator? What do I need to include in the expression box - do I need to put the field name =...? How do I make sure the calculator calculates into the new field I've just added?

Also, the leakage points have a date field - eventually I want to be able to split the leakage by year and have columns for the number of leaks for each year as well as a total number of leaks... So I guess I'd do this by performing selections by year on the leakage data before passing each year selection to separate Collect Events tools and then I need a spatial join for each one... At the moment the data goes back to 2006 but is there a way to generalise this to be able to cope with any range of years?

Any help is much appreciated!