Hello 🙂
I need to create random points. I was using the function to do this in ArcGIS but I got a problem. I can´t define a maximum distance among points.
I am trying to do so, starting with a fishnet points layer. I add fields that hold the values of the coordinates plus a random number between a minimum and a maximum.
The code works well.
However, I run into problems trying to create a new points layer. I used "FeatureClassToNumPyArray" and "NumPyArrayToFeatureClass" trying to replace the original shape@XY with the displaced points. I get this error:
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
In [104]:
Line 94: arcpy.da.NumPyArrayToFeatureClass(arr_random_points, Vpc,("RX","RY"))
RuntimeError: invalid table name
---------------------------------------------------------------------------I do not understand why the array is not valid. Is there something wrong in my code?
This is the code:
# Creation of Random Points from a Fishnet inside a rectangle
vOx=arr_poly["OX"][0]
vOy=arr_poly["OY"][0]
vMx=arr_poly["MX"][0]
vMy=arr_poly["MY"][0]
Orig_coord=str(vOx) + " " + str(vOy)
print(Orig_coord)
Y_axis_c=str(vOx) + " " + str(vMy)
print(Y_axis_c)
arcpy.management.CreateFishnet("Fishnet_feat",Orig_coord,Y_axis_c,0.5,0.5,"","","","LABELS",Boundary_polygon,"POLYGON")
arcpy.management.AddFields(
"Fishnet_feat_label",
[['X', 'DOUBLE', 'X', "10", "2",""],
['Y', 'DOUBLE', 'Y', "10","2",""],
['RX', 'DOUBLE', 'RX', "10","","2"],
['RY', 'DOUBLE', 'RY', "10","2",""],
["New_Shape","TEXT","New_Shape",50,""]])
arcpy.management.CalculateGeometryAttributes("Fishnet_feat_label", [["X", "POINT_X"], ["Y", "POINT_Y"]])
arcpy.management.CalculateFields("Fishnet_feat_label", expression_type="PYTHON3", fields=[["RX", "round(!X! + random.uniform(0,0.9),2)"], ["RY", "round(!Y! + random.uniform(0,0.9),2)"], ["New_Shape", "str(!RX!) +\",\" + str(!RY!)"]], code_block="import random")
arr_random_points= arcpy.da.FeatureClassToNumPyArray("Fishnet_feat_label",["*"])
Vpc="test.shp"
arcpy.da.NumPyArrayToFeatureClass(arr_random_points, Vpc,("RX","RY"))
Print(Vpc) Thank you!