|
108 | 108 | {
|
109 | 109 | "cell_type": "code",
|
110 | 110 | "execution_count": null,
|
| 111 | + "metadata": {}, |
| 112 | + "outputs": [], |
111 | 113 | "source": [
|
112 | 114 | "m = leafmap.Map()\n",
|
113 | 115 | "m.clear_layers()\n",
|
114 | 116 | "layers_dict = leafmap.basemap_xyz_tiles()\n",
|
115 | 117 | "m.add_time_slider(layers_dict, time_interval=1)\n",
|
116 | 118 | "m"
|
117 |
| - ], |
| 119 | + ] |
| 120 | + }, |
| 121 | + { |
| 122 | + "cell_type": "markdown", |
| 123 | + "metadata": {}, |
| 124 | + "source": [ |
| 125 | + "Use the time slider to visualize COG assets found within STAC items." |
| 126 | + ] |
| 127 | + }, |
| 128 | + { |
| 129 | + "cell_type": "code", |
| 130 | + "execution_count": null, |
| 131 | + "metadata": {}, |
118 | 132 | "outputs": [],
|
119 |
| - "metadata": { |
120 |
| - "scrolled": false |
121 |
| - } |
| 133 | + "source": [ |
| 134 | + "import ipyleaflet\n", |
| 135 | + "import json\n", |
| 136 | + "import requests\n", |
| 137 | + "\n", |
| 138 | + "stac_api = \"https://earth-search.aws.element84.com/v0\"\n", |
| 139 | + "search_endpoint = f\"{stac_api}/search\"\n", |
| 140 | + "\n", |
| 141 | + "collection = \"sentinel-s2-l2a-cogs\"\n", |
| 142 | + "payload = {\n", |
| 143 | + " \"bbox\": [\n", |
| 144 | + " -102.83340454101562, 49.77860375256143, -102.41043090820312, 50.05273014900257\n", |
| 145 | + " ],\n", |
| 146 | + " \"datetime\": \"2021-07-01T00:00:00Z/2021-10-01T12:31:12Z\",\n", |
| 147 | + " \"collections\": [collection],\n", |
| 148 | + " \"limit\": 10,\n", |
| 149 | + " \"query\": {\n", |
| 150 | + " \"eo:cloud_cover\": {\n", |
| 151 | + " \"gte\": 0,\n", |
| 152 | + " \"lte\": 10\n", |
| 153 | + " }\n", |
| 154 | + " }\n", |
| 155 | + "}\n", |
| 156 | + "\n", |
| 157 | + "headers = {\n", |
| 158 | + " 'Content-Type': 'application/json'\n", |
| 159 | + "}\n", |
| 160 | + "\n", |
| 161 | + "response = requests.request(\"POST\", search_endpoint, headers=headers, data=json.dumps(payload))\n", |
| 162 | + "\n", |
| 163 | + "features = response.json()[\"features\"]\n", |
| 164 | + "features.sort(key=lambda x: x[\"properties\"][\"datetime\"], reverse=False)\n", |
| 165 | + "\n", |
| 166 | + "layers_dict = {}\n", |
| 167 | + "for feature in features:\n", |
| 168 | + " feature_id = feature[\"id\"]\n", |
| 169 | + " print(feature_id)\n", |
| 170 | + " \n", |
| 171 | + " url = leafmap.stac_tile(f\"{stac_api}/collections/{collection}/items/{feature_id}\", bands=[\"visual\"])\n", |
| 172 | + " tile_layer = ipyleaflet.TileLayer(\n", |
| 173 | + " url=url,\n", |
| 174 | + " name=feature_id,\n", |
| 175 | + " )\n", |
| 176 | + " layers_dict[feature_id] = tile_layer\n", |
| 177 | + " \n", |
| 178 | + "m = leafmap.Map(center=[50.093079, -103.152825], zoom=11)\n", |
| 179 | + "m.add_time_slider(layers_dict, time_interval=2)\n", |
| 180 | + "m" |
| 181 | + ] |
| 182 | + }, |
| 183 | + { |
| 184 | + "cell_type": "code", |
| 185 | + "execution_count": null, |
| 186 | + "metadata": {}, |
| 187 | + "outputs": [], |
| 188 | + "source": [] |
122 | 189 | }
|
123 | 190 | ],
|
124 | 191 | "metadata": {
|
|
0 commit comments