1

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)**
5
  • Hey, welcome to GIS SE. What line of your code is yielding your error? Furthermore, how many bands does your raster have? Commented 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 Commented Aug 9, 2020 at 6:59
  • Can you share a small portion of your data to do some tests? Commented Aug 9, 2020 at 14:10
  • can CRS of my shapefile cause this issue? I'm using WGS84 reference system Commented 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. Commented Aug 10, 2020 at 13:29

1 Answer 1

0

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 and acknowledge you have read our privacy policy.

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