I've been trying to create random points to sample some locations based, at first, on a field which contains the number of samples I want.
But when I tried at first, in almost every feature it was sampled less than the number of the field.
Then, I tested another way: since I was writting inside a loop through cursor, and one of the fields of the cursor was the area in hectares, and the number of samples is based on the area of the feature, I decided to calculate out of the field the number of samples, but the result was the same.
Then, I was wondering what could cause this problem, it was when I decided to try to run the function with the minimum_distance
parameter set to zero, and it worked!
Apparently, what happened is that when I run the function with the minimum_distance
parameter, if a random point falls near another point within the minimum distance, the point is removed and I cannot get the total number of samples I need.
Here is the part of the code:
if 16 <= x[1] < 25:
minimum_distance = 100
elif x[1] > 25:
minimum_distance = 150
else:
minimum_distance = 0
number_of_samples = int(x[1]/8)
if number_of_samples == 0:
number_of_samples = 1
print(number_of_samples)
arcpy.CreateRandomPoints_management(out_path=arcpy.env.workspace,
out_name='samples_{}'.format(x[0]),
constraining_feature_class=negBuf_tal,
number_of_points_or_field=number_of_samples,
minimum_allowed_distance=minimum_distance)
Where:
x[0]: unique code of feature (inside a loop through cursor);
x[1]: Area in hectares of feature (inside a loop through cursor);
negBuf_tal: negative buffer area of the feature which the loop is going through (to avoid sampling on borders).
OBS: If after the negative buffer the area "desappears", the area to sample in becomes the area without the buffer itself.
How can I solve this without having to write a while structure or something like this?