<jupyter_start><jupyter_text>Select our field, we want it to be 1 for full excluded<jupyter_code>gdf['value'] = 1<jupyter_output><empty_output><jupyter_text>Only keep fields that we need; create fid field<jupyter_code>gdf['fid'] = gdf.index
gdf = gdf[['fid', 'value', 'geometry']]<jupyter_output><empty_output><jupyter_text>See the coordinate reference system<jupyter_code>gdf.crs<jupyter_output><empty_output><jupyter_text>Reproject to Albers<jupyter_code>pdf = gdf.to_crs('+proj=aea +lat_1=29.5 +lat_2=45.5 +lat_0=37.5 +lon_0=-96 +x_0=0 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs')
pdf.plot()
pdf.crs<jupyter_output><empty_output><jupyter_text>Check out our template raster<jupyter_code>template_raster = '/Users/d3y010/projects/cerf/suitability/_common/PNNL_Land_Mask_CONUS.img'

rast = rasterio.open(template_raster)
rast.meta<jupyter_output><empty_output><jupyter_text>TODO:  Get proj4s for shapefile reprojection from raster template CRS<jupyter_code>rast.crs
rast.close()<jupyter_output><empty_output><jupyter_text>Convert the geodataframe to a raster using our template<jupyter_code>def rasterize(geodataframe, template_raster, outras, field):
    
    with rasterio.open(template_raster) as src:
        kwargs = src.meta.copy()
        kwargs.update({
            'driver': 'GTiff',
            'compress': 'lzw'
        })
        
        #windows = src.block_windows(1)  
        
        with rasterio.open(outras, 'w', **kwargs) as dst:
            
            #for idx, window in windows:
                
            out_arr = src.read(1) #, window=window)
                
            # this is where we create a generator of geom, value pairs to use in rasterizing
            shapes = ((geom,value) for geom, value in zip(geodataframe.geometry, geodataframe[field]))

            burned = features.rasterize(shapes=shapes, fill=0, out=out_arr, transform=src.transform, all_touched=True)

            dst.write_band(1, burned) #, window=window)   
out_raster = '/Users/d3y010/Desktop/species.tif'

rasterize(pdf, template_raster, out_raster, 'value')<jupyter_output><empty_output><jupyter_text>Examine new raster<jupyter_code>with rasterio.open(out_raster) as rast:
    show(rast)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11796246648793565, 'fraction_numerical': 0.016979445933869526, 'mean_word_length': 4.28066037735849, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '6578', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 849, 'n_tokens_neox': 820, 'n_words': 146, 'path': 'notebooks/cerf_spatial.ipynb', 'repo_name': 'KristianNelson/nelson_etal_2021_scidata', 'size': '2238'}