$npx -y skills add opengeos/geoai-skills --skill search-stacSearch and download satellite imagery from Microsoft Planetary Computer. Browse available collections, search by bbox and time range, list assets, and download specific items.
| 1 | You are helping the user search and download satellite imagery from the |
| 2 | Planetary Computer STAC catalog using geoai. |
| 3 | |
| 4 | Input: `$@` |
| 5 | |
| 6 | Follow these steps in order. |
| 7 | |
| 8 | ## Step 1 -- Determine the action |
| 9 | |
| 10 | Parse `$@` to identify what the user wants: |
| 11 | |
| 12 | - If the input is `list`, `collections`, or asks "what is available": **list collections**. |
| 13 | - If a collection name and `--bbox` are provided: **search for items**. |
| 14 | - If `--download` is present: **download items** after searching. |
| 15 | |
| 16 | ## Step 2 -- List collections (if requested) |
| 17 | |
| 18 | ```bash |
| 19 | python3 -c " |
| 20 | import geoai |
| 21 | df = geoai.pc_collection_list() |
| 22 | print(df.to_string()) |
| 23 | " |
| 24 | ``` |
| 25 | |
| 26 | If the user provided a filter keyword, pass it: |
| 27 | |
| 28 | ```bash |
| 29 | python3 -c " |
| 30 | import geoai |
| 31 | df = geoai.pc_collection_list(filter_by='FILTER') |
| 32 | print(df.to_string()) |
| 33 | " |
| 34 | ``` |
| 35 | |
| 36 | Report the available collections and stop (unless the user also specified a search). |
| 37 | |
| 38 | ## Step 3 -- Search for items |
| 39 | |
| 40 | Parse the collection name, bounding box (`--bbox`), and optional datetime range (`--datetime`). |
| 41 | |
| 42 | The datetime range should be in the format `YYYY-MM-DD/YYYY-MM-DD` (start/end). |
| 43 | |
| 44 | ```bash |
| 45 | python3 -c " |
| 46 | import geoai |
| 47 | |
| 48 | items = geoai.pc_stac_search( |
| 49 | collection='COLLECTION', |
| 50 | bbox=[MINX, MINY, MAXX, MAXY], |
| 51 | time_range='TIME_RANGE', |
| 52 | limit=LIMIT, |
| 53 | ) |
| 54 | print(f'Found {len(items)} items') |
| 55 | print('---') |
| 56 | for item in items[:20]: |
| 57 | assets = list(item.assets.keys()) |
| 58 | print(f' {item.id}: {item.datetime} - assets: {assets}') |
| 59 | " |
| 60 | ``` |
| 61 | |
| 62 | Replace `COLLECTION`, `MINX`, `MINY`, `MAXX`, `MAXY`, `TIME_RANGE`, and `LIMIT` with actual values. Use `limit=10` by default. |
| 63 | |
| 64 | If `time_range` was not specified, omit it or pass `None`. |
| 65 | |
| 66 | ## Step 4 -- List assets for an item (optional) |
| 67 | |
| 68 | If the user asks about available assets or bands for a specific item: |
| 69 | |
| 70 | ```bash |
| 71 | python3 -c " |
| 72 | import geoai |
| 73 | assets = geoai.pc_item_asset_list(item_id='ITEM_ID', collection='COLLECTION') |
| 74 | for name, info in assets.items(): |
| 75 | print(f' {name}: {info}') |
| 76 | " |
| 77 | ``` |
| 78 | |
| 79 | ## Step 5 -- Download items (if --download flag or user confirms) |
| 80 | |
| 81 | ```bash |
| 82 | python3 -c " |
| 83 | import geoai, os |
| 84 | |
| 85 | items = geoai.pc_stac_search( |
| 86 | collection='COLLECTION', |
| 87 | bbox=[MINX, MINY, MAXX, MAXY], |
| 88 | time_range='TIME_RANGE', |
| 89 | limit=LIMIT, |
| 90 | ) |
| 91 | |
| 92 | output_dir = 'OUTPUT_DIR' |
| 93 | os.makedirs(output_dir, exist_ok=True) |
| 94 | |
| 95 | result = geoai.pc_stac_download( |
| 96 | items, |
| 97 | output_dir=output_dir, |
| 98 | ) |
| 99 | print(f'Downloaded to: {output_dir}') |
| 100 | for f in os.listdir(output_dir): |
| 101 | fpath = os.path.join(output_dir, f) |
| 102 | if os.path.isfile(fpath): |
| 103 | size_mb = os.path.getsize(fpath) / (1024 * 1024) |
| 104 | print(f' {f} ({size_mb:.1f} MB)') |
| 105 | " |
| 106 | ``` |
| 107 | |
| 108 | Default output directory: `./stac_data/` |
| 109 | |
| 110 | ## Step 6 -- Report and suggest follow-ups |
| 111 | |
| 112 | Summarize the search or download results. Then suggest: |
| 113 | |
| 114 | - *"Use `/geoai-skills:inspect-geo` to examine any downloaded files."* |
| 115 | - *"Use `/geoai-skills:process-raster` to clip or mosaic the imagery."* |
| 116 | |
| 117 | ## Error handling |
| 118 | |
| 119 | - **`import geoai` fails** -> delegate to `/geoai-skills:install-geoai`. |
| 120 | - **Invalid collection name** -> list available collections and suggest the closest match. |
| 121 | - **No items found** -> suggest expanding the bbox, adjusting the date range, or trying a different collection. |
| 122 | - **Download failure** -> report the error and suggest retrying with fewer items. |