首页 > 解决方案 > 从 shapefile 边界生成随机点

问题描述

这是我的困境。我真的希望有人能尽快提供帮助!在 shapefile 的边界内生成 150 个随机点,这些点也相距 1000 米

这是我尝试过的:

import arcpy, random, os
outGDB = 'E:\Python\week_4\week_4_topost\data\example_data.gdb'
numPoints = 150
minDistance = "1000 Meters"
outName = "testpoints.shp"
conFC = "Cache.shp"
arcpy.CreateRandomPoints_management(outGDB, outName, conFC, "", numPoints, minDistance)

这是我的错误信息:

ExecuteError                              Traceback (most recent call last)
<ipython-input-65-e5cc74ba6ed5> in <module>()
      5 outName = "testpoints.shp"
      6 conFC = "Cache.shp"
----> 7 arcpy.CreateRandomPoints_management(outGDB, outName, conFC, "", numPoints, minDistance)

C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\management.py in CreateRandomPoints(out_path, out_name, constraining_feature_class, constraining_extent, number_of_points_or_field, minimum_allowed_distance, create_multipoint_output, multipoint_size)
  17530         return retval
  17531     except Exception as e:
> 17532         raise e
  17533 
  17534 @gptooldoc('GeneratePointsAlongLines_management', None)

ExecuteError: ERROR 000354: The name contains invalid characters
Failed to execute (CreateRandomPoints).

我也一直在使用这个链接一段时间试图弄清楚但没有用。

标签: shapefileesriarcpy

解决方案


我想到了!我需要添加工作区行并对代码进行一些较小的修改,使其看起来像这样

output_gdb = r'E:\Python\week_4\week_4_topost\data\example_data.gdb'
arcpy.env.workspace = output_gdb
print output_gdb
boundary = 'Cache'
output_location = arcpy.CreateRandomPoints_management(output_gdb, 'Random_Points', boundary, None, 150, "1 Kilometer")

推荐阅读