Arcpy 随机选取部分要素并导出
Arcpy 随机选取部分要素并导出
# Import system modules import arcpy, os, time import random from arcpy import env print '程序开始:' + str(time.ctime()) # Set environment settings env.workspace = "D:\pythonlearint.gdb" # Set local variables inFeatures = "毕节市矢量图1228" fieldName1 = "RD" fieldPrecision = 9 fieldAlias = "随机数字" # Execute AddField arcpy.AddField_management(inFeatures, fieldName1, "DOUBLE", fieldPrecision, "", "", fieldAlias, "NULLABLE") field1 = "RD" cursor = arcpy.UpdateCursor(inFeatures) for row in cursor: # 随机赋值 row.setValue(field1, random.random()) cursor.updateRow(row) #导出选择的数据集 arcpy.MakeFeatureLayer_management(inFeatures, "lyr") arcpy.SelectLayerByAttribute_management("lyr", "NEW_SELECTION", ' "RD" < 0.05 ') # Write the selected features to a new featureclass arcpy.CopyFeatures_management("lyr", "RD_Train") print '程序结束:' + str(time.ctime()) --------------------- 作者:刘金榜 来源:CSDN 原文:https://blog.csdn.net/sprintwater/article/details/26239691 版权声明:本文为博主原创文章,转载请附上博文链接!