As part of a larger, more complex model, I need to generate random points over an input feature class where the ModelBuilder calculates the minimum allowed distance on the fly. This is my minimum working example:
In this model, my number
is a user-defined integer. In this case 50. This number is modified by the Calculate Value Tool (equation: 2* my number + 30, output type: Long) to create the number dist
.
The Constraint Polygons
is just an ordinary multi-polygon feature class. workspace
is the output workspace for the random points.
The value dist
is connected as "Minimum Allowed Distance [value or field]", and was calculated as a Long-type by the Calculate Value Tool.
Connection between dist and Generate Random Points
When I run the model, I get the error 'Error 000176: Field must be numeric'. Error when running the model
I tried to turn the value dist
into a Double-type, but that didn't help. I also tried adding dist
as a precondition to Create Random Points, but that didn't help either.
I also tried inserting %dist% in Minimum Allowed Distance, but that only resulted in the tool using 0m distance.
How can I generate a set of points using a pre-calculated distance?
2 Answers 2
If you review the help file for Create Random Points and look at the parameter section, what is the Data Type for the parameter Minimum Allowed Distance? You have fed in a number long or double but the data type is Linear Units. This is the problem.
The output of your calculate value tool needs to be a Linear Units object not a number as you have provided.
So how do you build one? Run the create random points tool on some test data, then from history panel copy to script and you will see the structure of it and this is what your Calculate Value tool needs to build. Something like "100 Meters"
.
-
1Thanks I thought I was going mad. I used
str(num) + " Meters"
in the code block to convert the number to a linear unit. When the data type of the Calculate Value Tool is also set to Linear Units, it works.saQuist– saQuist2024年09月02日 12:40:24 +00:00Commented Sep 2, 2024 at 12:40
The error message could point to a possible solution: Check the "Data type" at the bottom of the Dialog of Calculate Value. This should be Double for Decimal Numbers or Long for Integers. At the Moment it is probably set to Variant.
-
1Good point, but this was already mentioned in the question and it did not solve my issue.saQuist– saQuist2024年09月02日 12:17:54 +00:00Commented Sep 2, 2024 at 12:17