0

I'm trying to deal with an odd crash that occurs irregularly in arcGIS's arcpy, specifically under the create random points tool.

This occurs under ArcGIS 10.1 to 10.3.

During "CreateRandomPoints", the program attempts to create by polygon a number of points in the polygon, the number dictated by a field. The problem I experience is that occasionally, upon attempting this line, python will immediately crash without giving an error code.

I accept that it's a known issue. I accept that there's nothing to be done about the crash itself, other than working around it. the problem is, i can't seem to catch the error and work around it.

I have embedded the code chunk containing

 arcpy.CreateRandomPoints_management(wkspc,outshape,shape,,field)

inside of a try/except block. I have set up a logic where hopefully the code would execute (and if necessary, fail) 5 times before exiting the program with an informative error. However, it only runs once, and exits the program without stating the error. (my try/except block isn't catching the error).

I have tried every error code I can think relevant, even a naked except block which to my knowledge should catch everything.

Is there some other means to catch the error? something i haven't tried yet?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 29, 2015 at 15:42
1
  • I've fixed the workflow so that If I do have a crash, it won't cause lasting problems, but i don't know if I've solved the crash. Commented Dec 5, 2015 at 23:44

1 Answer 1

1

The error might be from how you're formatting the arguments with that empty argument between shape and field. You could try this instead:

arcpy.CreateRandomPoints_management(wkspc, outshape, shape, number_of_points_or_field=field)

Otherwise, I don't know if this would work for you, but I have a tool I made that creates random points too. You can download it here:

Generate Random Points Toolbox

View the Source Code

You could then use this in your Python script by doing the following:

arcpy.ImportToolbox("C:\\Tools\\GenerateRandomPoints.tbx")
arcpy.GenerateRandomPoints_GenerateRandomPoints(input_polygon, "YES", "fieldname", "#", 40, 2000, "KEEP_ALL", output)
#where parameters for the tool are:
arcpy.GenerateRandomPoints_GenerateRandomPoints(Input_Polygon_Feature_Class, Use_Field_for_Number_of_Random_Points, {Field_with_Number_of_Random_Points}, {Number_of_Random_Points}, Minimum_Distance_Between_Points, Maximum_Attempts, Keep_Point_Attempts, Output_Point_Feature_Class)

Here's a screenshot of the parameters: enter image description here

answered Nov 29, 2015 at 19:51
1
  • in arcpy.createrandompoints_management(), the empty argument is for the "extent" that would be used if the input shapefile wasn't populated. It is, so that argument is meaningless. That said, I tested your tool versus the arcpy tool.... In both cases, the input dataset (limited to 3 states... so a subset of the total data) was loaded in memory prior, and the arcpy tool took 15 seconds while your tool tool 350 seconds. I think your tool moves the data to memory (again), so the test may be a bit biased against your tool Commented Dec 5, 2015 at 23:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.