rasterize
rasterize_from_geometry(geometry, bounds=None, transform=None, resolution=None, window_out=None, value=1, dtype=np.uint8, crs_geom_bounds=None, fill=0, all_touched=False, return_only_data=False)
¶
Rasterise the provided geometry over the bounds with the specified resolution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geometry
|
Union[Polygon, MultiPolygon, LineString]
|
geometry to rasterise (with crs |
required |
bounds
|
Optional[Tuple[float, float, float, float]]
|
bounds where the polygons will be rasterised. (with crs |
None
|
transform
|
Optional[Affine]
|
if transform is provided it will use this instead of |
None
|
resolution
|
Optional[Union[float, Tuple[float, float]]]
|
spatial resolution of the rasterised array. It won't be used if transform is provided (with crs |
None
|
window_out
|
Optional[Window]
|
Window out in |
None
|
value
|
Number
|
column to take the values for rasterisation. |
1
|
dtype
|
Any
|
dtype of the rasterise raster. |
uint8
|
crs_geom_bounds
|
Optional[Any]
|
CRS of geometry and bounds |
None
|
fill
|
Union[int, float]
|
fill option for rasterio.features.rasterize |
0
|
all_touched
|
bool
|
all_touched option for rasterio.features.rasterize |
False
|
return_only_data
|
bool
|
if |
False
|
Returns:
Type | Description |
---|---|
Union[GeoTensor, ndarray]
|
GeoTensor or np.ndarray with shape (H, W) with the rasterised polygon |
Source code in georeader/rasterize.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
rasterize_from_geopandas(dataframe, column, bounds=None, transform=None, window_out=None, resolution=None, crs_out=None, fill=0, all_touched=False, return_only_data=False)
¶
Rasterise the provided geodataframe over the bounds with the specified resolution.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataframe
|
GeoDataFrame
|
geodataframe with columns geometry and |
required |
bounds
|
Optional[Tuple[float, float, float, float]]
|
bounds where the polygons will be rasterised with CRS |
None
|
transform
|
Optional[Affine]
|
if transform is provided if will use this for the resolution. |
None
|
resolution
|
Optional[Union[float, Tuple[float, float]]]
|
spatial resolution of the rasterised array |
None
|
window_out
|
Optional[Window]
|
Window out in |
None
|
column
|
str
|
column to take the values for rasterisation. |
required |
crs_out
|
Optional[Any]
|
defaults to dataframe.crs. This function will transform the geometries from dataframe.crs to this crs
before rasterisation. |
None
|
fill
|
Union[int, float]
|
fill option for rasterio.features.rasterize |
0
|
all_touched
|
bool
|
all_touched option for rasterio.features.rasterize |
False
|
return_only_data
|
bool
|
if |
False
|
Returns:
Type | Description |
---|---|
Union[GeoTensor, ndarray]
|
GeoTensor or np.ndarray with shape (H, W) with the rasterised polygons of the dataframe |
Source code in georeader/rasterize.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
rasterize_geometry_like(geometry, data_like, value=1, dtype=np.uint8, crs_geometry=None, fill=0, all_touched=False, return_only_data=False)
¶
Rasterise the geometry
to the same extent and resolution as defined data_like
GeoData object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
geometry
|
Union[Polygon, MultiPolygon, LineString]
|
geometry to rasterise |
required |
data_like
|
GeoData
|
geoData to use transform, bounds and crs for rasterisation |
required |
value
|
Number
|
value to use in the points within the geometry |
1
|
dtype
|
Any
|
dtype of the rasterise raster. |
uint8
|
crs_geometry
|
Optional[Any]
|
CRS of geometry |
None
|
fill
|
Union[int, float]
|
fill option for rasterio.features.rasterize |
0
|
all_touched
|
bool
|
all_touched option for rasterio.features.rasterize |
False
|
return_only_data
|
bool
|
if |
False
|
Returns:
Type | Description |
---|---|
Union[GeoTensor, ndarray]
|
GeoTensor or np.ndarray with shape (H, W) with the rasterised polygon |
Source code in georeader/rasterize.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
rasterize_geopandas_like(dataframe, data_like, column, fill=0, all_touched=False, return_only_data=False)
¶
Rasterise the geodataframe to the same extent and resolution as defined data_like
GeoData object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataframe
|
GeoDataFrame
|
geodataframe with columns geometry and |
required |
data_like
|
GeoData
|
geoData to use transform, bounds and crs for rasterisation |
required |
column
|
str
|
column to take the values for rasterisation. |
required |
fill
|
Union[int, float]
|
fill option for rasterio.features.rasterize |
0
|
all_touched
|
bool
|
all_touched option for rasterio.features.rasterize |
False
|
return_only_data
|
bool
|
if |
False
|
Returns:
Type | Description |
---|---|
Union[GeoTensor, ndarray]
|
GeoTensor or np.ndarray with shape (H, W) with the rasterised polygons of the dataframe |
Source code in georeader/rasterize.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|