Skip to content

Commit 4bdf80f

Browse files
authored
Merge pull request #182 from planetlabs/analytics_pagination_defaults
1.3.1. Features pagination tweaks
2 parents 556b270 + cc8cc81 commit 4bdf80f

File tree

5 files changed

+88
-19
lines changed

5 files changed

+88
-19
lines changed

CHANGES.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
1.3.1 (2019-07-19)
2+
-------------------------------------
3+
- Added default limit of 100 to `analytics collections features list`
4+
- Added separate `analytics collections features list-all` that will keep retrieving results with no limit
5+
- Added before, after options to both `analytics collections features list` and `analytics collections features list-all`
6+
17
1.3.0 (2019-07-10)
28
-------------------------------------
39
- Added support for Analytic Feeds
4-
510
- Fixing incorrect shorthand CLI arg
611
- Add comment to explain why the get resource entrypoint won't work in AF next.
7-
- bump version
812
- unit tests for analytics commands
913
- Adding auto-pagination for analytics commands
10-
- Misc fixup for flake8 and test dependencies
1114
- Add additional mosaics entrypoints to list mosaics for a series, as well mosaics for AF resources
1215
- Separate out analytics configuration to allow for using analytics alongside mosaics, even in AF next
13-
- Flesh out analytics CLI entrypoints and client funcs
14-
- Stub out analytics entrypoints
1516

1617
1.2.4 (2019-06-27)
1718
-------------------------------------

