Create Random Points in Polygon Feature Class

4962
4
Jump to solution
03-19-2015 01:09 AM
NilsRatnaweera
New Contributor III

Hey Guys,

I'm trying to use the tool "Create Random Points (Data Management)" in order to distribute 1 random point per Polygon using arcpy. My script is the following:

arcpy.CreateRandomPoints_management(out_path = "C:/Data/",  out_name="random.shp", constraining_feature_class="C:/Data/Grid3b.shp", number_of_points_or_field=1)

The weird thing is, the output create contains the expected amout of points, but they all have the same coordinates (i.e. are "on top of each other) and are far off from where they should be. I've uploaded my the constraining shapefile here, can someone help me out?

0 Kudos
1 Solution

Accepted Solutions
KishorGhatage
Occasional Contributor III

Could you please run repair geometry on the Grid3b and then use Create random points. When I ran the repair geometry I found problem with 24 features in this file.

Result:

"WARNING 000986: C:\Users\.........Local\Temp\Grid3b0.txt contains the full list of non simple features.

WARNING 000461: Repaired feature 0 because of incorrect ring ordering, ...., ......, ......, ......  WARNING 000461: Repaired feature 24 because of incorrect ring ordering"

Regards

Kishor

View solution in original post

4 Replies
KishorGhatage
Occasional Contributor III

Try using following syntax. Currently I do not have access to advanced license to test the behavior.

arcpy.CreateRandomPoints_management(r'C:\Temp',"Random.shp",r'C:\Temp\Grid3b.shp',"","1","","POINT","")

Hope this is helpful

Kishor

0 Kudos
NilsRatnaweera
New Contributor III

Thanks for your answer! Unfortunalty, the result ist the same. 49 Points, as expected, but all on top of each other with weird coordinates (9.85771519532085e-273 /1.02643732661912e-299 rather than somewhere around 600000 / 200000).

0 Kudos
KishorGhatage
Occasional Contributor III

Could you please run repair geometry on the Grid3b and then use Create random points. When I ran the repair geometry I found problem with 24 features in this file.

Result:

"WARNING 000986: C:\Users\.........Local\Temp\Grid3b0.txt contains the full list of non simple features.

WARNING 000461: Repaired feature 0 because of incorrect ring ordering, ...., ......, ......, ......  WARNING 000461: Repaired feature 24 because of incorrect ring ordering"

Regards

Kishor

NilsRatnaweera
New Contributor III

Indeed, the problem lies with an error in my shapefile! I drew the grid myself using an arcpy and pyshp and drew each square counterclockwise. Apperently, this only was a problem when I applied the random points tool. Thank you so much for the advice!

0 Kudos