Problem: given a bunch of buildings from a geopandas file and a list of lines, calculate the # of lines that don’t intersect any buildings / total # of lines. I’m currently investigating using rasterio rasterize() for this.
Question: Is there a method (like rasterio.transform.rowcol()) that if given a list of xs and list of ys (or rows, cols) will return the values of all the pixels making up the line from the raster?
I have selected the features (buildings) from a geopandas file and created the raster using rasterio.features.rasterize().
- I could use rasterio.transform.rowcol() to convert (x,y) coordinates of points along the line to (row,col) indices.
- I could then use [row][col] to read the pixel values one at a time from the raster ndarray. [I think this will be the slow part for the billions of points.]
I will need to do this for millions of lines, so I’m looking for a fast way to do this.
Note: I have seen these similar questions
Extract pixel values form a multispectral (B1-B6) raster image using a shape file mask
This looks like each call returns a ndarray the size of the original raster. I tried something like this but using np.any() for these large arrays (3 GB or larger) was slow. (I only need the values of the pixels along the lines.)
How to extract a profile of value from a raster along a given line?
From this answer it seems there is not a single (fast) rasterio method that gets the values for the pixels along the line in a single call instead of having to make 1 function call to read each pixel value. Is this Correct?