API Reference
raster_utilities
Ortophoto(path=None, folder=None, crs=25831)
Raster algorithm containing the different values to be kept.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
The path to the image, with the GDAL-accepted formats. Defaults to None. |
None
|
folder
|
str
|
The default folder for all computations to be performed. Defaults to None, and will be stored in with a name like DATA_DIR/{path}. |
None
|
crs
|
int
|
CRS of the tile to be loaded. Defaults to 25831. |
25831
|
Raises:
Type | Description |
---|---|
Exception
|
File is not valid |
Source code in apb_spatial_computer_vision/raster_utilities.py
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 110 |
|
cloneBand(image, dst_filename, driver_name=None)
Creates a new raster file just like the current, given a matrix
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image
|
array
|
[[row, col],[row,col],...] pixel-level description of the image |
required |
dst_filename
|
str
|
Absolute path of the file to be written to |
required |
driver_name
|
str
|
GDAL-Driver to run the create command.If not specified it will guess from the dst_filename, or if it fails as GTiff. Defaults to None. |
None
|
Source code in apb_spatial_computer_vision/raster_utilities.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
|
create_pyramid(lowest_pixel_size)
Generates a log_2 based image pyramid with the most available tiles.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lowest_pixel_size
|
int
|
Number of pixels of the size for each tile |
required |
Returns:
Name | Type | Description |
---|---|---|
pyramid_dir |
The path to where the pyramid was stored |
Source code in apb_spatial_computer_vision/raster_utilities.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
|
create_resolutions(depth)
Generate images with degraded resolutions using bilineal interpolation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
depth
|
int
|
The amount of numbers to be used in the development of the data. |
required |
Returns:
Name | Type | Description |
---|---|---|
resolutions_dir |
str
|
The path where the resolutions are stored (within the ortophoto /project folder) |
Source code in apb_spatial_computer_vision/raster_utilities.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
|
create_tiles_duckdb_table(lowest_pixel_size=1024)
Generates a DUCKDB table named tiles, containing the image pyramid data and its information. May trigger pyramid_depth or pyramid calculation if not abailable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lowest_pixel_size
|
int
|
Number of pixels for each tile in the pyramid. Defaults to 1024. |
1024
|
Source code in apb_spatial_computer_vision/raster_utilities.py
329 330 331 332 333 334 335 336 337 338 339 340 |
|
explore(bound_list, tile_size)
Generates an interactive map in HTML for the tiles
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bound_list
|
Iterable[tuple[float]]
|
list of bounds, like from the tiles |
required |
tile_size
|
Iterable[str]
|
tile size with which the bounds have been developed. |
required |
Source code in apb_spatial_computer_vision/raster_utilities.py
414 415 416 417 418 419 420 421 422 423 424 425 426 |
|
find_intersection_centroid(gdf)
Intersects an image and a gdf and returns intersection centroid
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gdf
|
GeoDataFrame
|
Geospatial table containing a 'geometry' column |
required |
Returns:
Name | Type | Description |
---|---|---|
coords |
The XY coordinates of the centroid of the intersection |
Source code in apb_spatial_computer_vision/raster_utilities.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 |
|
getSRS()
Get the OSGEO/OSR WKT CRS
Returns:
Name | Type | Description |
---|---|---|
str |
OSGEO/OSR Well-known Text (WKT) CRS |
Source code in apb_spatial_computer_vision/raster_utilities.py
228 229 230 231 232 233 234 235 236 237 238 |
|
get_pyramid(lowest_pixel_size)
Gets the pyramid directory or creates it if not yet implemented
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lowest_pixel_size
|
int
|
Number of pixels for each tile in the pyramid. Defaults to 1024. |
required |
Returns:
Type | Description |
---|---|
self.pyramid (str) : Path to the pyramid |
Source code in apb_spatial_computer_vision/raster_utilities.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
|
get_pyramid_depth(lowest_pixel_size=1024)
Calculates the depth of the image pyramid, creates it too if it hasn't been done yet
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lowest_pixel_size
|
int
|
Number of pixels for each tile in the pyramid. Defaults to 1024. |
1024
|
Returns:
Type | Description |
---|---|
self.pyramid_depth (int): Number of levels of the pyramid |
Source code in apb_spatial_computer_vision/raster_utilities.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 |
|
get_pyramid_tiles(lowest_pixel_size=1024)
Fetches the list containing the paths for all files in the pyramid
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lowest_pixel_size
|
int
|
Number of pixels for each tile in the pyramid. Defaults to 1024. |
1024
|
Returns:
Type | Description |
---|---|
self.pyramid_tiles (list): Paths for the tiles in the pyramid |
Source code in apb_spatial_computer_vision/raster_utilities.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
mosaic_rasters(im_input, name, fetch=False, pixel_value_to_be_ignored='')
staticmethod
Returns the ortophoto object of the addition of the imput elements' iterable
Parameters:
Name | Type | Description | Default |
---|---|---|---|
im_input
|
Iterable
|
a list of Ortophoto objects or paths |
required |
name
|
str
|
Output name for the mosaic |
required |
fetch
|
bool
|
Wether to return the Ortophoto object. Defaults to False. |
False
|
pixel_value_to_be_ignored
|
str
|
Pixel value that will not override other previous values in case of overlap. Defaults to ''. |
''
|
Returns:
Name | Type | Description |
---|---|---|
outname |
str
|
Output file name. |
out_orto |
Ortophoto
|
Generated ortophoto object for the output file, only created if fetch equals True. |
Source code in apb_spatial_computer_vision/raster_utilities.py
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 196 197 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 |
|
nice_write(num)
staticmethod
Computes the needed digits to be applied to zfill for succesful number ordering
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num
|
int
|
input number |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
The number of digits to be applied into zfill |
Source code in apb_spatial_computer_vision/raster_utilities.py
246 247 248 249 250 251 252 253 254 255 256 257 |
|
polygonize(step_x, step_y=None)
Creates GDAL-based image cropping given an image size. Concurrently-sped up.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
step_x
|
int
|
The size of the resulting elements |
required |
horizontal_skew
|
int
|
The pixel units to add from to step in the X direction (cols or i). Defaults to None. |
required |
vertical_skew
|
int
|
The pixel units to add from to step in the Y direction (rows or j). Defaults to None. |
required |
Source code in apb_spatial_computer_vision/raster_utilities.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 |
|
tesselation(dir, step_x, step_y=None)
Generation of tesselation algorithms
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dir
|
str
|
Output directory |
required |
step_x
|
int
|
Pixel width of the image crops. |
required |
step_y
|
int
|
Pixel heigh to the image crops if different. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
name_list |
list
|
Names for the tiles' files |
bound_list |
list[tuple]
|
Nested bounding box list like [(xmin,ymin,xmax,ymax),...,(...)] |
Source code in apb_spatial_computer_vision/raster_utilities.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
Tile(path, crs=25831)
Bases: Ortophoto
Class Tile (Ortophoto) Child class from parent Ortophoto
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
str
|
Complete path to the tile as a string |
required |
crs
|
int
|
CRS of the tile to be loaded. Defaults to 25831. |
25831
|
Source code in apb_spatial_computer_vision/raster_utilities.py
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 |
|
__eq__(t2)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t2(Ortophoto)
|
Tile to be compared |
required |
Returns: bool, True if in the same layer of the pyramid Exceptions: Raise if not an instance of the Ortophoto class
Source code in apb_spatial_computer_vision/raster_utilities.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
|
get_children()
Retrieves the tiles which have a higher resolution for the same point (lower levels of the pyramid for a given tile)
Returns:
Name | Type | Description |
---|---|---|
out_list |
list
|
2D-list. Each list contains a level of deepness, from closer to the current level until the lowest layer of the pyramid. |
Source code in apb_spatial_computer_vision/raster_utilities.py
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 |
|
get_n_rows_cols()
Get the number of rows and columns of a certain level in a pyramid
Returns:
Name | Type | Description |
---|---|---|
n_row |
int
|
number of rows at the current level |
n_col |
int
|
number of columns at the current level |
Source code in apb_spatial_computer_vision/raster_utilities.py
633 634 635 636 637 638 639 640 641 642 643 644 |
|
get_parents()
Retrieves the tiles which have a higher resolution for the same point (lower levels of the pyramid for a given tile)
Returns:
Name | Type | Description |
---|---|---|
out_list |
list
|
2D-list. Each list contains a level of deepness, from closer to the current level until the lowest layer of the pyramid. |
Source code in apb_spatial_computer_vision/raster_utilities.py
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 |
|
get_row_col(path=None)
Get the original size, row and col of a certain tile
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raster
|
str
|
Raster path to be added. Defaults to None. |
required |
Returns:
Name | Type | Description |
---|---|---|
original_size |
int
|
original size of the parent class from where it has been resampled |
row |
int
|
row in the current pyramid layer |
col |
int
|
col in the current pyramid layer |
Source code in apb_spatial_computer_vision/raster_utilities.py
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 |
|
get_siblings()
Finds the four tiles which come from one level higher in the pyramid. It is equivalent to finding the first parent and looking at its first children
Returns:
Type | Description |
---|---|
self.siblings (list): A list of the four immediate siblings in the current level of the pyramid |
Source code in apb_spatial_computer_vision/raster_utilities.py
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 |
|