Exemple #1
0
 def retrieve_sample_locations(self, loc_id_field, additional_attributes = []):
     u"""
     Retrieve sampling locations by using the specified attribute in the
     previously defined location data source.
     """
     self.loc_id_field = loc_id_field
     # handling location data source
     self.loc_ds = ogr.Open(self.loc_src)
     self.loc_ly = self.loc_ds.GetLayer(0)
     # caching locations
     self.cached_locations = ogr_utils.cache_locations(self.loc_ly, [self.loc_id_field] + additional_attributes)
     self.cached_locations = sorted(self.cached_locations, key = itemgetter('attributes'))
Exemple #2
0
 def retrieve_sample_locations(self,
                               loc_id_field,
                               additional_attributes=[]):
     u"""
     Retrieve sampling locations by using the specified attribute in the
     previously defined location data source.
     """
     self.loc_id_field = loc_id_field
     # handling location data source
     self.loc_ds = ogr.Open(self.loc_src)
     self.loc_ly = self.loc_ds.GetLayer(0)
     # caching locations
     self.cached_locations = ogr_utils.cache_locations(
         self.loc_ly, [self.loc_id_field] + additional_attributes)
     self.cached_locations = sorted(self.cached_locations,
                                    key=itemgetter('attributes'))
Exemple #3
0
    except:
        bad_bands = list()

    # building an image data dictionary using strip ids as keys
    image_data = dict()
    # list of all available strip ids
    available_strips = list()
    for f in image_data_files:
        strip_id = int(re.search("_(\d)_", f).group(1))
        available_strips.append(strip_id)
        image_data[strip_id] = f
    # retrieving plots
    plt_ds = ogr.Open(plt_shp_src)
    plt_ly = plt_ds.GetLayer(0)
    # caching plots
    cached_plots = ogr_utils.cache_locations(plt_ly, ['plot_id'])

    # setting up output
    output = list()

    # iterating over a selection of strip ids
    for strip_id in available_strips:
        # retrieving band count
        band_count = gdal_utils.get_band_count(image_data[strip_id])
        # retrieving good bands by calculating the difference between all
        # bands and those that have been declared bad
        good_bands = list(set(range(1, band_count + 1)).difference(bad_bands))

        tgt_file = "".join(
            (re.search("(.+)_\d_",
                       os.path.basename(image_data[strip_id])).group(1),
    except:
        bad_bands = list()

    # building an image data dictionary using strip ids as keys
    image_data = dict()
    # list of all available strip ids
    available_strips = list()
    for f in image_data_files:
        strip_id = int(re.search("_(\d)_", f).group(1))
        available_strips.append(strip_id)
        image_data[strip_id] = f
    # retrieving plots
    plt_ds = ogr.Open(plt_shp_src)
    plt_ly = plt_ds.GetLayer(0)
    # caching plots
    cached_plots = ogr_utils.cache_locations(plt_ly, ['plot_id'])

    # setting up output
    output = list()
    
    # iterating over a selection of strip ids
    for strip_id in available_strips:
        # retrieving band count
        band_count = gdal_utils.get_band_count(image_data[strip_id])
        # retrieving good bands by calculating the difference between all 
        # bands and those that have been declared bad
        good_bands = list(set(range(1, band_count + 1)).difference(bad_bands))

        tgt_file = "".join((re.search("(.+)_\d_", os.path.basename(image_data[strip_id])).group(1), '_spectra.txt'))

        # setting up a list of plots that are linked with the current strip
Exemple #5
0
    cov_dir = r"D:\work\ms.monina\wp5\wahner_heide\2011-09-14_apex\coverage"
    #cov_dir = r"D:\work\ms.monina\wp5\wahner_heide\2009-08-06_hymap\coverage"    
    #cov_dir = r"D:\work\ms.monina\wp5\wahner_heide\2011-08-02_worldview\coverage"

    plot_id_name = 'plot_id'
    plot_id_name = 'pnt_id'
    #plot_id_name = 'ID'
    #plot_id_name = 'NUMMER'

    img_extension = '*.tif'

    # reading plots from vector dataset
    plt_ds = ogr.Open(plt_src)
    plt_ly = plt_ds.GetLayer(0)
    # caching plots to prepare raster data extraction
    cached_plots = ogr_utils.cache_locations(plt_ly, [plot_id_name])

    coverages = dict()

    # iterating over all images in coverage directory
    for img in glob.glob(os.path.join(cov_dir, img_extension)):
        print "+ Checking for plot availability in dataset '%s'..." % os.path.basename(img),
        # checking plot coverage for current GeoTiff
        cov = check_coverage(img, cached_plots, 2, plot_id_name)
        coverages[os.path.basename(img)] = cov
        print "Done"

    # iterating over all plot ids
    for cp in sorted(cached_plots, key = itemgetter('attributes')):
        plot_id = cp['attributes'][plot_id_name]
        line = list()