I'm new to Python. I'm trying to sample raster values to points based on the geometries of a shapefile using the below code but I'm receiving the below error .

import fiona
import rasterio as rio
import pandas as pd

 multi_values_points = pd.Series()
 with fiona.open(inputShape) as shp:
     for feature in shp:
        Name = feature['properties']['Name']
        coords = feature['geometry']['coordinates']
        with rio.open(inputRaster) as stack_src:
           value = [v for v in stack_src.sample([coords])]
        multi_values_points.loc[Name] = value
 **ValueError: not enough values to unpack (expected 2, got 1)**
  • Hey, welcome to GIS SE. What line of your code is yielding your error? Furthermore, how many bands does your raster have? Aug 8, 2020 at 20:06
  • The error has occured at value = [v for v in stack_src.sample([coords])] , my raster has 7 bands Aug 9, 2020 at 6:59
  • Can you share a small portion of your data to do some tests? Aug 9, 2020 at 14:10
  • can CRS of my shapefile cause this issue? I'm using WGS84 reference system Aug 10, 2020 at 6:20
  • Do the points and the raster have the same CRS? If they do, it should not matter what the CRS is. Aug 10, 2020 at 13:29

1 Answer 1


I have figured out that coodinates of my raster data are in 3-Dimension and hence converted them to 2D as I no longer needed my z coordinate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.