C02 Init Grid¶
Create a grid over the metropole or a selection of city and save it to DB
Command
¶
Bases: BaseCommand
Source code in back/iarbre_data/management/commands/c02_init_grid.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
|
_create_grid_city(city, batch_size, logger, grid_type, side_length, grid_size, delete)
staticmethod
¶
Create grid for a specific city.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
city | City | The city object with geometry, id and name. | required |
batch_size | int | The size of the batch to save to the DB. | required |
logger | Logger | The logger object. | required |
grid_type | int | The type of grid to create. | required |
side_length | float | The size of equilateral triangles forming the hexagon. (for hexagonal grid only). | required |
grid_size | float | The size of the grid in meters (for square grid). | required |
delete | bool | Flag to indicate if existing tiles should be deleted. | required |
Returns:
Type | Description |
---|---|
None | None |
Source code in back/iarbre_data/management/commands/c02_init_grid.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
add_arguments(parser)
¶
Add arguments to the command.
Source code in back/iarbre_data/management/commands/c02_init_grid.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
handle(*args, **options)
¶
Create grid and save it to DB.
Source code in back/iarbre_data/management/commands/c02_init_grid.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
|
HexTileShape
¶
Bases: TileShape
Generate hexagonal tile.
Source code in back/iarbre_data/management/commands/c02_init_grid.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
adjust_bounds(xmin, ymin, xmax, ymax, grid_size, side_length)
staticmethod
¶
Snap bounds to the nearest grid alignment.
Source code in back/iarbre_data/management/commands/c02_init_grid.py
74 75 76 77 78 79 80 81 82 83 |
|
create_tile_polygon(x, y, grid_size, side_length, i)
staticmethod
¶
Create a single hexagon and round geometries to optimize storage.
Source code in back/iarbre_data/management/commands/c02_init_grid.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
tile_positions(xmin, ymin, xmax, ymax, grid_size, side_length)
staticmethod
¶
Generate an iterator for all the position where to create a tile.
Source code in back/iarbre_data/management/commands/c02_init_grid.py
85 86 87 88 89 90 91 92 93 |
|
SquareTileShape
¶
Bases: TileShape
Generate square tile.
Source code in back/iarbre_data/management/commands/c02_init_grid.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
adjust_bounds(xmin, ymin, xmax, ymax, grid_size, side_length=None)
staticmethod
¶
Snap bounds to the nearest grid alignment.
Source code in back/iarbre_data/management/commands/c02_init_grid.py
46 47 48 49 50 51 52 53 |
|
create_tile_polygon(x, y, grid_size, side_length=None, i=None)
staticmethod
¶
Create a single square and round geometries to optimize storage.
Source code in back/iarbre_data/management/commands/c02_init_grid.py
63 64 65 66 67 68 |
|
tile_positions(xmin, ymin, xmax, ymax, grid_size, side_length=None)
staticmethod
¶
Generate an iterator for all the position where to create a tile.
Source code in back/iarbre_data/management/commands/c02_init_grid.py
55 56 57 58 59 60 61 |
|
clean_outside(selected_city, batch_size)
¶
Remove all tiles outside the selected cities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selected_city | DataFrame | The DataFrame of the selected cities. | required |
batch_size | int | The size of the batch to delete. | required |
Returns:
Type | Description |
---|---|
None | None |
Source code in back/iarbre_data/management/commands/c02_init_grid.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
create_tiles_for_city(city, grid_size, tile_shape_cls, logger, batch_size=int(1000000.0), side_length=None, height_ratio=1)
¶
Create tiles (square or hexagonal) for a specific city.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
city | GeoPandas DataFrame | City GeoDataFrame. | required |
grid_size | float | The size of the grid in meters. | required |
tile_shape_cls | class | Class to generate individual tile shapes. | required |
logger | Logger | The logger object. | required |
batch_size | int | The size of the batch to save to DB. | int(1000000.0) |
side_length | float | Size of equilateral triangles forming the hexagon. | None |
height_ratio | float) | The height ratio of the grid element (1 for square and sin(60) for hexs). | 1 |
Returns:
Type | Description |
---|---|
None | None |
Source code in back/iarbre_data/management/commands/c02_init_grid.py
112 113 114 115 116 117 118 119 120 121 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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|