Create random points loop

423
2
Jump to solution
02-14-2022 06:40 AM
ErikKjellman
New Contributor III

I have shapefile with several different fields in which there is data that needs to be converted into random points. Currently I have been using the Create Random Points (Data Management) tool, which works really well but is very timeconsuming when i have a lot of these that I want to process. What I am wondering is if there is a way to automate this with a loop so I only have to do this once per shapefile, or perhaps once per GDB? My coding skills are lacking at best (although I am learning), so I am not sure this will work.

My Idea is that the script should loop through all fields and use the field name as outName and Numfield.

This is what it currently looks like, but I am getting errors which i'm not  sure I understand. The latter seems to be because the table field is a join field, but I don't see another way of describing the field other than with the field name.

 

 

 

import arcpy

arcpy.env.overwriteOutput = True

fieldList = ["T_Flekke_spes_mat$_.Heterogen", "T_Flekke_spes_mat$_.Grå", "T_Flekke_spes_mat$_.Bryozo", "T_Flekke_spes_mat$_.Hvit_grov", "T_Flekke_spes_mat$_.Lys_fin", "T_Flekke_spes_mat$_.Mørk_fin", "T_Flekke_spes_mat$_.Uspesifisert"]

for field in fieldList:
    outGDB = "D:\ArcGIS\HV\HV.gdb"
    outName = field
    conFC = "D:\ArcGIS\HV\HV.gdb\Årbogen_lag_1"
    numField = field
    arcpy.CreateRandomPoints_management(outGDB, outName, conFC, "", numField)

 

 

 

 

---------------------------------------------------------------------------
ExecuteError                              Traceback (most recent call last)
In  [3]:
Line 12:    arcpy.CreateRandomPoints_management(outGDB, outName, conFC, "", numField)

File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py, in CreateRandomPoints:
Line 21598: raise e

File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py, in CreateRandomPoints:
Line 21595: retval = convertArcObjectToPythonObject(gp.CreateRandomPoints_management(*gp_fixargs((out_path, out_name, constraining_feature_class, constraining_extent, number_of_points_or_field, minimum_allowed_distance, create_multipoint_output, multipoint_size), True)))

File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py, in <lambda>:
Line 512:   return lambda *args: val(*gp_fixargs(args, True))

ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000728: Field T_Flekke_spes_mat$_.Heterogen does not exist within table
Failed to execute (CreateRandomPoints).

---------------------------------------------------------------------------
0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

try making the join permanent (eg.  a new featureclass and see if that solves the problem


... sort of retired...

View solution in original post

0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

try making the join permanent (eg.  a new featureclass and see if that solves the problem


... sort of retired...
0 Kudos
ErikKjellman
New Contributor III

Thanks, that did the trick!

0 Kudos