Create Random Points (Data Management)

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.

Learn more about how Create Random Points works

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.

Parameters

LabelExplanationData Type
Output Location

The location or workspace in which the random points feature class will be created. This location or workspace must already exist.

Feature Dataset;Workspace
Output Point Feature Class

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.

  • Current Display Extent Map View—The extent will be based on the active map or scene. This option is only available when there is an active map.
  • Draw Extent Square and Finish—The extent will be based on a rectangle drawn on the map or scene. This option will create a feature class in the project geodatabase and add a layer to the map. The feature class will have the same coordinate system as the map.
    Note:

    This option is not available in the Environments dialog box. It is only available from a tool parameter with an extent data type or from the Environments tab on a tool dialog box.

    Note:

    When the Enable and disable editing from the Edit tab editing option is checked, you must enable editing on the Edit ribbon tab to draw the extent.

  • Extent of a Layer Layer—The extent will be based on an active map layer. Use the drop-down list to choose an available layer or use the Extent of data in all layers option to get the combined extent of all active map layers, excluding the basemap. This option is only available when there is an active map with layers.

    Each map layer has the following options:

    • All Features Select All—The extent of all features in the layer.
    • Selected Features Area from Selected Features—The extent of the selected features in the layer.
    • Visible Features Extent Indicator—The extent of the visible features in the layer.
      Note:

      The extents from the Selected Features Area from Selected Features and Visible Features Extent Indicator options are only available for feature layers.

  • Browse Browse—The extent will be based on an existing dataset.
  • Clipboard Paste—The extent can be copied to and pasted from the clipboard.
    • Copy Extent Copy—Copies the extent coordinates and coordinate system to the clipboard.
    • Use Paste Extent Paste—Pastes the extent coordinates and, optionally, the coordinate system from the clipboard. If the clipboard values do not include a coordinate system, the extent will use the map’s coordinate system.
    Note:

    The extent coordinates are copied to and pasted from the clipboard using the same formatting and order as the ArcPy Extent object: x-min, y-min, x-max, y-max, and the spatial reference.

  • Reset Extent Reset—The extent will be reset to the default value.
  • Manually entered coordinates—The coordinates must be numeric values and in the active map's coordinate system.
    Caution:

    The map may use different display units than the entered coordinates. The use of a cardinal direction (N, S, E, W) is not supported. Use a negative value sign for south and west coordinates.

Extent; Feature Layer; Raster Layer
Number of Points [value 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 [value or field]
(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.

  • Unchecked—The output will be geometry type point (each point is a separate feature). This is the default.
  • Checked—The output will be geometry type multipoint (all points are a single feature).
Boolean
Maximum Number of Points per Multipoint
(Optional)

If Create Multipoint Output is checked, specify the number of random points to be placed in each multipoint geometry.

Long

Derived Output

LabelExplanationData Type
Output Feature Class

The output random points feature class.

Feature Class

arcpy.management.CreateRandomPoints(out_path, out_name, {constraining_feature_class}, {constraining_extent}, {number_of_points_or_field}, {minimum_allowed_distance}, {create_multipoint_output}, {multipoint_size})
NameExplanationData 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.

  • MAXOF—The maximum extent of all inputs will be used.
  • MINOF—The minimum area common to all inputs will be used.
  • DISPLAY—The extent is equal to the visible display.
  • Layer name—The extent of the specified layer will be used.
  • Extent object—The extent of the specified object will be used.
  • Space delimited string of coordinates—The extent of the specified string will be used. Coordinates are expressed in the order of x-min, y-min, x-max, y-max.
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.

  • POINTThe output will be geometry type point (each point is a separate feature). This is the default.
  • MULTIPOINTThe output will be geometry type multipoint (all points are a single 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

NameExplanationData 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.management.CreateRandomPoints("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.management.CreateRandomPoints(outGDB, outName, conFC, "", numField)

# set workspace
arcpy.env.workspace = "C:/data/county.gdb"

# Create fields for random values
fieldInt = "fieldInt"
fieldFlt = "fieldFlt"
arcpy.management.AddField(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.management.CalculateField(outName, fieldInt, "random.randint(1,100)", 
                                "PYTHON", "import random")
arcpy.management.CalculateField(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.management.CreateRandomPoints(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.management.CreateRandomPoints(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.management.CreateRandomPoints(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.management.CreateRandomPoints(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.management.CreateRandomPoints(outGDB, outName, "", fcExtent, numPoints, 
                                    "", "MULTIPOINT", numMP)

Related topics