docs/source/cli/examples.rst

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,35 @@ List all mosaics associated with a feed, subscription, or collection (if the fee
142142
planet analytics subscriptions list-mosaics <subscription_id>
143143
planet analytics collections list-mosaics <collection_id or subscription_id>
144144

145-
Get all features (GeoJSON results) for a collection::
145+
Features (GeoJSON results) for a collection can be requested in one of two ways. The `list` option
146+
will only return slices of results (defaults to 100 at a time), whereas `list-all` will stream
147+
features until all features have been retrieved. Both options accept the same additional filters.
146148

147149
planet analytics collections features list <collection_id or subscription_id>
150+
planet analytics collections features list-all <collection_id or subscription_id>
148151

149-
Get the first 500 features (GeoJSON results) for a collection within a certain time range::
152+
To page through results when using `list`::
150153

151-
planet analytics collections features list <collection_id or subscription_id> --time-range 2019-01-01T00:00:00.00Z/2019-02-01T00:00:00.00Z --limit 500
154+
planet analytics collections features list <collection_id or subscription_id>
155+
planet analytics collections features list <collection_id or subscription_id> --before <feature_id_of_last_feature_in_previous_page>
156+
157+
Get the 10 most recent features (GeoJSON results) for a collection::
158+
159+
planet analytics collections features list <collection_id or subscription_id> --limit 10
160+
161+
Stream all features (GeoJSON results) since last seen feature::
162+
163+
planet analytics collections features list-all <collection_id or subscription_id> --after <feature_id>
164+
165+
Get features (GeoJSON results) for a collection within a certain time range::
166+
167+
planet analytics collections features list <collection_id or subscription_id> --time-range 2019-01-01T00:00:00.00Z/2019-02-01T00:00:00.00Z
168+
planet analytics collections features list-all <collection_id or subscription_id> --time-range 2019-01-01T00:00:00.00Z/2019-02-01T00:00:00.00Z
152169

153-
Get all features (GeoJSON results) for a collection within a certain area::
170+
Get features (GeoJSON results) for a collection within a certain area::
154171

155172
planet analytics collections features list <collection_id or subscription_id> --bbox 122.3,47.6,122.4,47.7
173+
planet analytics collections features list-all <collection_id or subscription_id> --bbox 122.3,47.6,122.4,47.7
156174

157175
It is also possible to get resources associated with a particular GeoJSON feature in a collection.
158176
Just as different feeds are based upon different imagery types and produce different types of

planet/api/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.3.0'
1+
__version__ = '1.3.1'

planet/api/client.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,22 +443,32 @@ def get_collection_info(self, subscription_id):
443443

444444
def list_collection_features(self,
445445
subscription_id,
446-
bbox,
447-
time_range,
446+
bbox=None,
447+
time_range=None,
448+
before=None,
449+
after=None,
448450
):
449451
'''
450452
List features for an analytic subscription.
451453
:param subscription_id:
452454
:param time_range str: ISO format datetime interval.
453455
:param bbox tuple: A lon_min, lat_min, lon_max, lat_max area to search
456+
:param before str: return features published before item with given ID
457+
:param after str: return features published after item with given ID
454458
:raises planet.api.exceptions.APIException: On API error.
455459
:returns: :py:Class:`planet.api.models.WFS3Features`
456460
'''
457-
params = {
458-
'time': time_range,
459-
}
461+
params = {}
462+
460463
if bbox:
461464
params['bbox'] = ','.join([str(b) for b in bbox])
465+
if time_range:
466+
params['time'] = time_range
467+
if before:
468+
params['before'] = before
469+
if after:
470+
params['after'] = after
471+
462472
url = self._url('collections/{}/items'.format(subscription_id))
463473
return self._get(url, models.WFS3Features, params=params).get_body()
464474

planet/scripts/v1.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,6 @@ def features():
571571

572572
@features.command('list')
573573
@click.argument('subscription_id')
574-
@limit_option(None)
575574
@click.option('--bbox', type=BoundingBox(), help=(
576575
'Region to query as a comma-delimited string:'
577576
' lon_min,lat_min,lon_max,lat_max'
@@ -585,15 +584,56 @@ def features():
585584
'items since the start of January 2019), 2019-01-01T00:00:00.00Z '
586585
'(instant)'
587586
))
587+
@click.option('--before', type=str, help=(
588+
'Get results published before the item with the provided ID.'
589+
))
590+
@click.option('--after', type=str, help=(
591+
'Get results published after the item with the provided ID.'
592+
))
593+
@limit_option(100)
588594
@pretty
589-
def list_features(subscription_id, pretty, limit, rbox, bbox, time_range):
590-
'''Request feature list for a particular subscription.'''
595+
def list_features(subscription_id, pretty, limit, rbox, bbox, time_range,
596+
before, after):
597+
'''Request feature list for a particular subscription, 100 at a time.'''
591598
cl = analytics_client_v1()
592599
bbox = bbox or rbox
593-
features = cl.list_collection_features(subscription_id, bbox, time_range)
600+
features = cl.list_collection_features(subscription_id, bbox, time_range,
601+
before, after)
594602
echo_json_response(features, pretty, limit)
595603

596604

605+
@features.command('list-all')
606+
@click.argument('subscription_id')
607+
@click.option('--bbox', type=BoundingBox(), help=(
608+
'Region to query as a comma-delimited string:'
609+
' lon_min,lat_min,lon_max,lat_max'
610+
))
611+
@click.option('--rbox', type=BoundingBox(), help='Alias for --bbox')
612+
@click.option('--time-range', type=DateInterval(), help=(
613+
'Time interval. Can be open or closed interval, start times are '
614+
'inclusive and end times are exclusive: '
615+
'2019-01-01T00:00:00.00Z/2019-02-01T00:00:00.00Z (Closed interval for '
616+
'January 2019), 2019-01-01T00:00:00.00Z/.. (Open interval for all '
617+
'items since the start of January 2019), 2019-01-01T00:00:00.00Z '
618+
'(instant)'
619+
))
620+
@click.option('--before', type=str, help=(
621+
'Get results published before the item with the provided ID.'
622+
))
623+
@click.option('--after', type=str, help=(
624+
'Get results published after the item with the provided ID.'
625+
))
626+
@pretty
627+
def list_features_all(subscription_id, pretty, rbox, bbox, time_range, before,
628+
after):
629+
'''Return every available feature for a particular subscription'''
630+
cl = analytics_client_v1()
631+
bbox = bbox or rbox
632+
features = cl.list_collection_features(subscription_id, bbox, time_range,
633+
before, after)
634+
echo_json_response(features, pretty)
635+
636+
597637
@features.command('get')
598638
@click.argument('resource_type', type=click.Choice(
599639
['source-image-info', 'target-quad', 'source-quad']))

0 commit comments

Comments
 (0)