coreutils module¶
build_computed_object_tree(ee_object, layer_name='', opened=False)
¶
Return a tree structure representing an EE object.
The source code was adapted from https://github.com/google/earthengine-jupyter. Credits to Tyler Erickson.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ee_object
|
FeatureCollection | Image | Geometry | Feature
|
The Earth Engine object. |
required |
layer_name
|
str
|
The name of the layer. |
''
|
opened
|
bool
|
Whether to expand the tree. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The node representing the Earth Engine object information. |
Source code in geemap/coreutils.py
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 238 239 240 241 242 | |
check_cmap(cmap)
¶
Check the colormap and return a list of colors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmap
|
str | list[str]
|
The colormap to check. |
required |
Returns:
| Type | Description |
|---|---|
list[str] | str
|
A list of colors. |
Source code in geemap/coreutils.py
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 | |
check_color(in_color)
¶
Checks the input color and returns the corresponding hex color code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_color
|
str | tuple | list
|
Can be a string (e.g., 'red', '#ffff00', 'ffff00', 'ff0') or RGB tuple/list (e.g., (255, 127, 0)). |
required |
Returns:
| Type | Description |
|---|---|
str
|
A hex color code. |
Source code in geemap/coreutils.py
361 362 363 364 365 366 367 368 369 370 371 372 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 | |
create_code_cell(code='', where='below')
¶
Creates a code cell in the IPython Notebook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
Code to fill the new code cell with. |
''
|
where
|
str
|
Where to add the new code cell. It can be one of the following: above, below, at_bottom. |
'below'
|
Source code in geemap/coreutils.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
download_file(url=None, output=None, quiet=False, proxy=None, speed=None, use_cookies=True, verify=True, id=None, fuzzy=False, resume=False, unzip=True, overwrite=False)
¶
Download a file from URL, including Google Drive shared URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str | None
|
Google Drive URL is also supported. |
None
|
output
|
str | None
|
Output filename. Default is basename of URL. |
None
|
quiet
|
bool
|
Suppress terminal output. |
False
|
proxy
|
str | None
|
Proxy. |
None
|
speed
|
float | None
|
Download byte size per second (e.g., 256KB/s = 256 * 1024). |
None
|
use_cookies
|
bool
|
Flag to use cookies. |
True
|
verify
|
bool | str
|
Either a bool, in which case it controls whether the server's TLS certificate is verified, or a string, in which case it must be a path to a CA bundle to use. |
True
|
id
|
str | None
|
Google Drive's file ID. |
None
|
fuzzy
|
bool
|
Fuzzy extraction of Google Drive's file Id. |
False
|
resume
|
bool
|
Resume the download from existing tmp file if possible. |
False
|
unzip
|
bool
|
Unzip the file. |
True
|
overwrite
|
bool
|
Overwrite the file if it already exists. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The output file path. |
Source code in geemap/coreutils.py
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 726 727 | |
ee_initialize(token_name='EARTHENGINE_TOKEN', auth_mode=None, auth_args=None, user_agent_prefix='geemap', project=None, **kwargs)
¶
Authenticates Earth Engine and initialize an Earth Engine session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token_name
|
str
|
The name of the Earth Engine token. Defaults to "EARTHENGINE_TOKEN". In Colab, you can also set a secret named "EE_PROJECT_ID" to initialize Earth Engine. |
'EARTHENGINE_TOKEN'
|
auth_mode
|
str | None
|
The authentication mode, can be one of colab, notebook, localhost, or gcloud. See https://developers.google.com/earth-engine/guides/auth for more details. |
None
|
auth_args
|
dict[str, Any] | None
|
Additional authentication parameters for aa.Authenticate(). Defaults to {}. |
None
|
user_agent_prefix
|
str
|
If set, the prefix (version-less) value used for setting the user-agent string. |
'geemap'
|
project
|
str | None
|
The Google cloud project ID for Earth Engine. |
None
|
kwargs
|
Any
|
Additional parameters for ee.Initialize(). For example, opt_url='https://earthengine-highvolume.googleapis.com' to use the Earth Engine High-Volume platform. |
{}
|
Source code in geemap/coreutils.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 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 | |
geojson_to_ee(geo_json, geodesic=False, encoding='utf-8')
¶
Converts a GeoJSON to an Earth Engine Geometry or FeatureCollection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geo_json
|
dict[str, Any] | str
|
A GeoJSON geometry dictionary or file path. |
required |
geodesic
|
bool
|
Whether line segments should be interpreted as spherical geodesics. If false, indicates that line segments should be interpreted as planar lines in the specified CRS. If absent, defaults to true if the CRS is geographic (including the default EPSG:4326), or to false if the CRS is projected. |
False
|
encoding
|
str
|
The encoding of characters. |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
Geometry | FeatureCollection
|
Earth Engine Geometry or FeatureCollection. |
Raises:
| Type | Description |
|---|---|
Exception
|
If the GeoJSON cannot be converted to an Earth Engine object. |
Source code in geemap/coreutils.py
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 | |
geometry_type(ee_object)
¶
Get geometry type of an Earth Engine object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ee_object
|
Any
|
An Earth Engine object. |
required |
Returns:
| Type | Description |
|---|---|
str
|
One of Point, MultiPoint, LineString, LinearRing, MultiLineString, BBox, Rectangle, Polygon, MultiPolygon. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the ee_object is not one of ee.Geometry, ee.Feature, ee.FeatureCollection. |
Source code in geemap/coreutils.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
get_env_var(key)
¶
Returns an environment variable or Colab secret for the given key.
Colab secrets have precedence over environment variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The key that's used to fetch the environment variable. |
required |
Source code in geemap/coreutils.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | |
get_google_maps_api_key(key='GOOGLE_MAPS_API_KEY')
¶
Returns the Google Maps API key from the environment or Colab user data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
The name of the environment variable or Colab user data key where the API key is stored. |
'GOOGLE_MAPS_API_KEY'
|
Source code in geemap/coreutils.py
344 345 346 347 348 349 350 351 352 353 | |
get_info(ee_object, layer_name='', opened=False, return_node=False)
¶
Print out the information for an Earth Engine object using a tree structure.
The source code was adapted from https://github.com/google/earthengine-jupyter. Credits to Tyler Erickson.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ee_object
|
FeatureCollection | Image | Geometry | Feature
|
The Earth Engine object. |
required |
layer_name
|
str
|
The name of the layer. |
''
|
opened
|
bool
|
Whether to expand the tree. |
False
|
return_node
|
bool
|
Whether to return the widget as ipytree.Node. If False, returns the widget as ipytree.Tree. |
False
|
Returns:
| Type | Description |
|---|---|
|
The tree or node representing the Earth Engine object information. |
Source code in geemap/coreutils.py
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 | |
github_raw_url(url)
¶
Returns the raw URL for a GitHub file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The GitHub URL. |
required |
Source code in geemap/coreutils.py
637 638 639 640 641 642 643 644 645 646 647 | |
hex_to_rgb(value='FFFFFF')
¶
Converts hex color to RGB color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Hex color code as a string. Defaults to 'FFFFFF'. |
'FFFFFF'
|
Returns:
| Type | Description |
|---|---|
tuple[int, int, int]
|
RGB color as a tuple. |
Source code in geemap/coreutils.py
468 469 470 471 472 473 474 475 476 477 478 479 | |
in_colab_shell()
¶
Returns True if the code is running in a Google Colab environment.
Source code in geemap/coreutils.py
356 357 358 | |
new_tree_node(label, children=None, expanded=False, top_level=False)
¶
Returns node JSON for an interactive representation of an EE ComputedObject.
Source code in geemap/coreutils.py
121 122 123 124 125 126 127 128 129 130 131 132 133 | |
open_url(url)
¶
Opens the URL in a new browser tab.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to open. |
required |
Source code in geemap/coreutils.py
625 626 627 628 629 630 631 632 633 634 | |
random_string(string_length=3)
¶
Returns a random string of fixed length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string_length
|
int
|
Fixed length. |
3
|
Source code in geemap/coreutils.py
482 483 484 485 486 487 488 489 | |
rgb_to_hex(rgb=(255, 255, 255))
¶
Converts RGB to hex color.
In RGB color, R stands for Red, G stands for Green, and B stands for Blue, and it ranges from the decimal value of 0 – 255.
Args:
1 | |
Returns:
| Type | Description |
|---|---|
str
|
Hex color code. |
Source code in geemap/coreutils.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
temp_file_path(extension)
¶
Returns a temporary file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extension
|
str
|
The file extension. |
required |
Source code in geemap/coreutils.py
650 651 652 653 654 655 656 657 658 659 660 661 | |
to_hex_colors(colors)
¶
Convert a GEE color palette into hexadecimal color codes.
Can handle mixed formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
colors
|
list[str | tuple[int, int, int]]
|
A list of colors in hex or RGB format. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of hex color codes prefixed with #. |
Source code in geemap/coreutils.py
438 439 440 441 442 443 444 445 446 447 448 449 | |
widget_template(widget=None, opened=True, show_close_button=True, widget_icon='gear', close_button_icon='times', widget_args=None, close_button_args=None, display_widget=None, m=None, position='topright')
¶
Create a widget template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
widget
|
Widget | None
|
The widget to be displayed. |
None
|
opened
|
bool
|
Whether to open the toolbar. |
True
|
show_close_button
|
bool
|
Whether to show the close button. |
True
|
widget_icon
|
str
|
The icon name for the toolbar button. |
'gear'
|
close_button_icon
|
str
|
The icon name for the close button. |
'times'
|
widget_args
|
dict[str, Any] | None
|
Additional arguments to pass to the toolbar button. |
None
|
close_button_args
|
dict[str, Any] | None
|
Additional arguments to pass to the close button. |
None
|
display_widget
|
Widget | None
|
The widget to be displayed when the toolbar is clicked. |
None
|
m
|
Map | None
|
The ipyleaflet.Map instance. |
None
|
position
|
str
|
The position of the toolbar. |
'topright'
|
Returns:
| Type | Description |
|---|---|
Widget | None
|
The created widget template. |
Source code in geemap/coreutils.py
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 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 | |