3

I am working on machine learning algorithms for predicting wildfire sites on state level. I have a CSV of wildfire instances, that has 37 columns including a geometry column, a lat column and a lon column. I also have a stacked raster, in TIFF format of various climate and other associated variables. I am trying to use Python to extract the values from the stacked raster at the point locations (from the wildfire CSV) and create a data frame.

I have done a similar task before in R, using:

training <- raster::extract(raster_stack, wildfire, df=TRUE)

I have tried a couple of methods, similar to this response Python - Extract raster values at point locations and this one

with fiona.open('wildfire_gdb/wf_clip.shp') as shp:
    for feature in shp:
        wf_category = feature['properties']['FIRENAME']
        coords = feature['geometry']['coordinates']
        with rasterio.open('/Users/marie/Desktop/GI3/projekt/stacked.tif') as src:
            value = [v for v in src.sample([coords])][0][0]
        raster_values.loc['FIRENAME']=value

However, it just returns a CSV with a single cell of -3.4e+38, and think I am going wrong with calling the geometry or lat/lon values somewhere on a feature, 'FIRENAME' as I am not 100% sure what was meant by 'properties' and 'coordinates' in the code I tried to edit for my own use.

Sorry, I am new to this and not sure what other information you need that would be helpful and have searched everywhere and found nothing so far that gets me the output expected.

0 Answers0