Ejemplo n.º 1
0
 def extract_spectra(self, description_field='', verbose=True):
     u"""
     Extract spectra from source imagery and creates well-defined spectrum
     objects.
     """
     # extracting spectra as simple lists
     spectra = gdal_utils.extract_spectra(self.img_src,
                                          self.extract_locations,
                                          neighborhood=self.neighborhood,
                                          verbose=verbose,
                                          bad_bands=self.bad_bands,
                                          scale_factor=self.slope,
                                          nb_type=self.neighborhood_type)
     # converting lists to spectrum objects
     # defining list of all extracted spectra
     # iterating over location/spectrum pairs
     for cp, sp in zip(self.extract_locations, spectra):
         # retrieving location id
         if cp.has_key('attributes'):
             additional_attributes = cp['attributes'].keys()
             additional_attributes.remove(self.loc_id_field)
         loc_id = cp[self.loc_id_field]
         # creating new spectrum object using location id and according coordinates
         spectrum = Spectrum(loc_id, (cp['x'], cp['y']))
         for aa in additional_attributes:
             spectrum.set_attribute(aa, cp['attributes'][aa])
         spectrum.set_neighborhood(self.neighborhood)
         spectrum.set_neighborhood_type(self.neighborhood_type)
         spectrum.set_source(self.img_id)
         if description_field:
             spectrum.set_description(cp[description_field])
         # adding values to spectrum
         for gb, val in zip(self.good_bands, sp):
             spectrum.set_value(gb, val)
         # adding values of bad bands to spectrum
         for bb in self.bad_bands:
             spectrum.set_invalid(bb)
         # adding current spectrum to list of all extracted spectra
         self.spectra.append(spectrum)
Ejemplo n.º 2
0
 def extract_spectra(self, description_field = '', verbose = True):
     u"""
     Extract spectra from source imagery and creates well-defined spectrum
     objects.
     """
     # extracting spectra as simple lists
     spectra = gdal_utils.extract_spectra(self.img_src, self.extract_locations,
                                          neighborhood = self.neighborhood,
                                          verbose = verbose, bad_bands = self.bad_bands,
                                          scale_factor = self.slope, nb_type = self.neighborhood_type)
     # converting lists to spectrum objects
     # defining list of all extracted spectra
     # iterating over location/spectrum pairs
     for cp, sp in zip(self.extract_locations, spectra):
         # retrieving location id
         if cp.has_key('attributes'):
             additional_attributes = cp['attributes'].keys()
             additional_attributes.remove(self.loc_id_field)
         loc_id = cp[self.loc_id_field]
         # creating new spectrum object using location id and according coordinates
         spectrum = Spectrum(loc_id, (cp['x'], cp['y']))
         for aa in additional_attributes:
             spectrum.set_attribute(aa, cp['attributes'][aa])
         spectrum.set_neighborhood(self.neighborhood)
         spectrum.set_neighborhood_type(self.neighborhood_type)
         spectrum.set_source(self.img_id)
         if description_field:
             spectrum.set_description(cp[description_field])
         # adding values to spectrum
         for gb, val in zip(self.good_bands, sp):
             spectrum.set_value(gb, val)
         # adding values of bad bands to spectrum
         for bb in self.bad_bands:
             spectrum.set_invalid(bb)
         # adding current spectrum to list of all extracted spectra
         self.spectra.append(spectrum)