python 创建要素类的随机样本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 创建要素类的随机样本相关的知识,希望对你有一定的参考价值。

import arcpy
import numpy as np

def randomFCSample(fc, fd='sample_fd', sample_field='OBJECTID', sample_pct=10):
  """Return a randomish sample of a feature class as a feature layer

    Parameters:
    fc (str): Input feature class to sample
    fd (str): Name of output feature layer
    sample_field (int): Numeric field to sample values from
    sample_pct (float): Percentage of feature class to sample  

    Returns:
    feature layer sample of input feature class

  """
  count_class = arcpy.GetCount_management(fc)
  count = int(count_class[0])
  random_vals = np.random.choice(count, int(count*(sample_pct/100)))
  arcpy.MakeFeatureLayer_management(fc,
                                    fd + "_" + str(sample_pct) + 'pct',
                                    sample_field + ' IN ' + str(tuple(random_vals))
                                    )

以上是关于python 创建要素类的随机样本的主要内容,如果未能解决你的问题,请参考以下文章

Python小案例:朴素贝叶斯分类器

在python中层次聚类的每一步打印所有聚类和样本

Python中的加权随机样本问题,怎么解决

ArcGIS微课1000例0006:创建随机点(Create Random Points)

ArcGIS微课1000例0006:创建随机点(Create Random Points)

现代信号处理01 -概率论与随机过程回顾