从shapfile边界生成随机点

问题描述 投票:0回答:1

这是我的困境。我真的希望有人能尽快提供帮助!在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)

here is my error message

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).

而且我一直在使用this link试图弄清楚它,但没有用。

shapefile esri arcpy
1个回答
0
投票

我想通了!我需要添加工作区行并对代码进行一些较小的修改,因此它应该看起来像这样

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")
© www.soinside.com 2019 - 2024. All rights reserved.