How to use the planet.api.filters function in planet

To help you get started, we’ve selected a few planet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github planetlabs / planet-client-python / tests / test_filters.py View on Github external
def test_date_range(dt, expected):
    fieldname = "acquired"
    arg = "gte"

    assert filters.date_range(fieldname, **{arg: dt}) == expected
github yghlc / Landuse_DL / planetScripts / autoDownload_PlanetImg.py View on Github external
def get_items_count(combined_filter, item_types):

    req = filters.build_search_request(combined_filter, item_types, interval="year") #year  or day
    stats = client.stats(req).get()
    # p(stats)
    total_count = 0
    for bucket in stats['buckets']:
        total_count += bucket['count']
    return total_count
github yghlc / Landuse_DL / planetScripts / autoDownload_PlanetImg.py View on Github external
def get_a_filter_cli_api(polygon_json,start_date, end_date, could_cover_thr):

    geo_filter = filters.geom_filter(polygon_json)
    date_filter = filters.date_range('acquired', gte=start_date, lte = end_date)
    cloud_filter = filters.range_filter('cloud_cover', lte=could_cover_thr)

    combined_filters = filters.and_filter(geo_filter, date_filter, cloud_filter)

    return combined_filters
github yghlc / Landuse_DL / planetScripts / download_planet_img.py View on Github external
'''
    create a filter based on a geometry, date range, cloud cover
    :param polygon_json: a polygon in json format
    :param start_date: start date
    :param end_date:  end date
    :param could_cover_thr: images with cloud cover less than this value
    :return:  a combined filter (and filter)
    '''

    # gt: Greater Than
    # gte: Greater Than or Equal To
    # lt: Less Than
    # lte: Less Than or Equal To

    geo_filter = filters.geom_filter(polygon_json)
    date_filter = filters.date_range('acquired', gte=start_date, lte = end_date)
    cloud_filter = filters.range_filter('cloud_cover', lte=could_cover_thr)

    combined_filters = filters.and_filter(geo_filter, date_filter, cloud_filter)

    return combined_filters
github planetlabs / planet-client-python / planet / scripts / types.py View on Github external
def convert(self, val, param, ctx):
        val = read(val)
        if not val:
            return []
        try:
            filt = json.loads(val)
        except ValueError:
            raise click.BadParameter('invalid JSON')
        if not filters.is_filter_like(filt):
            self.fail('Does not appear to be valid filter', param, ctx)
        return filt
github planetlabs / planet-client-python / planet / scripts / util.py View on Github external
def and_filter_from_opts(opts):
    '''build an AND filter from the provided opts dict as passed to a command
    from the filter_options decorator. Assumes all dict values are lists of
    filter dict constructs.'''
    return filters.and_filter(*list(chain.from_iterable([
        o for o in opts.values() if o]
    )))
github planetlabs / planet-client-python / planet / scripts / util.py View on Github external
def search_req_from_opts(**kw):
    # item_type will be list of lists - flatten
    item_types = chain.from_iterable(kw.pop('item_type'))
    name = kw.pop('name', '')
    interval = kw.pop('interval', '')
    filt = filter_from_opts(**kw)
    return filters.build_search_request(
        filt, item_types, name=name, interval=interval)
github planetlabs / planet-client-python / planet / scripts / types.py View on Github external
def convert(self, val, param, ctx):
        val = read(val)
        if not val:
            return []
        try:
            geoj = json.loads(val)
        except ValueError:
            raise click.BadParameter('invalid GeoJSON')
        geom = geometry_from_json(geoj)
        if geom is None:
            raise click.BadParameter('unable to find geometry in input')
        return [filters.geom_filter(geom)]