Contents
How to rasterize a shapefile with geopandas or Fiona?
The overall idea is to create an iterable containing tuples of (geometry, value), where the geometry is a shapely geometry and the value is what you want to burn into the raster at that geometry’s location. Both Fiona and GeoPANDAS use shapely geometries so you are in luck there.
How does a vector layer work in raster?
Input vector layer with point, line or polygon geometries. Defines the attribute field from which the attributes for the pixels should be chosen. If activated writes the results into an existing raster layer. If the above option is not checked either the output size is in pixels (0) or the output resolution is in map units per pixel (1).
How to draw a raster band from a vector?
Next we define the shape of the output band, the transform (both of these are just taken from the original worldpop raster file), the fill value for pixels that have no rasterized vector, the all_touched option draws in all pixels that are touched by the geometries. To manipulate this new band, I have had to save it in a raster file.
Which is the best raster for shapely geometry?
I found a piece of code from rasterio which seems to be able to take a shapely geometry and burn it into a new raster http://tinyurl.com/op49uek You are on the right track and the geopandas GeoDataFrame is a good choice for rasterization over Fiona.
Which is better for shapefiles, Fiona or Dataframe?
Fiona is a great toolset, but I think that the DataFrame is better suited to shapefiles and geometries than nested dictionaries. The overall idea is to create an iterable containing tuples of (geometry, value), where the geometry is a shapely geometry and the value is what you want to burn into the raster at that geometry’s location.
How to rasterize a geospatial shapefile in Python?
In both cases most geospatial software packages handle these operations for you behind the scenes. The very simple script below shows you how you can rasterize a shapefile using the Python Shapefile Library (PSL) and the Python Imaging Library (PIL).