Skip to content

Commit 3b6122d

Browse files
authored
Merge pull request #145 from jlarsen-usgs/main
fix rasterio index() call
2 parents d8a6d36 + 937315f commit 3b6122d

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

notebooks/part0_python_intro/10_Rasterio.ipynb

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,16 @@
156156
"metadata": {},
157157
"outputs": [],
158158
"source": [
159-
"list(zip(*points))"
159+
"xpts, ypts = list(zip(*points))\n",
160+
"# points"
160161
]
161162
},
162163
{
163164
"cell_type": "markdown",
164165
"id": "404a972a",
165166
"metadata": {},
166167
"source": [
167-
"#### Now let's sample elevations at these points\n",
168-
"\n",
169-
"If we do the unpacking in a function call (e.g. `src.index(*zip(*points))`), we need to add a leading `*` to unpack the tuple into two separate arguments"
168+
"#### Now let's sample elevations at these points\n"
170169
]
171170
},
172171
{
@@ -176,10 +175,14 @@
176175
"metadata": {},
177176
"outputs": [],
178177
"source": [
179-
"with rasterio.open(input_rasters[2015]) as src: \n",
180-
" meta = src.meta\n",
181-
" data = src.read(1)\n",
182-
" i, j = src.index(*zip(*points))\n",
178+
"with rasterio.open(input_rasters[2015]) as src: \n",
179+
" meta = src.meta\n",
180+
" data = src.read(1)\n",
181+
" i, j = [], []\n",
182+
" for ix in range(len(xpts)):\n",
183+
" ti, tj = src.index(xpts[ix], ypts[ix])\n",
184+
" i.append(ti)\n",
185+
" j.append(tj)\n",
183186
"print(data[i, j])"
184187
]
185188
},
@@ -993,7 +996,7 @@
993996
"name": "python",
994997
"nbconvert_exporter": "python",
995998
"pygments_lexer": "ipython3",
996-
"version": "3.11.7"
999+
"version": "3.11.10"
9971000
}
9981001
},
9991002
"nbformat": 4,

0 commit comments

Comments
 (0)