Spatial Join in ModelBuilder overwriting Allow NULL values?

884
1
Jump to solution
06-26-2018 01:28 PM
DevonBurton1
New Contributor II

My problem is as follows:

I'm using model builder for all of this.

  1. I set up a blank feature class
  2. I add fields to this blank feature class with names based on strings in a list, with the option Allow NULL values : No. Type: double, and immediately set their default value to 0. No records yet, it's all fine.
  3. I append a line to this blank feature class (which has type: polyline) with schema type as: NO_TEST. The output is still "No" for all relevant fields, and they have their default value of 0.
  4. I convert this line into a bunch of equally long line segments. Each field is still "No" for NULL values and the default of 0 is listed for each record. (Generate points along line -> split line at points, this is fine)
  5. I run a spatial join on the output of 4 and a featureclass that exists here and there along my line, with a "Within distance: 100 meters". I make sure that the field mapping still has everything set to "No" for NULL values, BUT
  6. The output fields are now all Allow NULL Values: "Yes"
    • My goal was to use the field calculator to grab the sum of a field from the joined featureclass and add it to a running total field in the target featureclass, I intended to get around an issue I was having wherein the target features that lacked a spatially joined feature would get NULL added to it, I think, and remove the value, causing me to eventually get ONLY NULL values for all of my relevant fields.
    • I kept all target features because I didn't want to join some separated tables based on a UID, but I'm starting to get the feeling that I'll have to do that anyways

Does Spatial Join do this sometimes where it can overwrite the Allow Null Values flag from No to Yes?

Is there any way for me to prevent that?

Is the easier way to just join fields based on UID later?

What's a solution to this?

I had an idea where I could do this in python and use search cursors/ update cursors to just NOT calculate field on records where any of my inputs are NULL but that could take a while for me to set up compared to this version in model builder. This is mainly due to my own limited experience.

I also feel quite unaware of logical operations from inside model builder / the field calculator, so maybe the solution is something like "if input field == NULL" or "if NOT inputField:" from within my field calculator, possibly expanding that to change the value of a variable to 0 if that condition is met, like a = inputField if the inputField has a number in it and a=0 if the input field doesn't have a number in it. Any tips on how to do that logical test if my above solution isn't the right way to do this?

0 Kudos
1 Solution

Accepted Solutions
DevonBurton1
New Contributor II

Amazing what a night's sleep will do:

Using field calculator and learning how to do pre-logic scripting, I added this and this seems to work perfectly.

def myTest(dest,test,test1):
    if test==None:
        a = dest + 0
        return a
else:
    a = dest + test + test1
    return a

View solution in original post

0 Kudos
1 Reply
DevonBurton1
New Contributor II

Amazing what a night's sleep will do:

Using field calculator and learning how to do pre-logic scripting, I added this and this seems to work perfectly.

def myTest(dest,test,test1):
    if test==None:
        a = dest + 0
        return a
else:
    a = dest + test + test1
    return a

0 Kudos