创建随机点 (Data Management)

许可等级:BasicStandardAdvanced

摘要

创建指定数量的随机点要素。可以在范围窗口中、面要素内、点要素上或线要素沿线生成随机点。

了解有关“创建随机点”工作原理的详细信息

用法

语法

CreateRandomPoints_management (out_path, out_name, {constraining_feature_class}, {constraining_extent}, {number_of_points_or_field}, {minimum_allowed_distance}, {create_multipoint_output}, {multipoint_size})
参数说明数据类型
out_path

创建随机点要素类所要使用的位置或工作空间。此位置或工作空间必须已经存在。

Feature Dataset;Workspace
out_name

要创建的随机点要素类的名称。

String
constraining_feature_class
(可选)

将在此要素类中的要素的内部或沿线生成随机点。约束要素类可以是点、多点、线或面。 点将被随机放置在面要素内、线要素沿线或点要素位置处。此要素类中的每个要素内部都会生成指定数量的点(例如,如果您指定 100 个点且约束要素类中包含 5 个要素,则每个要素中会生成 100 个随机点,共生成 500 个点)。

Feature Layer
constraining_extent
(可选)

将在此范围内生成随机点。仅当未指定约束要素类时,才会使用约束范围。

Extent;Feature Layer;Raster Layer
number_of_points_or_field
(可选)

要随机生成的点的数量。

可将点数指定为长整型数值或指定为约束要素中的字段,其中约束要素需包含表示每个要素中要放置多少随机点的数值。此字段选项仅对面约束要素或线约束要素有效。如果点数以长整型数值的形式提供,则将在约束要素类中每个要素的内部或沿线生成该数量的随机点。

Field;Long
minimum_allowed_distance
(可选)

任意两个随机放置的点之间的最小允许距离。 如果将此距离值指定为 1 米,则所有随机点距最近点的距离都将大于 1 米。

Field;Linear unit
create_multipoint_output
(可选)

确定输出要素类是多部分要素还是单部分要素。

  • POINT输出的几何类型将为点(每个点均是独立要素)。这是默认设置。
  • MULTIPOINT输出的几何类型将为多点(所有点是一个要素)。
Boolean
multipoint_size
(可选)

如果使用“创建多点输出”选项(选中/MULTIPOINT),此参数用于指定每个多点几何中要放置的随机点的数量。

Long

代码实例

创建随机点 (CreateRandomPoints) 示例 1(Python 窗口)

以下 Python 窗口脚本演示了如何在即时模式下使用创建随机点 (CreateRandomPoints) 工具:

import arcpy
arcpy.CreateRandomPoints_management("c:/data/project", "samplepoints", "c:/data/studyarea.shp", "", 500, "", "POINT", "")
用随机值创建随机点 (CreateRandomPoints) 示例 2(独立 Python 脚本)

以下独立 Python 脚本演示了如何使用随机值创建随机点:

#Name: RandomPointsRandomValues.py
#Purpose: create random points with random values

# Import system modules
import arcpy, os, random
from arcpy import env

# 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
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) 示例 3(独立 Python 脚本)

以下独立 Python 脚本演示了使用创建随机点 (CreateRandomPoints) 工具的几种方法:

#Name: RandomPoints.py
#Purpose: create several types of random points feature classes

# Import system modules
import arcpy, os
from arcpy import env

#set environment settings
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"
env.outputCoordinateSystem = "Coordinate Systems/Projected Coordinate Systems/World/Miller Cylindrical (world).prj"
arcpy.CreateRandomPoints_management(outFolder, outName, "", numExtent, numPoints)
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)

环境

相关主题

许可信息

ArcGIS for Desktop Basic:需要 3D Analyst 或者Spatial Analyst
ArcGIS for Desktop Standard:需要 3D Analyst 或者Spatial Analyst
ArcGIS for Desktop Advanced:是
9/15/2013