original_docstring:  Create a clipped training set from polygon shapefiles.
  
          This complicated-looking function finds the wrs_2 descending Landsat tile corresponding
          to the path row provided, gets the bounding box and profile (aka meta) from
          compose_array.get_tile_geometry, clips the training data to the landsat tile, then performs a
          union to reduce the number of polygon objects.
  
          The dict object this uses has a template in pixel_classification.runspec.py.
  
          Approach is to loop through the polygons, create a random grid of points over the extent of
          each polygon, random shuffle order of points, loop over points, check if point is within polygon,
          and if within, create a sample point.
  
          If a relatively simple geometry is available, use create_negative_sample_points(), though if
          there ar > 10**4 polygons, it will probably hang on unary_union().
  
          
docstring: Create a clipped training set from polygon shapefiles.
  This complicated-looking function finds the wrs_2 descending Landsat tile corresponding
  to the path row provided, gets the bounding box and profile (aka meta) from
  compose_array.get_tile_geometry, clips the training data to the landsat tile, then performs a
  union to reduce the number of polygon objects.
  
  The dict object this uses has a template in pixel_classification.runspec.py.
  
  Approach is to loop through the polygons, create a random grid of points over the extent of
  each polygon, random shuffle order of points, loop over points, check if point is within polygon,
  and if within, create a sample point.
  
  If a relatively simple geometry is available, use create_negative_sample_points(), though if
  there ar > 10**4 polygons, it will probably hang on unary_union().
docstring_tokens: Create a clipped training set from polygon shapefiles . This complicated - looking function finds the wrs_2 descending Landsat tile corresponding to the path row provided gets the bounding box and profile ( aka meta ) from compose_array . get_tile_geometry clips the training data to the landsat tile then performs a union to reduce the number of polygon objects . The dict object this uses has a template in pixel_classification . runspec . py . Approach is to loop through the polygons create a random grid of points over the extent of each polygon random shuffle order of points loop over points check if point is within polygon and if within create a sample point . If a relatively simple geometry is available use create_negative_sample_points () though if there ar > 10 ** 4 polygons it will probably hang on unary_union () .
code: def create_sample_points(self):
          """ Create a clipped training set from polygon shapefiles.
  
          This complicated-looking function finds the wrs_2 descending Landsat tile corresponding
          to the path row provided, gets the bounding box and profile (aka meta) from
          compose_array.get_tile_geometry, clips the training data to the landsat tile, then performs a
          union to reduce the number of polygon objects.
  
          The dict object this uses has a template in pixel_classification.runspec.py.
  
          Approach is to loop through the polygons, create a random grid of points over the extent of
          each polygon, random shuffle order of points, loop over points, check if point is within polygon,
          and if within, create a sample point.
  
          If a relatively simple geometry is available, use create_negative_sample_points(), though if
          there ar > 10**4 polygons, it will probably hang on unary_union().
  
          """
  
          for class_code, _dict in self.geography.attributes.items():
              print(_dict['ltype'])
              polygons = self._get_polygons(_dict['path']) # this is a hardcoded shapefile name.
              _dict['instance_count'] = 0
  
              if len(polygons) > self.m_instances:
                  areas = zip(polygons, [x.area for x in polygons])
                  srt = sorted(areas, key=lambda x: x[1], reverse=True)
                  polygons = [x for x, y in srt[:self.m_instances]]
  
              polygons = unary_union(polygons)
              positive_area = sum([x.area for x in polygons])
              class_count = 0
  
              for i, poly in enumerate(polygons):
                  if class_count >= self.m_instances:
                      break
                  fractional_area = poly.area / positive_area
                  required_points = max([1, fractional_area * self.m_instances])
                  x_range, y_range = self._random_points(poly.bounds)
                  poly_pt_ct = 0
  
                  for coord in zip(x_range, y_range):
                      if Point(coord[0], coord[1]).within(poly):
                          self._add_entry(coord, val=class_code)
                          poly_pt_ct += 1
                          _dict['instance_count'] += 1
  
                      if _dict['instance_count'] > self.m_instances:
                          break
  
                      if poly_pt_ct >= required_points:
                          break
  
                  class_count += poly_pt_ct
code_tokens: def create_sample_points ( self ) : for class_code , _dict in self . geography . attributes . items ( ) : print ( _dict [ 'ltype' ] ) polygons = self . _get_polygons ( _dict [ 'path' ] ) _dict [ 'instance_count' ] = 0 if len ( polygons ) > self . m_instances : areas = zip ( polygons , [ x . area for x in polygons ] ) srt = sorted ( areas , key = lambda x : x [ 1 ] , reverse = True ) polygons = [ x for x , y in srt [ : self . m_instances ] ] polygons = unary_union ( polygons ) positive_area = sum ( [ x . area for x in polygons ] ) class_count = 0 for i , poly in enumerate ( polygons ) : if class_count >= self . m_instances : break fractional_area = poly . area / positive_area required_points = max ( [ 1 , fractional_area * self . m_instances ] ) x_range , y_range = self . _random_points ( poly . bounds ) poly_pt_ct = 0 for coord in zip ( x_range , y_range ) : if Point ( coord [ 0 ] , coord [ 1 ] ) . within ( poly ) : self . _add_entry ( coord , val = class_code ) poly_pt_ct += 1 _dict [ 'instance_count' ] += 1 if _dict [ 'instance_count' ] > self . m_instances : break if poly_pt_ct >= required_points : break class_count += poly_pt_ct
short_docstring: Create a clipped training set from polygon shapefiles.
short_docstring_tokens: Create a clipped training set from polygon shapefiles .
comment: """ Create a clipped training set from polygon shapefiles.
  
          This complicated-looking function finds the wrs_2 descending Landsat tile corresponding
          to the path row provided, gets the bounding box and profile (aka meta) from
          compose_array.get_tile_geometry, clips the training data to the landsat tile, then performs a
          union to reduce the number of polygon objects.
  
          The dict object this uses has a template in pixel_classification.runspec.py.
  
          Approach is to loop through the polygons, create a random grid of points over the extent of
          each polygon, random shuffle order of points, loop over points, check if point is within polygon,
          and if within, create a sample point.
  
          If a relatively simple geometry is available, use create_negative_sample_points(), though if
          there ar > 10**4 polygons, it will probably hang on unary_union().
  
          """$SEP$# this is a hardcoded shapefile name.