read
read_from_center_coords(data_in, center_coords, shape, crs_center_coords=None, return_only_data=False, trigger_load=False, boundless=True)
¶
Returns a chip of data_in
centered on center_coords
of shape shape
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_in
|
GeoData
|
GeoData object |
required |
center_coords
|
Tuple[float, float]
|
x, y tuple of coords in |
required |
shape
|
Tuple[int, int]
|
shape of the window to read |
required |
crs_center_coords
|
Optional[Any]
|
CRS of center coords. If provided will check if it needs to reproject the coords before computing the reading window. |
None
|
return_only_data
|
bool
|
defaults to |
False
|
trigger_load
|
bool
|
defaults to |
False
|
boundless
|
bool
|
if |
True
|
Returns:
Type | Description |
---|---|
Union[GeoData, ndarray]
|
GeoData or np.array sliced from |
Source code in georeader/read.py
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 |
|
read_from_bounds(data_in, bounds, crs_bounds=None, pad_add=(0, 0), return_only_data=False, trigger_load=False, boundless=True)
¶
Reads a slice of data_in covering the bounds
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_in
|
GeoData
|
GeoData with geographic info (crs and geotransform). |
required |
bounds
|
Tuple[float, float, float, float]
|
bounding box to read. |
required |
crs_bounds
|
Optional[str]
|
if not None will transform the bounds from that crs to the |
None
|
pad_add
|
Tuple[int, int]
|
Tuple[int, int]. Pad in pixels to add to the |
(0, 0)
|
return_only_data
|
bool
|
defaults to |
False
|
trigger_load
|
bool
|
defaults to |
False
|
boundless
|
bool
|
if |
True
|
Returns:
Type | Description |
---|---|
Union[GeoData, ndarray]
|
sliced GeoData |
Source code in georeader/read.py
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 |
|
read_from_polygon(data_in, polygon, crs_polygon=None, pad_add=(0, 0), return_only_data=False, trigger_load=False, boundless=True, window_surrounding=False)
¶
Reads a slice of data_in covering the polygon
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_in
|
GeoData
|
GeoData with geographic info (crs and geotransform). |
required |
polygon
|
Union[Polygon, MultiPolygon]
|
Polygon or MultiPolygon that specifies the region to read. |
required |
crs_polygon
|
Optional[str]
|
if not None will transform the polygon from that crs to the data.crs to read the chip. |
None
|
pad_add
|
Tuple[int, int]
|
pad in pixels to add to the |
(0, 0)
|
return_only_data
|
bool
|
defaults to |
False
|
trigger_load
|
bool
|
defaults to |
False
|
boundless
|
bool
|
if |
True
|
window_surrounding
|
bool
|
The window surrounds the polygon. (i.e. |
False
|
Returns:
Type | Description |
---|---|
Union[GeoData, ndarray]
|
sliced GeoData |
Source code in georeader/read.py
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 |
|
read_from_window(data_in, window, return_only_data=False, trigger_load=False, boundless=True)
¶
Reads a window from data_in padding with data_in.fill_value_default
if needed
(output GeoData will have window.height
, window.width
shape if boundless is True
).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_in
|
GeoData
|
GeoData with "x" and "y" coordinates |
required |
window
|
Window
|
window to slice the GeoData with. |
required |
return_only_data
|
bool
|
defaults to |
False
|
trigger_load
|
bool
|
defaults to |
False
|
boundless
|
bool
|
if |
True
|
Returns:
Type | Description |
---|---|
Union[GeoData, ndarray, None]
|
GeoData object |
Source code in georeader/read.py
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
read_from_tile(data, x, y, z, dst_crs=WEB_MERCATOR_CRS, out_shape=(SIZE_DEFAULT, SIZE_DEFAULT), resolution_dst_crs=None, assert_if_not_intersects=False)
¶
Read a web mercator tile from a GeoData object. Tiles are TMS tiles defined as: (https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
GeoData
|
GeoData object |
required |
x
|
int
|
x. x coordinate of the tile in the TMS system. |
required |
y
|
int
|
y. y coordinate of the tile in the TMS system. |
required |
z
|
int
|
z. zoom level |
required |
dst_crs
|
Optional[Any]
|
output crs. Defaults to WEB_MERCATOR_CRS. If None uses the crs of data. |
WEB_MERCATOR_CRS
|
out_shape
|
Optional[Tuple[int, int]]
|
output size. Defaults to (SIZE_DEFAULT, SIZE_DEFAULT). If None it will be the size of the tile in the input resolution. |
(SIZE_DEFAULT, SIZE_DEFAULT)
|
resolution_dst_crs
|
Optional[Union[float, Tuple[float, float]]]
|
output resolution. Defaults to None. If out_shape is not None it will be ignored. If None and out_shape is None the output will be at the resolution of the input data. |
None
|
assert_if_not_intersects
|
bool
|
If True it will raise an error if the tile does not intersect the data. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
GeoTensor |
Optional[GeoTensor]
|
GeoTensor covering the tile or None if the tile does not intersect the data. |
Source code in georeader/read.py
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 |
|
read_to_crs(data_in, dst_crs, resampling=rasterio.warp.Resampling.cubic_spline, resolution_dst_crs=None, return_only_data=False)
¶
Change the crs of data_in to dst_crs. This function is a wrapper of the read_reproject
function
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_in
|
GeoData
|
GeoData to reproyect |
required |
dst_crs
|
Any
|
dst crs |
required |
return_only_data
|
bool
|
Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Union[GeoTensor, ndarray]
|
Union[GeoTensor, np.ndarray]: data in dst_crs |
Source code in georeader/read.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
|
read_reproject_like(data_in, data_like, resolution_dst=None, resampling=rasterio.warp.Resampling.cubic_spline, dtype_dst=None, return_only_data=False, dst_nodata=None)
¶
Reads from data_in
and reprojects to have the same extent and resolution than data_like
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_in
|
GeoData
|
GeoData to read and reproject. Expected coords "x" and "y". |
required |
data_like
|
GeoData
|
GeoData to get the bounds and resolution to reproject |
required |
resampling
|
Resampling
|
specifies how data is reprojected from |
cubic_spline
|
resolution_dst
|
Optional[Union[float, Tuple[float, float]]]
|
if not None it will overwrite the resolution of |
None
|
dtype_dst
|
Any
|
if None it will be inferred |
None
|
return_only_data
|
bool
|
defaults to |
False
|
dst_nodata
|
Optional[int]
|
dst_nodata value |
None
|
Returns:
Type | Description |
---|---|
Union[GeoTensor, ndarray]
|
GeoTensor read from |
Source code in georeader/read.py
334 335 336 337 338 339 340 341 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 |
|
resize(data_in, resolution_dst, window_out=None, anti_aliasing=True, anti_aliasing_sigma=None, resampling=rasterio.warp.Resampling.cubic_spline, return_only_data=False)
¶
Change the spatial resolution of data_in to resolution_dst
. This function is a wrapper of the read_reproject
function
that adds anti_aliasing before reprojecting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_in
|
GeoData
|
GeoData to change the resolution. Expected coords "x" and "y". |
required |
resolution_dst
|
Union[float, Tuple[float, float]]
|
spatial resolution in data_in crs |
required |
window_out
|
Optional[Window]
|
Optional. output size of the fragment to read and reproject. Defaults to the ceiling size |
None
|
anti_aliasing
|
bool
|
Whether to apply a Gaussian filter to smooth the image prior to downsampling |
True
|
anti_aliasing_sigma
|
Optional[Union[float, ndarray]]
|
anti_aliasing_sigma : {float}, optional Standard deviation for Gaussian filtering used when anti-aliasing. By default, this value is chosen as (s - 1) / 2 where s is the downsampling factor, where s > 1 |
None
|
resampling
|
Resampling
|
specifies how data is reprojected from |
cubic_spline
|
return_only_data
|
bool
|
defaults to |
False
|
Returns:
Type | Description |
---|---|
Union[GeoTensor, ndarray]
|
GeoTensor with spatial resolution |
Source code in georeader/read.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 |
|
read_reproject(data_in, dst_crs=None, bounds=None, resolution_dst_crs=None, dst_transform=None, window_out=None, resampling=rasterio.warp.Resampling.cubic_spline, dtype_dst=None, return_only_data=False, dst_nodata=None)
¶
This function slices the data by the bounds and reprojects it to the dst_crs and resolution_dst_crs
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_in
|
GeoData
|
GeoData to read and reproject. Expected coords "x" and "y". |
required |
bounds
|
Optional[Tuple[float, float, float, float]]
|
Optional. bounds in CRS specified by |
None
|
dst_crs
|
Optional[str]
|
CRS to reproject. |
None
|
resolution_dst_crs
|
Optional[Union[float, Tuple[float, float]]]
|
resolution in the CRS specified by |
None
|
dst_transform
|
Optional[Affine]
|
Optional dest transform. If not provided the dst_transform is a rectilinear transform computed with the bounds and resolution_dst_crs. |
None
|
window_out
|
Optional[Window]
|
Window out to read w.r.t |
None
|
resampling
|
Resampling
|
specifies how data is reprojected from |
cubic_spline
|
dtype_dst
|
Any
|
if None it will be data_in.dtype |
None
|
return_only_data
|
bool
|
defaults to |
False
|
dst_nodata
|
Optional[int]
|
dst_nodata value |
None
|
Returns:
Type | Description |
---|---|
Union[GeoTensor, ndarray]
|
GeoTensor reprojected to dst_crs with resolution_dst_crs |
Source code in georeader/read.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 |
|
read_rpcs(input_npy, rpcs, fill_value_default=0, dst_crs=None, resolution_dst_crs=None, resampling=rasterio.warp.Resampling.cubic_spline, return_only_data=False)
¶
This function georreferences an array using the RPCs. The RPCs are used to compute the transform from the input array to the destination crs.
This function assumes that the RPCs are in EPSG:4326.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_npy
|
NDArray
|
Array to georeference. It must have 2, 3 or 4 dimensions. |
required |
rpcs
|
RPC
|
RPCs to compute the transform. |
required |
fill_value_default
|
int
|
how to encode the nodata value. Defaults to 0. |
0
|
dst_crs
|
Optional[Any]
|
Destination crs. Defaults to None. If None, the dst_crs is the same as in the RPC polynomial (EPSG:4326). |
None
|
resampling
|
Resampling
|
Resampling method. Defaults to rasterio.warp.Resampling.cubic_spline. |
cubic_spline
|
return_only_data
|
bool
|
If True it returns only the data. Defaults to False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
GeoTensor |
GeoTensor
|
GeoTensor with the georeferenced array based on the RPCs. |
Source code in georeader/read.py
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 |
|
window_from_bounds(data_in, bounds, crs_bounds=None)
¶
Compute window to read in data_in from bounds in crs_bounds. If crs_bounds is None it assumes bounds are in the crs of data_in
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_in
|
Union[GeoData, DatasetReader]
|
Reader with crs and transform attributes |
required |
bounds
|
Tuple[float, float, float, float]
|
tuple with bounds to find the corresponding window |
required |
crs_bounds
|
Optional[str]
|
Optional coordinate reference system of the bounds. If not provided assumes same crs as |
None
|
Returns:
Type | Description |
---|---|
Window
|
Window object with location in pixel coordinates relative to |
Source code in georeader/read.py
93 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 |
|
window_from_center_coords(data_in, center_coords, shape, crs_center_coords=None)
¶
Compute window to read in data_in
from the coordinates of the center pixel. If crs_center_coords
is None it assumes
center_coords
are in the crs of data_in
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_in
|
Union[GeoData, DatasetReader]
|
Reader with crs and transform attributes |
required |
center_coords
|
Tuple[float, float]
|
Tuple with center coords (x, y) format |
required |
shape
|
Tuple[int, int]
|
Tuple with shape to read (H, W) format |
required |
crs_center_coords
|
Optional[Any]
|
Optional coordinate reference system of the bounds. If not provided assumes same crs as |
None
|
Returns:
Type | Description |
---|---|
Window
|
Window object with location in pixel coordinates relative to |
Source code in georeader/read.py
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 |
|
window_from_polygon(data_in, polygon, crs_polygon=None, window_surrounding=False)
¶
Obtains the data window that surrounds the polygon
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_in
|
Union[GeoData, DatasetReader]
|
Reader with crs and transform attributes |
required |
polygon
|
Union[Polygon, MultiPolygon]
|
Polygon or MultiPolygon |
required |
crs_polygon
|
Optional[str]
|
Optional coordinate reference system of the bounds. If not provided assumes same crs as |
None
|
window_surrounding
|
bool
|
The window surrounds the polygon. (i.e. window.row_off + window.height will not be a vertex) |
False
|
Returns:
Type | Description |
---|---|
Window
|
Window object with location in pixel coordinates relative to |
Source code in georeader/read.py
41 42 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
window_from_tile(data_in, x, y, z)
¶
Returns the window corresponding to the x,y,z tile in the data_in.
Tiles are TMS tiles defined as: (https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_in
|
Union[GeoData, DatasetReader]
|
GeoData object |
required |
x
|
int
|
x coordinate of the tile in the TMS system. |
required |
y
|
int
|
y coordinate of the tile in the TMS system. |
required |
z
|
int
|
z coordinate of the tile in the TMS system. |
required |
Returns:
Type | Description |
---|---|
Window
|
rasterio.windows.Window: window corresponding to the tile |
Source code in georeader/read.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|