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 more
My problem is as follows: I'm using model builder for all of this. I set up a blank feature class 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. 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. 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) 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 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?
... View more