shapefile - 从 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).
我也一直在使用这个链接一段时间试图弄清楚但没有用。
解决方案
我想到了!我需要添加工作区行并对代码进行一些较小的修改,使其看起来像这样
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")
推荐阅读
- node.js - 如何在 index.js 文件中获取文档 ID 以进行推送通知颤动?
- c++ - 在 Ubuntu 20.04 LTS 上查找 Qt5 时 CMake find_package 失败 - cmake 版本不匹配
- ruby-on-rails - ROR:参数数量错误(给定 2,预期 1)
- html - 引导程序中的导航栏列表对齐问题
- scala - 如何在 Scala 中实现 Levenshtein 距离算法
- angular - Angular routerLink 什么都不做并重定向到主页
- node.js - 不使用 await 异步函数的性能问题
- java - JPA - 辅助表映射方向
- class - 如何处理需要彼此工作的类?
- python - 如何使用 Elementtree python 删除结束标签?