arcpy创建随机点,生成shp的代码
时间: 2024-03-14 14:47:58 浏览: 142
以下是使用ArcPy创建随机点并生成shapefile的示例代码:
```
import arcpy
import random
# 设置工作空间和输出路径
arcpy.env.workspace = r"C:\data"
out_path = r"C:\output"
# 定义输出要素类名称和坐标系
out_name = "random_points.shp"
spatial_reference = arcpy.SpatialReference(4326) # WGS 1984坐标系
# 定义随机点数量和范围
num_points = 1000
x_min, y_min, x_max, y_max = -180, -90, 180, 90
# 创建空要素类
arcpy.CreateFeatureclass_management(out_path, out_name, "POINT", spatial_reference=spatial_reference)
# 添加点要素
with arcpy.da.InsertCursor(out_path + "\\" + out_name, ["SHAPE@XY"]) as cursor:
for i in range(num_points):
x = random.uniform(x_min, x_max)
y = random.uniform(y_min, y_max)
cursor.insertRow([(x, y)])
```
以上代码将创建一个名为`random_points.shp`的空shapefile,并在其中生成1000个随机点。随机点的范围为经度-180到180,纬度-90到90。最后,使用`InsertCursor`将随机点添加到空shapefile中。
阅读全文
相关推荐













