Summary
Creates a specified number of random point features. Random points can be generated in an extent window, inside polygon features, on point features, or along line features.
Usage
The area in which random points will be generated can be defined either by constraining polygon, point, or line features or by a constraining extent window.
The Number of Points parameter can be specified as a number or as a numeric field in the constraining feature class containing values for how many random points to place within each feature. The field option is only valid for polygon or line constraining features. If the number of points is supplied as a number, each feature in the constraining feature class will have that number of random points generated inside or along it.
If you are using a constraining feature class that has more than one feature, and you wish to specify the total number of random points to be generated (as opposed to the number of random points to be placed inside each feature), first use the Dissolve tool so that the constraining feature class only contains a single feature; then use that dissolved feature class as the constraining feature class.
The coordinate system of the output feature class will be the coordinate system of the
- Constraining feature class if one is specified
- Map data frame if a constraining extent is specified in the map using a layer in the map or the path to a feature class
- Feature class if a constraining extent is specified in Python by using the path to a feature class
- Output Coordinate System geoprocessing environment if it is set (and overrides all other behaviors detailed above)
- Unknown if none of the above applies
To assign random values to randomly placed points, first generate random points using this tool. Second, use the Add Field tool to create a new numeric field in the random points feature class. Suggested field types are long integer or float. Third, use the Calculate Field tool to assign random values to the empty field in the random points feature class. To generate a random integer between a and b (inclusively), use the Python expression random.randint(a,b). To generate a random float number between a and b (exclusively), use the Python expression random.uniform(a,b). In the code block, import the random module using the expression import random.
The Constraining Extent parameter can be entered as a set of minimum and maximum x- and y-coordinates or as equal to the extent of a feature layer or feature class.
If both a constraining feature class and constraining extent are specified, the constraining feature class value will be used and the constraining extent value will be ignored.
When unable to place anymore random points within a constraining area without breaking the minimum allowed distance specified, the number of random points in the constraining area will be reduced to the maximum possible under the minimum allowed distance.
The Minimum Allowed Distance parameter can be specified as a linear unit or a field from the constraining features containing numeric values. This value will determine the minimum allowed distance between random points within each input feature. The field option is only valid for polygon or line constraining features. Random points may be within the minimum allowed distance if they were generated inside or along different constraining feature parts.
Using point features as the constraining feature class creates a random subset of the constraining point features. No new point locations are generated.
Noninteger (whole) positive values for the Number of Points and Minimum Allowed Distance parameters will be rounded to the nearest whole number. Nonnumeric and negative values are set to 0.
Syntax
CreateRandomPoints(out_path, out_name, {constraining_feature_class}, {constraining_extent}, {number_of_points_or_field}, {minimum_allowed_distance}, {create_multipoint_output}, {multipoint_size})
Parameter | Explanation | Data Type |
out_path | The location or workspace in which the random points feature class will be created. This location or workspace must already exist. | Feature Dataset;Workspace |
out_name | The name of the random points feature class to be created. | String |
constraining_feature_class (Optional) | Random points will be generated inside or along the features in this feature class. The constraining feature class can be point, multipoint, line, or polygon. Points will be randomly placed inside polygon features, along line features, or at point feature locations. Each feature in this feature class will have the specified number of points generated inside it (for example, if you specify 100 points, and the constraining feature class has 5 features, 100 random points will be generated in each feature, totaling 500 points). | Feature Layer |
constraining_extent (Optional) | Random points will be generated inside the extent. The constraining extent will only be used if no constraining feature class is specified. | Extent;Feature Layer;Raster Layer |
number_of_points_or_field (Optional) | The number of points to be randomly generated. The number of points can be specified as a long integer number or as a field from the constraining features containing numeric values for how many random points to place within each feature. The field option is only valid for polygon or line constraining features. If the number of points is supplied as a long integer number, each feature in the constraining feature class will have that number of random points generated inside or along it. | Field; Long |
minimum_allowed_distance (Optional) | The shortest distance allowed between any two randomly placed points. If a value of 1 Meter is specified, all random points will be farther than 1 meter away from the closest point. | Field;Linear unit |
create_multipoint_output (Optional) | Determines if the output feature class will be a multipart or single-part feature.
| Boolean |
multipoint_size (Optional) | If create_multipoint_output is set to MULTIPOINT, specify the number of random points to be placed in each multipoint geometry. The default is 10. | Long |
Derived Output
Name | Explanation | Data Type |
out_feature_class | The output random points feature class. | Feature Class |
Code sample
CreateRandomPoints example 1 (Python window)
The following Python window script demonstrates how to use the CreateRandomPoints tool in immediate mode.
import arcpy
arcpy.CreateRandomPoints_management("c:/data/project", "samplepoints", "c:/data/studyarea.shp", "", 500, "", "POINT")
CreateRandomPoints example 2 (stand-alone script)
The following stand-alone Python script demonstrates how to create random points with random values.
# Name: RandomPointsRandomValues.py
# Purpose: create random points with random values
# Import system modules
import arcpy
# Create random points in the features of a constraining feature class
# Number of points for each feature determined by the value in the field specified
outGDB = "C:/data/county.gdb"
outName = "randpeople"
conFC = "C:/data/county.gdb/blocks"
numField = "POP2000"
arcpy.CreateRandomPoints_management(outGDB, outName, conFC, "", numField)
# set workspace
arcpy.env.workspace = "C:/data/county.gdb"
# Create fields for random values
fieldInt = "fieldInt"
fieldFlt = "fieldFlt"
arcpy.AddField_management(outName, fieldInt, "LONG") # add long integer field
arcpy.AddField_management(outName, fieldFlt, "FLOAT") # add float field
# Calculate random values between 1-100 in the new fields
arcpy.CalculateField_management(outName, fieldInt, "random.randint(1,100)", "PYTHON", "import random")
arcpy.CalculateField_management(outName, fieldFlt, "random.uniform(1,100)", "PYTHON", "import random")
CreateRandomPoints example 3 (stand-alone script)
The following stand-alone Python script demonstrates several methods to use the CreateRandomPoints tool.
# Name: RandomPoints.py
# Purpose: create several types of random points feature classes
# Import system modules
import arcpy
# set environment settings
arcpy.env.overWriteOutput = True
# Create random points in an extent defined simply by numbers
outFolder = "C:/data"
numExtent = "0 0 1000 1000"
numPoints = 100
outName = "myRandPnts.shp"
arcpy.env.outputCoordinateSystem = "Coordinate Systems/Projected Coordinate Systems/World/Miller Cylindrical (world).prj"
arcpy.CreateRandomPoints_management(outFolder, outName, "", numExtent, numPoints)
arcpy.env.outputCoordinateSystem = ""
# Create random points in an extent defined by another feature class
outName = "testpoints.shp"
fcExtent = "C:/data/studyarea.shp"
arcpy.CreateRandomPoints_management(outFolder, outName, "", fcExtent, numPoints)
# Create random points in the features of a constraining feature class
# Number of points for each feature determined by the value in the field specified
outGDB = "C:/data/county.gdb"
outName = "randpeople"
conFC = "C:/data/county.gdb/blocks"
numField = "POP2000"
arcpy.CreateRandomPoints_management(outGDB, outName, conFC, "", numField)
#create random points in the features of a constraining
#feature class with a minimum allowed distance
outName = "constparcelpnts"
conFC = "C:/data/county.gdb/parcels"
numPoints = 10
minDistance = "5 Feet"
arcpy.CreateRandomPoints_management(outGDB, outName, conFC, "", numPoints, minDistance)
#Create random points with a multipoint output
outName = "randomMPs"
fcExtent = "C:/data/county.gdb/county"
numPoints = 100
numMP = 10
arcpy.CreateRandomPoints_management(outGDB, outName, "", fcExtent, numPoints, "", "MULTIPOINT", numMP)
Environments
Licensing information
- Basic: Requires 3D Analyst or Spatial Analyst
- Standard: Requires 3D Analyst or Spatial Analyst
- Advanced: Yes