|
23 | 23 |
|
24 | 24 | class _Base(object): |
25 | 25 | '''High-level access to Planet's API.''' |
| 26 | + |
26 | 27 | def __init__(self, api_key=None, base_url='https://api.planet.com/', |
27 | 28 | workers=4): |
28 | 29 | ''' |
@@ -272,13 +273,30 @@ def get_assets_by_id(self, item_type, id): |
272 | 273 | url = 'data/v1/item-types/%s/items/%s/assets' % (item_type, id) |
273 | 274 | return self._get(url).get_body() |
274 | 275 |
|
275 | | - def get_mosaics(self): |
| 276 | + def get_mosaic_series(self, series_id): |
| 277 | + '''Get information pertaining to a mosaics series |
| 278 | + :returns: :py:Class:`planet.api.models.JSON` |
| 279 | + ''' |
| 280 | + url = self._url('basemaps/v1/series/{}'.format(series_id)) |
| 281 | + return self._get(url, models.JSON).get_body() |
| 282 | + |
| 283 | + def get_mosaics_for_series(self, series_id): |
| 284 | + '''Get list of mosaics available for a series |
| 285 | + :returns: :py:Class:`planet.api.models.Mosaics` |
| 286 | + ''' |
| 287 | + url = self._url('basemaps/v1/series/{}/mosaics'.format(series_id)) |
| 288 | + return self._get(url, models.Mosaics).get_body() |
| 289 | + |
| 290 | + def get_mosaics(self, name_contains=None): |
276 | 291 | '''Get information for all mosaics accessible by the current user. |
277 | 292 |
|
278 | 293 | :returns: :py:Class:`planet.api.models.Mosaics` |
279 | 294 | ''' |
| 295 | + params = {} |
| 296 | + if name_contains: |
| 297 | + params['name__contains'] = name_contains |
280 | 298 | url = self._url('basemaps/v1/mosaics') |
281 | | - return self._get(url, models.Mosaics).get_body() |
| 299 | + return self._get(url, models.Mosaics, params=params).get_body() |
282 | 300 |
|
283 | 301 | def get_mosaic_by_name(self, name): |
284 | 302 | '''Get the API representation of a mosaic by name. |
@@ -344,3 +362,126 @@ def download_quad(self, quad, callback=None): |
344 | 362 | ''' |
345 | 363 | download_url = quad['_links']['download'] |
346 | 364 | return self._get(download_url, models.Body, callback=callback) |
| 365 | + |
| 366 | + def check_analytics_connection(self): |
| 367 | + ''' |
| 368 | + Validate that we can use the Analytics API. Useful to test connectivity |
| 369 | + to test environments. |
| 370 | + :returns: :py:Class:`planet.api.models.JSON` |
| 371 | + ''' |
| 372 | + return self._get(self._url('health')).get_body() |
| 373 | + |
| 374 | + def wfs_conformance(self): |
| 375 | + ''' |
| 376 | + Details about WFS3 conformance |
| 377 | + :returns: :py:Class:`planet.api.models.JSON` |
| 378 | + ''' |
| 379 | + return self._get(self._url('conformance')).get_body() |
| 380 | + |
| 381 | + def list_analytic_subscriptions(self, feed_id): |
| 382 | + ''' |
| 383 | + Get subscriptions that the authenticated user has access to |
| 384 | + :param feed_id str: Return subscriptions associated with a particular |
| 385 | + feed only. |
| 386 | + :raises planet.api.exceptions.APIException: On API error. |
| 387 | + :returns: :py:Class:`planet.api.models.Subscriptions` |
| 388 | + ''' |
| 389 | + params = {'feedID': feed_id} |
| 390 | + url = self._url('subscriptions') |
| 391 | + return self._get(url, models.Subscriptions, params=params).get_body() |
| 392 | + |
| 393 | + def get_subscription_info(self, subscription_id): |
| 394 | + ''' |
| 395 | + Get the information describing a specific subscription. |
| 396 | + :param subscription_id: |
| 397 | + :raises planet.api.exceptions.APIException: On API error. |
| 398 | + :returns: :py:Class:`planet.api.models.JSON` |
| 399 | + ''' |
| 400 | + url = self._url('subscriptions/{}'.format(subscription_id)) |
| 401 | + return self._get(url, models.JSON).get_body() |
| 402 | + |
| 403 | + def list_analytic_feeds(self, stats): |
| 404 | + ''' |
| 405 | + Get collections that the authenticated user has access to |
| 406 | + :raises planet.api.exceptions.APIException: On API error. |
| 407 | + :returns: :py:Class:`planet.api.models.Feeds` |
| 408 | + ''' |
| 409 | + params = {'stats': stats} |
| 410 | + url = self._url('feeds') |
| 411 | + return self._get(url, models.Feeds, params=params).get_body() |
| 412 | + |
| 413 | + def get_feed_info(self, feed_id): |
| 414 | + ''' |
| 415 | + Get the information describing a specific collection. |
| 416 | + :param subscription_id: |
| 417 | + :raises planet.api.exceptions.APIException: On API error. |
| 418 | + :returns: :py:Class:`planet.api.models.JSON` |
| 419 | + ''' |
| 420 | + url = self._url('feeds/{}'.format(feed_id)) |
| 421 | + return self._get(url, models.JSON).get_body() |
| 422 | + |
| 423 | + def list_analytic_collections(self): |
| 424 | + ''' |
| 425 | + Get collections that the authenticated user has access to |
| 426 | + :raises planet.api.exceptions.APIException: On API error. |
| 427 | + :returns: :py:Class:`planet.api.models.WFS3Collections` |
| 428 | + ''' |
| 429 | + params = {} |
| 430 | + url = self._url('collections') |
| 431 | + return self._get(url, models.WFS3Collections, |
| 432 | + params=params).get_body() |
| 433 | + |
| 434 | + def get_collection_info(self, subscription_id): |
| 435 | + ''' |
| 436 | + Get the information describing a specific collection. |
| 437 | + :param subscription_id: |
| 438 | + :raises planet.api.exceptions.APIException: On API error. |
| 439 | + :returns: :py:Class:`planet.api.models.JSON` |
| 440 | + ''' |
| 441 | + url = 'collections/{}'.format(subscription_id) |
| 442 | + return self._get(self._url(url), models.JSON).get_body() |
| 443 | + |
| 444 | + def list_collection_features(self, |
| 445 | + subscription_id, |
| 446 | + bbox, |
| 447 | + time_range, |
| 448 | + ): |
| 449 | + ''' |
| 450 | + List features for an analytic subscription. |
| 451 | + :param subscription_id: |
| 452 | + :param time_range str: ISO format datetime interval. |
| 453 | + :param bbox tuple: A lon_min, lat_min, lon_max, lat_max area to search |
| 454 | + :raises planet.api.exceptions.APIException: On API error. |
| 455 | + :returns: :py:Class:`planet.api.models.WFS3Features` |
| 456 | + ''' |
| 457 | + params = { |
| 458 | + 'time': time_range, |
| 459 | + } |
| 460 | + if bbox: |
| 461 | + params['bbox'] = ','.join([str(b) for b in bbox]) |
| 462 | + url = self._url('collections/{}/items'.format(subscription_id)) |
| 463 | + return self._get(url, models.WFS3Features, params=params).get_body() |
| 464 | + |
| 465 | + def get_associated_resource_for_analytic_feature(self, |
| 466 | + subscription_id, |
| 467 | + feature_id, |
| 468 | + resource_type): |
| 469 | + ''' |
| 470 | + Get resource associated with some feature in an analytic subscription. |
| 471 | + Response might be JSON or a TIF, depending on requested resource. |
| 472 | + :param subscription_id str: ID of subscription |
| 473 | + :param feature_id str: ID of feature |
| 474 | + :param resource_type str: Type of resource to request. |
| 475 | + :raises planet.api.exceptions.APIException: On API error or resource |
| 476 | + type unavailable. |
| 477 | + :returns: :py:Class:`planet.api.models.JSON` for resource type |
| 478 | + `source-image-info`, but can also return |
| 479 | + :py:Class:`planet.api.models.Response` containing a |
| 480 | + :py:Class:`planet.api.models.Body` of the resource. |
| 481 | + ''' |
| 482 | + url = self._url( |
| 483 | + 'collections/{}/items/{}/resources/{}'.format(subscription_id, |
| 484 | + feature_id, |
| 485 | + resource_type)) |
| 486 | + response = self._get(url).get_body() |
| 487 | + return response |
0 commit comments