leafmap module¶
Main module.
GoogleMapsTileProvider
¶
Bases: TileProvider
Google Maps TileProvider.
Source code in leafmap/common.py
19178 19179 19180 19181 19182 19183 19184 19185 19186 19187 19188 19189 19190 19191 19192 19193 19194 19195 19196 19197 19198 19199 19200 19201 19202 19203 19204 19205 19206 19207 19208 19209 19210 19211 19212 19213 19214 19215 19216 19217 19218 19219 19220 19221 19222 19223 19224 19225 19226 19227 19228 19229 19230 19231 19232 19233 19234 19235 19236 19237 19238 19239 19240 19241 19242 19243 19244 19245 19246 19247 19248 19249 19250 19251 19252 19253 19254 19255 19256 19257 19258 19259 19260 19261 19262 19263 19264 19265 19266 19267 19268 19269 19270 19271 19272 19273 19274 19275 19276 19277 19278 19279 | |
__init__(map_type='roadmap', language='en-Us', region='US', api_key=None, **kwargs)
¶
Generates Google Map tiles using the provided parameters. To get an API key
and enable Map Tiles API, visit
https://developers.google.com/maps/get-started#create-project.
You can set the API key using the environment variable
GOOGLE_MAPS_API_KEY or by passing it as an argument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
map_type
|
str
|
The type of map to generate. Options are 'roadmap', 'satellite', 'terrain', 'hybrid', 'traffic', 'streetview'. Defaults to 'roadmap'. |
'roadmap'
|
language
|
str
|
An IETF language tag that specifies the language used to display information on the tiles, such as 'zh-Cn'. Defaults to 'en-Us'. |
'en-Us'
|
region
|
str
|
A Common Locale Data Repository region identifier (two uppercase letters) that represents the physical location of the user. Defaults to 'US'. |
'US'
|
api_key
|
str
|
The API key to use for the Google Maps API. If not provided, it will try to get it from the environment or Colab user data with the key 'GOOGLE_MAPS_API_KEY'. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional parameters to pass to the map generation. For more info, visit https://bit.ly/3UhbZKU |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the API key is not provided and cannot be found in the environment or Colab user data. |
ValueError
|
If the map_type is not one of the allowed types. |
Example
from leafmap.basemaps import GoogleMapsTileProvider m = leafmap.Map() basemap = GoogleMapsTileProvider(map_type='roadmap', language="en-Us", region="US", scale="scaleFactor2x", highDpi=True) m.add_basemap(basemap)
Source code in leafmap/common.py
19194 19195 19196 19197 19198 19199 19200 19201 19202 19203 19204 19205 19206 19207 19208 19209 19210 19211 19212 19213 19214 19215 19216 19217 19218 19219 19220 19221 19222 19223 19224 19225 19226 19227 19228 19229 19230 19231 19232 19233 19234 19235 19236 19237 19238 19239 19240 19241 19242 19243 19244 19245 19246 19247 19248 19249 19250 19251 19252 19253 19254 19255 19256 19257 19258 19259 19260 19261 19262 19263 19264 19265 19266 19267 19268 19269 19270 19271 19272 19273 19274 19275 19276 19277 19278 19279 | |
ImageOverlay
¶
Bases: ImageOverlay
ImageOverlay class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
http URL or local file path to the image. |
required |
bounds
|
tuple
|
bounding box of the image in the format of (lower_left(lat, lon), upper_right(lat, lon)), such as ((13, -130), (32, -100)). |
required |
Source code in leafmap/leafmap.py
6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 | |
Map
¶
Bases: Map
The Map class inherits ipyleaflet.Map. The arguments you can pass to the Map can be found at https://ipyleaflet.readthedocs.io/en/latest/api_reference/map.html. By default, the Map will add OpenStreetMap as the basemap.
Returns:
| Name | Type | Description |
|---|---|---|
object |
ipyleaflet map object. |
Source code in leafmap/leafmap.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 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 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 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 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 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 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 459 460 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 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 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 660 661 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 726 727 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 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 | |
add(obj, index=None, **kwargs)
¶
Adds a layer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
object
|
The layer to add to the map. |
required |
index
|
int
|
The index at which to add the layer. Defaults to None. |
None
|
Source code in leafmap/leafmap.py
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 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
add_basemap(basemap='HYBRID', show=True, **kwargs)
¶
Adds a basemap to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
basemap
|
str
|
Can be one of string from basemaps. Defaults to 'HYBRID'. |
'HYBRID'
|
visible
|
bool
|
Whether the basemap is visible or not. Defaults to True. |
required |
**kwargs
|
Keyword arguments for the TileLayer. |
{}
|
Source code in leafmap/leafmap.py
330 331 332 333 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 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 | |
add_basemap_gui(position='topright')
¶
Add the basemap widget to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
str
|
The position of the widget. Defaults to "topright". |
'topright'
|
Source code in leafmap/leafmap.py
4952 4953 4954 4955 4956 4957 4958 4959 4960 | |
add_bbox(bbox, layer_name='Bounding Box', color='blue', fill_color=None, fill_opacity=0.1, weight=2, **kwargs)
¶
Add a bbox defined by [x_min, y_min, x_max, y_max] to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
Union[List[float], Tuple[float, float, float, float], Sequence[float]]
|
A list or tuple containing four numbers representing the bounding box: [x_min, y_min, x_max, y_max]. Assumed to be in longitude/latitude coordinates. |
required |
layer_name
|
str
|
The name to assign to the GeoJSON layer. Defaults to "Bounding Box". |
'Bounding Box'
|
color
|
str
|
The color of the bounding box outline (stroke). Defaults to "blue". |
'blue'
|
fill_color
|
Optional[str]
|
The fill color of the bounding box. If None, the box will not be filled. Defaults to None. |
None
|
fill_opacity
|
float
|
The opacity of the fill color (only used if fill_color is provided). Value should be between 0.0 and 1.0. Defaults to 0.1. |
0.1
|
weight
|
int
|
The thickness of the bounding box outline (stroke). Defaults to 2. |
2
|
**kwargs
|
Additional keyword arguments to pass directly to the
underlying |
{}
|
Source code in leafmap/leafmap.py
4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 | |
add_census_data(wms, layer, census_dict=None, **kwargs)
¶
Adds a census data layer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wms
|
str
|
The wms to use. For example, "Current", "ACS 2021", "Census 2020". See the complete list at https://tigerweb.geo.census.gov/tigerwebmain/TIGERweb_wms.html |
required |
layer
|
str
|
The layer name to add to the map. |
required |
census_dict
|
dict
|
A dictionary containing census data. Defaults to None. It can be obtained from the get_census_dict() function. |
None
|
Source code in leafmap/leafmap.py
4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 | |
add_circle_markers_from_xy(data, x='lon', y='lat', radius=10, popup=None, font_size=2, stroke=True, color='#0033FF', weight=2, fill=True, fill_color=None, fill_opacity=0.2, opacity=1.0, layer_name='Circle Markers', **kwargs)
¶
Adds a marker cluster to the map. For a list of options, see https://ipyleaflet.readthedocs.io/en/latest/_modules/ipyleaflet/leaflet.html#Path
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | DataFrame
|
A csv or Pandas DataFrame containing x, y, z values. |
required |
x
|
str
|
The column name for the x values. Defaults to "lon". |
'lon'
|
y
|
str
|
The column name for the y values. Defaults to "lat". |
'lat'
|
radius
|
int
|
The radius of the circle. Defaults to 10. |
10
|
popup
|
list
|
A list of column names to be used as the popup. Defaults to None. |
None
|
font_size
|
int
|
The font size of the popup. Defaults to 2. |
2
|
stroke
|
bool
|
Whether to stroke the path. Defaults to True. |
True
|
color
|
str
|
The color of the path. Defaults to "#0033FF". |
'#0033FF'
|
weight
|
int
|
The weight of the path. Defaults to 2. |
2
|
fill
|
bool
|
Whether to fill the path with color. Defaults to True. |
True
|
fill_color
|
str
|
The fill color of the path. Defaults to None. |
None
|
fill_opacity
|
float
|
The fill opacity of the path. Defaults to 0.2. |
0.2
|
opacity
|
float
|
The opacity of the path. Defaults to 1.0. |
1.0
|
layer_name
|
str
|
The layer name to use for the marker cluster. Defaults to "Circle Markers". |
'Circle Markers'
|
Source code in leafmap/leafmap.py
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 | |
add_cog_layer(url, name='Untitled', attribution='', opacity=1.0, shown=True, bands=None, titiler_endpoint=None, zoom_to_layer=True, layer_index=None, overwrite=False, **kwargs)
¶
Adds a COG TileLayer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the COG tile layer. |
required |
name
|
str
|
The layer name to use for the layer. Defaults to 'Untitled'. |
'Untitled'
|
attribution
|
str
|
The attribution to use. Defaults to ''. |
''
|
opacity
|
float
|
The opacity of the layer. Defaults to 1. |
1.0
|
shown
|
bool
|
A flag indicating whether the layer should be on by default. Defaults to True. |
True
|
bands
|
list
|
A list of bands to use for the layer. Defaults to None. |
None
|
titiler_endpoint
|
str
|
TiTiler endpoint. Defaults to "https://giswqs-titiler-endpoint.hf.space". |
None
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer extent. Defaults to True. |
True
|
layer_index
|
int
|
The index at which to add the layer. Defaults to None. |
None
|
overwrite
|
bool
|
Whether to overwrite the layer if it already exists. Defaults to False. |
False
|
**kwargs
|
Arbitrary keyword arguments, including bidx, expression, nodata, unscale, resampling, rescale,
color_formula, colormap, colormap_name, return_mask. See https://developmentseed.org/titiler/endpoints/cog/
and https://cogeotiff.github.io/rio-tiler/colormap/. To select a certain bands, use bidx=[1, 2, 3].
apply a rescaling to multiple bands, use something like |
{}
|
Source code in leafmap/leafmap.py
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 | |
add_colorbar(colors, vmin=0, vmax=1.0, index=None, caption='', categorical=False, step=None, height='45px', transparent_bg=False, position='bottomright', **kwargs)
¶
Add a branca colorbar to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
colors
|
list
|
The set of colors to be used for interpolation. Colors can be provided in the form: * tuples of RGBA ints between 0 and 255 (e.g: (255, 255, 0) or (255, 255, 0, 255)) * tuples of RGBA floats between 0. and 1. (e.g: (1.,1.,0.) or (1., 1., 0., 1.)) * HTML-like string (e.g: “#ffff00) * a color name or shortcut (e.g: “y” or “yellow”) |
required |
vmin
|
int
|
The minimal value for the colormap. Values lower than vmin will be bound directly to colors[0].. Defaults to 0. |
0
|
vmax
|
float
|
The maximal value for the colormap. Values higher than vmax will be bound directly to colors[-1]. Defaults to 1.0. |
1.0
|
index
|
list
|
The values corresponding to each color. It has to be sorted, and have the same length as colors. If None, a regular grid between vmin and vmax is created.. Defaults to None. |
None
|
caption
|
str
|
The caption for the colormap. Defaults to "". |
''
|
categorical
|
bool
|
Whether or not to create a categorical colormap. Defaults to False. |
False
|
step
|
int
|
The step to split the LinearColormap into a StepColormap. Defaults to None. |
None
|
height
|
str
|
The height of the colormap widget. Defaults to "45px". |
'45px'
|
transparent_bg
|
bool
|
Whether to use transparent background for the colormap widget. Defaults to True. |
False
|
position
|
str
|
The position for the colormap widget. Defaults to "bottomright". |
'bottomright'
|
Source code in leafmap/leafmap.py
2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 | |
add_colormap(cmap='gray', colors=None, discrete=False, label=None, width=3, height=0.25, orientation='horizontal', vmin=0, vmax=1.0, axis_off=False, show_name=False, font_size=8, transparent_bg=False, position='bottomright', **kwargs)
¶
Adds a matplotlib colormap to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmap
|
str
|
Matplotlib colormap. Defaults to "gray". See https://matplotlib.org/3.3.4/tutorials/colors/colormaps.html#sphx-glr-tutorials-colors-colormaps-py for options. |
'gray'
|
colors
|
list
|
A list of custom colors to create a colormap. Defaults to None. |
None
|
discrete
|
bool
|
Whether to create a discrete colorbar. Defaults to False. |
False
|
label
|
str
|
Label for the colorbar. Defaults to None. |
None
|
width
|
float
|
The width of the colormap. Defaults to 8.0. |
3
|
height
|
float
|
The height of the colormap. Defaults to 0.4. |
0.25
|
orientation
|
str
|
The orientation of the colormap. Defaults to "horizontal". |
'horizontal'
|
vmin
|
float
|
The minimum value range. Defaults to 0. |
0
|
vmax
|
float
|
The maximum value range. Defaults to 1.0. |
1.0
|
axis_off
|
bool
|
Whether to turn axis off. Defaults to False. |
False
|
show_name
|
bool
|
Whether to show the colormap name. Defaults to False. |
False
|
font_size
|
int
|
Font size of the text. Defaults to 12. |
8
|
transparent_bg
|
bool
|
Whether to use transparent background for the colormap widget. Defaults to True. |
False
|
position
|
str
|
The position for the colormap widget. Defaults to "bottomright". |
'bottomright'
|
Source code in leafmap/leafmap.py
2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 | |
add_data(data, column, colors=None, labels=None, cmap=None, scheme='Quantiles', k=5, add_legend=True, legend_title=None, legend_position='bottomright', legend_kwds=None, classification_kwds=None, layer_name='Untitled', style=None, hover_style=None, style_callback=None, marker_radius=10, marker_args=None, info_mode='on_hover', encoding='utf-8', **kwargs)
¶
Add vector data to the map with a variety of classification schemes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | DataFrame | GeoDataFrame
|
The data to classify. It can be a filepath to a vector dataset, a pandas dataframe, or a geopandas geodataframe. |
required |
column
|
str
|
The column to classify. |
required |
cmap
|
str
|
The name of a colormap recognized by matplotlib. Defaults to None. |
None
|
colors
|
list
|
A list of colors to use for the classification. Defaults to None. |
None
|
labels
|
list
|
A list of labels to use for the legend. Defaults to None. |
None
|
scheme
|
str
|
Name of a choropleth classification scheme (requires mapclassify). Name of a choropleth classification scheme (requires mapclassify). A mapclassify.MapClassifier object will be used under the hood. Supported are all schemes provided by mapclassify (e.g. 'BoxPlot', 'EqualInterval', 'FisherJenks', 'FisherJenksSampled', 'HeadTailBreaks', 'JenksCaspall', 'JenksCaspallForced', 'JenksCaspallSampled', 'MaxP', 'MaximumBreaks', 'NaturalBreaks', 'Quantiles', 'Percentiles', 'StdMean', 'UserDefined'). Arguments can be passed in classification_kwds. |
'Quantiles'
|
k
|
int
|
Number of classes (ignored if scheme is None or if column is categorical). Default to 5. |
5
|
add_legend
|
bool
|
Whether to add a legend to the map. Defaults to True. |
True
|
legend_title
|
str
|
The title of the legend. Defaults to None. |
None
|
legend_position
|
str
|
The position of the legend. Can be 'topleft', 'topright', 'bottomleft', or 'bottomright'. Defaults to 'bottomright'. |
'bottomright'
|
legend_kwds
|
dict
|
Keyword arguments to pass to :func: |
None
|
classification_kwds
|
dict
|
Keyword arguments to pass to mapclassify. Defaults to None. |
None
|
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to None. style is a dictionary of the following form: style = { "stroke": False, "color": "#ff0000", "weight": 1, "opacity": 1, "fill": True, "fillColor": "#ffffff", "fillOpacity": 1.0, "dashArray": "9" "clickable": True, } |
None
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. hover_style is a dictionary of the following form: hover_style = {"weight": style["weight"] + 1, "fillOpacity": 0.5} |
None
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. style_callback is a function that takes the feature as argument and should return a dictionary of the following form: style_callback = lambda feat: {"fillColor": feat["properties"]["color"]} |
None
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
encoding
|
str
|
The encoding of the GeoJSON file. Defaults to "utf-8". |
'utf-8'
|
**kwargs
|
Additional keyword arguments to pass to the GeoJSON class, such as fields, which can be a list of column names to be included in the popup. |
{}
|
Source code in leafmap/leafmap.py
4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 | |
add_ee_layer(ee_object=None, vis_params={}, asset_id=None, name=None, attribution='Google Earth Engine', shown=True, opacity=1.0, **kwargs)
¶
Adds a Google Earth Engine tile layer to the map based on the tile layer URL from https://github.com/opengeos/ee-tile-layers/blob/main/datasets.tsv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ee_object
|
object
|
The Earth Engine object to display. |
None
|
vis_params
|
dict
|
Visualization parameters. For example, {'min': 0, 'max': 100}. |
{}
|
asset_id
|
str
|
The ID of the Earth Engine asset. |
None
|
name
|
str
|
The name of the tile layer. If not provided, the asset ID will be used. Default is None. |
None
|
attribution
|
str
|
The attribution text to be displayed. Default is "Google Earth Engine". |
'Google Earth Engine'
|
shown
|
bool
|
Whether the tile layer should be shown on the map. Default is True. |
True
|
opacity
|
float
|
The opacity of the tile layer. Default is 1.0. |
1.0
|
**kwargs
|
Additional keyword arguments to be passed to the underlying |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/leafmap.py
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 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 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
add_gdf(gdf, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=None, info_mode='on_hover', zoom_to_layer=False, encoding='utf-8', **kwargs)
¶
Adds a GeoDataFrame to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
A GeoPandas GeoDataFrame. |
required |
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
None
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer. Defaults to False. |
False
|
encoding
|
str
|
The encoding of the GeoDataFrame. Defaults to "utf-8". |
'utf-8'
|
Source code in leafmap/leafmap.py
3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 | |
add_gdf_from_postgis(sql, con, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=['black'], info_mode='on_hover', zoom_to_layer=True, **kwargs)
¶
Reads a PostGIS database and returns data as a GeoDataFrame to be added to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sql
|
str
|
SQL query to execute in selecting entries from database, or name of the table to read from the database. |
required |
con
|
Engine
|
Active connection to the database to query. |
required |
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
['black']
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer. |
True
|
Source code in leafmap/leafmap.py
3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 | |
add_geojson(in_geojson, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=None, info_mode='on_hover', zoom_to_layer=False, encoding='utf-8', **kwargs)
¶
Adds a GeoJSON file to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_geojson
|
str | dict
|
The file path or http URL to the input GeoJSON or a dictionary containing the geojson. |
required |
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
None
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer after adding it to the map. Defaults to False. |
False
|
encoding
|
str
|
The encoding of the GeoJSON file. Defaults to "utf-8". |
'utf-8'
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
The provided GeoJSON file could not be found. |
Source code in leafmap/leafmap.py
2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 | |
add_geotiff(url, name='GeoTIFF', attribution='', opacity=1.0, shown=True, bands=None, titiler_endpoint=None, zoom_to_layer=True, layer_index=None, overwrite=False, **kwargs)
¶
Adds a Cloud Optimized GeoTIFF (COG) to the map.
This helper wraps :meth:add_cog_layer so that users can quickly load a
remote GeoTIFF/COG by simply providing its URL. By default it relies on
the TiTiler endpoint configured for the map (the public demo endpoint is
used when none is provided).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The HTTP URL of the GeoTIFF/COG. |
required |
name
|
str
|
Layer name to display in the layer tree.
Defaults to |
'GeoTIFF'
|
attribution
|
str
|
Attribution text for the layer.
Defaults to |
''
|
opacity
|
float
|
Layer opacity between 0.0 and 1.0. Defaults to 1.0. |
1.0
|
shown
|
bool
|
Whether the layer should be visible when first added. Defaults to True. |
True
|
bands
|
Sequence[Union[int, str]]
|
Specific band indices (1-based) or band names to render. Defaults to None which lets Leafmap pick sensible defaults. |
None
|
titiler_endpoint
|
str
|
Custom TiTiler endpoint to use. Defaults to the library's configured endpoint. |
None
|
zoom_to_layer
|
bool
|
Whether to fit the map view to the layer bounds after it loads. Defaults to True. |
True
|
layer_index
|
int
|
Stack index at which to insert the layer. Defaults to None (append). |
None
|
overwrite
|
bool
|
When True, an existing layer with the same name is replaced. Defaults to False. |
False
|
**kwargs
|
Additional keyword arguments forwarded to
:meth: |
{}
|
Source code in leafmap/leafmap.py
2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 | |
add_heatmap(data, latitude='latitude', longitude='longitude', value='value', name='Heat map', radius=25, **kwargs)
¶
Adds a heat map to the map. Reference: https://ipyleaflet.readthedocs.io/en/latest/api_reference/heatmap.html
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | list | DataFrame
|
File path or HTTP URL to the input file or a list of data points in the format of [[x1, y1, z1], [x2, y2, z2]]. For example, https://raw.githubusercontent.com/opengeos/leafmap/master/examples/data/world_cities.csv |
required |
latitude
|
str
|
The column name of latitude. Defaults to "latitude". |
'latitude'
|
longitude
|
str
|
The column name of longitude. Defaults to "longitude". |
'longitude'
|
value
|
str
|
The column name of values. Defaults to "value". |
'value'
|
name
|
str
|
Layer name to use. Defaults to "Heat map". |
'Heat map'
|
radius
|
int
|
Radius of each “point” of the heatmap. Defaults to 25. |
25
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If data is not a list. |
Source code in leafmap/leafmap.py
3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 | |
add_html(html, position='bottomright', **kwargs)
¶
Add HTML to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
html
|
str
|
The HTML to add. |
required |
position
|
str
|
The position of the HTML, can be one of "topleft", "topright", "bottomleft", "bottomright". Defaults to "bottomright". |
'bottomright'
|
Source code in leafmap/leafmap.py
4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 | |
add_image(image, position='bottomright', **kwargs)
¶
Add an image to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
str | Image
|
The image to add. |
required |
position
|
str
|
The position of the image, can be one of "topleft", "topright", "bottomleft", "bottomright". Defaults to "bottomright". |
'bottomright'
|
Source code in leafmap/leafmap.py
4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 | |
add_inspector_gui(position='topright', opened=True)
¶
Add the Inspector widget to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
str
|
The position of the widget. Defaults to "topright". |
'topright'
|
opened
|
bool
|
Whether the widget is open. Defaults to True. |
True
|
Source code in leafmap/leafmap.py
4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 | |
add_kml(in_kml, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=None, info_mode='on_hover', **kwargs)
¶
Adds a KML file to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_kml
|
str
|
The input file path or HTTP URL to the KML. |
required |
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
None
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
The provided KML file could not be found. |
Source code in leafmap/leafmap.py
3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 | |
add_labels(data, column, font_size='12pt', font_color='black', font_family='arial', font_weight='normal', x='longitude', y='latitude', draggable=True, layer_name='Labels', **kwargs)
¶
Adds a label layer to the map. Reference: https://ipyleaflet.readthedocs.io/en/latest/api_reference/divicon.html
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame | GeoDataFrame | str
|
The input data to label. |
required |
column
|
str
|
The column name of the data to label. |
required |
font_size
|
str
|
The font size of the labels. Defaults to "12pt". |
'12pt'
|
font_color
|
str
|
The font color of the labels. Defaults to "black". |
'black'
|
font_family
|
str
|
The font family of the labels. Defaults to "arial". |
'arial'
|
font_weight
|
str
|
The font weight of the labels, can be normal, bold. Defaults to "normal". |
'normal'
|
x
|
str
|
The column name of the longitude. Defaults to "longitude". |
'longitude'
|
y
|
str
|
The column name of the latitude. Defaults to "latitude". |
'latitude'
|
draggable
|
bool
|
Whether the labels are draggable. Defaults to True. |
True
|
layer_name
|
str
|
Layer name to use. Defaults to "Labels". |
'Labels'
|
Source code in leafmap/leafmap.py
3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 | |
add_layer(layer)
¶
Adds a layer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
ipyleaflet layer
|
The layer to be added. |
required |
Source code in leafmap/leafmap.py
430 431 432 433 434 435 436 437 438 439 | |
add_layer_control(position='topright')
¶
Adds a layer control to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
str
|
The position of the layer control. Defaults to 'topright'. |
'topright'
|
Source code in leafmap/leafmap.py
511 512 513 514 515 516 517 518 | |
add_layer_manager(position='topright', opened=True)
¶
Add the Layer Manager to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
str
|
The position of the Layer Manager. Defaults to "topright". |
'topright'
|
Source code in leafmap/leafmap.py
4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 | |
add_legend(title='Legend', legend_dict=None, labels=None, colors=None, position='bottomright', builtin_legend=None, layer_name=None, shape_type='rectangle', **kwargs)
¶
Adds a customized basemap to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Title of the legend. Defaults to 'Legend'. |
'Legend'
|
legend_dict
|
dict
|
A dictionary containing legend items as keys and color as values. If provided, legend_keys and legend_colors will be ignored. Defaults to None. |
None
|
labels
|
list
|
A list of legend keys. Defaults to None. |
None
|
colors
|
list
|
A list of legend colors. Defaults to None. |
None
|
position
|
str
|
Position of the legend. Defaults to 'bottomright'. |
'bottomright'
|
builtin_legend
|
str
|
Name of the builtin legend to add to the map. Defaults to None. |
None
|
layer_name
|
str
|
Layer name of the legend to be associated with. Defaults to None. |
None
|
Source code in leafmap/leafmap.py
1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 | |
add_marker(location, **kwargs)
¶
Adds a marker to the map. More info about marker at https://ipyleaflet.readthedocs.io/en/latest/api_reference/marker.html.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
list | tuple
|
The location of the marker in the format of [lat, lng]. |
required |
**kwargs
|
Keyword arguments for the marker. |
{}
|
Source code in leafmap/leafmap.py
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
add_markers(markers, x='lon', y='lat', radius=10, popup=None, font_size=2, stroke=True, color='#0033FF', weight=2, fill=True, fill_color=None, fill_opacity=0.2, opacity=1.0, shape='circle', layer_name='Markers', **kwargs)
¶
Adds markers to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
markers
|
Union[List[List[Union[int, float]]], List[Union[int, float]]]
|
List of markers. Each marker can be defined as a list of [x, y] coordinates or as a single [x, y] coordinate. |
required |
x
|
str
|
Name of the x-coordinate column in the marker data. Defaults to "lon". |
'lon'
|
y
|
str
|
Name of the y-coordinate column in the marker data. Defaults to "lat". |
'lat'
|
radius
|
int
|
Radius of the markers. Defaults to 10. |
10
|
popup
|
str
|
Popup text for the markers. Defaults to None. |
None
|
font_size
|
int
|
Font size of the popup text. Defaults to 2. |
2
|
stroke
|
bool
|
Whether to display marker stroke. Defaults to True. |
True
|
color
|
str
|
Color of the marker stroke. Defaults to "#0033FF". |
'#0033FF'
|
weight
|
int
|
Weight of the marker stroke. Defaults to 2. |
2
|
fill
|
bool
|
Whether to fill markers. Defaults to True. |
True
|
fill_color
|
str
|
Fill color of the markers. Defaults to None. |
None
|
fill_opacity
|
float
|
Opacity of the marker fill. Defaults to 0.2. |
0.2
|
opacity
|
float
|
Opacity of the markers. Defaults to 1.0. |
1.0
|
shape
|
str
|
Shape of the markers. Options are "circle" or "marker". Defaults to "circle". |
'circle'
|
layer_name
|
str
|
Name of the marker layer. Defaults to "Markers". |
'Markers'
|
**kwargs
|
Additional keyword arguments to pass to the marker plotting function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
This function does not return any value. |
Source code in leafmap/leafmap.py
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 | |
add_minimap(zoom=5, position='bottomright')
¶
Adds a minimap (overview) to the ipyleaflet map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zoom
|
int
|
Initial map zoom level. Defaults to 5. |
5
|
position
|
str
|
Position of the minimap. Defaults to "bottomright". |
'bottomright'
|
Source code in leafmap/leafmap.py
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 | |
add_mosaic_layer(url=None, titiler_endpoint=None, name='Mosaic Layer', attribution='', opacity=1.0, shown=True, **kwargs)
¶
Adds a STAC TileLayer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
HTTP URL to a MosaicJSON. |
None
|
titiler_endpoint
|
str
|
TiTiler endpoint, e.g., "https://giswqs-titiler-endpoint.hf.space". Defaults to None. |
None
|
name
|
str
|
The layer name to use for the layer. Defaults to 'Mosaic Layer'. |
'Mosaic Layer'
|
attribution
|
str
|
The attribution to use. Defaults to ''. |
''
|
opacity
|
float
|
The opacity of the layer. Defaults to 1. |
1.0
|
shown
|
bool
|
A flag indicating whether the layer should be on by default. Defaults to True. |
True
|
Source code in leafmap/leafmap.py
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 | |
add_netcdf(filename, variables=None, palette=None, vmin=None, vmax=None, nodata=None, attribution=None, layer_name='NetCDF layer', shift_lon=True, lat='lat', lon='lon', lev='lev', level_index=0, time=0, **kwargs)
¶
Generate an ipyleaflet/folium TileLayer from a netCDF file. If you are using this function in JupyterHub on a remote server (e.g., Binder, Microsoft Planetary Computer), try adding to following two lines to the beginning of the notebook if the raster does not render properly.
1 2 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
File path or HTTP URL to the netCDF file. |
required |
variables
|
int
|
The variable/band names to extract data from the netCDF file. Defaults to None. If None, all variables will be extracted. |
None
|
port
|
str
|
The port to use for the server. Defaults to "default". |
required |
palette
|
str
|
The name of the color palette from |
None
|
vmin
|
float
|
The minimum value to use when colormapping the palette when plotting a single band. Defaults to None. |
None
|
vmax
|
float
|
The maximum value to use when colormapping the palette when plotting a single band. Defaults to None. |
None
|
nodata
|
float
|
The value from the band to use to interpret as not valid data. Defaults to None. |
None
|
attribution
|
str
|
Attribution for the source raster. This defaults to a message about it being a local file.. Defaults to None. |
None
|
layer_name
|
str
|
The layer name to use. Defaults to "netCDF layer". |
'NetCDF layer'
|
shift_lon
|
bool
|
Flag to shift longitude values from [0, 360] to the range [-180, 180]. Defaults to True. |
True
|
lat
|
str
|
Name of the latitude variable. Defaults to 'lat'. |
'lat'
|
lon
|
str
|
Name of the longitude variable. Defaults to 'lon'. |
'lon'
|
lev
|
str
|
Name of the level variable. Defaults to 'lev'. |
'lev'
|
level_index
|
int
|
Index of level to use. Defaults to 0'. |
0
|
time
|
int
|
Index of time to use. Defaults to 0'. |
0
|
Source code in leafmap/leafmap.py
2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 | |
add_nlcd(years=[2023], add_legend=True, **kwargs)
¶
Adds National Land Cover Database (NLCD) data to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
years
|
list
|
A list of years to add. It can be any of 1985-2023. Defaults to [2023]. |
[2023]
|
add_legend
|
bool
|
Whether to add a legend to the map. Defaults to True. |
True
|
**kwargs
|
Additional keyword arguments to pass to the add_cog_layer method. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/leafmap.py
6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 | |
add_nlcd_ts(left_year=1985, right_layer=2023, widget_width='70px', add_legend=True, add_layer_control=True, **kwargs)
¶
Adds a time series comparison of NLCD (National Land Cover Database) layers to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left_year
|
int
|
The initial year for the left layer. Defaults to 1985. |
1985
|
right_layer
|
int
|
The initial year for the right layer. Defaults to 2023. |
2023
|
widget_width
|
str
|
The width of the dropdown widgets. Defaults to "70px". |
'70px'
|
add_legend
|
bool
|
If True, adds a legend to the map. Defaults to True. |
True
|
add_layer_control
|
bool
|
If True, adds a layer control to the map. Defaults to True. |
True
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the cog_tile function. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/leafmap.py
6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 | |
add_nwi(data, col_name='WETLAND_TY', add_legend=True, style_callback=None, layer_name='Wetlands', **kwargs)
¶
Adds National Wetlands Inventory (NWI) data to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[str, GeoDataFrame]
|
The NWI data to add. It can be a file path or a GeoDataFrame. |
required |
col_name
|
str
|
The column name in the GeoDataFrame that contains the wetland types. |
'WETLAND_TY'
|
add_legend
|
bool
|
Whether to add a legend to the map. Defaults to True. |
True
|
style_callback
|
Optional[Callable[[dict], dict]]
|
A callback function to style the features. Defaults to None. |
None
|
layer_name
|
str
|
The name of the layer to add. Defaults to "Wetlands". |
'Wetlands'
|
**kwargs
|
Additional keyword arguments to pass to the add_vector or add_gdf method. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/leafmap.py
5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 | |
add_oam_gui(position='topright', opened=True)
¶
Add the OpenAerialMap search widget to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
str
|
The position of the widget. Defaults to "topright". |
'topright'
|
opened
|
bool
|
Whether the widget is open. Defaults to True. |
True
|
Source code in leafmap/leafmap.py
4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 | |
add_opacity_control(layer=None, position='topright', min_opacity=0.0, max_opacity=1.0, step=0.05)
¶
Adds an interactive opacity control panel to the map.
The panel provides a dropdown to choose from the map layers that expose
an opacity attribute and a slider to adjust the selected layer's
transparency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer
|
str | Layer
|
Layer (or layer name) to select initially. Defaults to the first available layer. |
None
|
position
|
str
|
Location for the widget control.
Defaults to |
'topright'
|
min_opacity
|
float
|
Minimum slider value. Defaults to 0.0. |
0.0
|
max_opacity
|
float
|
Maximum slider value. Defaults to 1.0. |
1.0
|
step
|
float
|
Slider step size. Defaults to 0.05. |
0.05
|
Source code in leafmap/leafmap.py
2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 | |
add_osm_from_address(address, tags, dist=1000, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=None, info_mode='on_hover')
¶
Adds OSM entities within some distance N, S, E, W of address to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
The address to geocode and use as the central point around which to get the geometries. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
dist
|
int
|
Distance in meters. Defaults to 1000. |
1000
|
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
None
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
Source code in leafmap/leafmap.py
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 | |
add_osm_from_bbox(north, south, east, west, tags, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=None, info_mode='on_hover')
¶
Adds OSM entities within a N, S, E, W bounding box to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
north
|
float
|
Northern latitude of bounding box. |
required |
south
|
float
|
Southern latitude of bounding box. |
required |
east
|
float
|
Eastern longitude of bounding box. |
required |
west
|
float
|
Western longitude of bounding box. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
None
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
Source code in leafmap/leafmap.py
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 | |
add_osm_from_geocode(query, which_result=None, by_osmid=False, buffer_dist=None, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=None, info_mode='on_hover')
¶
Adds OSM data of place(s) by name or ID to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str | dict | list
|
Query string(s) or structured dict(s) to geocode. |
required |
which_result
|
int
|
Which geocoding result to use. if None, auto-select the first (Multi)Polygon or raise an error if OSM doesn't return one. to get the top match regardless of geometry type, set which_result=1. Defaults to None. |
None
|
by_osmid
|
bool
|
If True, handle query as an OSM ID for lookup rather than text search. Defaults to False. |
False
|
buffer_dist
|
float
|
Distance to buffer around the place geometry, in meters. Defaults to None. |
None
|
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
None
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
Source code in leafmap/leafmap.py
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | |
add_osm_from_place(query, tags, which_result=None, buffer_dist=None, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=None, info_mode='on_hover')
¶
Adds OSM entities within boundaries of geocodable place(s) to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str | dict | list
|
Query string(s) or structured dict(s) to geocode. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
which_result
|
int
|
Which geocoding result to use. if None, auto-select the first (Multi)Polygon or raise an error if OSM doesn't return one. to get the top match regardless of geometry type, set which_result=1. Defaults to None. |
None
|
buffer_dist
|
float
|
Distance to buffer around the place geometry, in meters. Defaults to None. |
None
|
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
None
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
Source code in leafmap/leafmap.py
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 820 821 822 823 824 825 826 827 828 829 830 831 832 | |
add_osm_from_point(center_point, tags, dist=1000, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=None, info_mode='on_hover')
¶
Adds OSM entities within some distance N, S, E, W of a point to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center_point
|
tuple
|
The (lat, lng) center point around which to get the geometries. |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
dist
|
int
|
Distance in meters. Defaults to 1000. |
1000
|
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
None
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
Source code in leafmap/leafmap.py
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 | |
add_osm_from_polygon(polygon, tags, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=None, info_mode='on_hover')
¶
Adds OSM entities within boundaries of a (multi)polygon to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polygon
|
Polygon | MultiPolygon
|
Geographic boundaries to fetch geometries within |
required |
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
None
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
Source code in leafmap/leafmap.py
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 | |
add_osm_from_view(tags, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=None, info_mode='on_hover')
¶
Adds OSM entities within the current map view to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tags
|
dict
|
Dict of tags used for finding objects in the selected area. Results returned are the union, not intersection of each individual tag. Each result matches at least one given tag. The dict keys should be OSM tags, (e.g., building, landuse, highway, etc) and the dict values should be either True to retrieve all items with the given tag, or a string to get a single tag-value combination, or a list of strings to get multiple values for the given tag. For example, tags = {‘building’: True} would return all building footprints in the area. tags = {‘amenity’:True, ‘landuse’:[‘retail’,’commercial’], ‘highway’:’bus_stop’} would return all amenities, landuse=retail, landuse=commercial, and highway=bus_stop. |
required |
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
None
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
Source code in leafmap/leafmap.py
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 | |
add_planet_by_month(year=2016, month=1, layer_name=None, api_key=None, token_name='PLANET_API_KEY', **kwargs)
¶
Adds a Planet global mosaic by month to the map. To get a Planet API key, see https://developers.planet.com/quickstart/apis
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
The year of Planet global mosaic, must be >=2016. Defaults to 2016. |
2016
|
month
|
int
|
The month of Planet global mosaic, must be 1-12. Defaults to 1. |
1
|
layer_name
|
str
|
The layer name to use. Defaults to None. |
None
|
api_key
|
str
|
The Planet API key. Defaults to None. |
None
|
token_name
|
str
|
The environment variable name of the API key. Defaults to "PLANET_API_KEY". |
'PLANET_API_KEY'
|
Source code in leafmap/leafmap.py
3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 | |
add_planet_by_quarter(year=2016, quarter=1, layer_name=None, api_key=None, token_name='PLANET_API_KEY', **kwargs)
¶
Adds a Planet global mosaic by quarter to the map. To get a Planet API key, see https://developers.planet.com/quickstart/apis
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
The year of Planet global mosaic, must be >=2016. Defaults to 2016. |
2016
|
quarter
|
int
|
The quarter of Planet global mosaic, must be 1-12. Defaults to 1. |
1
|
layer_name
|
str
|
The layer name to use. Defaults to None. |
None
|
api_key
|
str
|
The Planet API key. Defaults to None. |
None
|
token_name
|
str
|
The environment variable name of the API key. Defaults to "PLANET_API_KEY". |
'PLANET_API_KEY'
|
Source code in leafmap/leafmap.py
3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 | |
add_pmtiles(url, style=None, name='PMTiles', show=True, zoom_to_layer=True, **kwargs)
¶
Adds a PMTiles layer to the map. This function is not officially supported yet by ipyleaflet yet. Install it with the following command: pip install git+https://github.com/giswqs/ipyleaflet.git@pmtiles
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the PMTiles file. |
required |
style
|
str
|
The CSS style to apply to the layer. Defaults to None. See https://docs.mapbox.com/style-spec/reference/layers/ for more info. |
None
|
name
|
str
|
The name of the layer. Defaults to None. |
'PMTiles'
|
show
|
bool
|
Whether the layer should be shown initially. Defaults to True. |
True
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer extent. Defaults to True. |
True
|
**kwargs
|
Additional keyword arguments to pass to the PMTilesLayer constructor. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/leafmap.py
654 655 656 657 658 659 660 661 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 | |
add_point_layer(filename, popup=None, layer_name='Marker Cluster', **kwargs)
¶
Adds a point layer to the map with a popup attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
str, http url, path object or file-like object. Either the absolute or relative path to the file or URL to be opened, or any object with a read() method (such as an open file or StringIO) |
required |
popup
|
str | list
|
Column name(s) to be used for popup. Defaults to None. |
None
|
layer_name
|
str
|
A layer name to use. Defaults to "Marker Cluster". |
'Marker Cluster'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the specified column name does not exist. |
ValueError
|
If the specified column names do not exist. |
Source code in leafmap/leafmap.py
3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 | |
add_points_from_xy(data, x='longitude', y='latitude', popup=None, layer_name='Marker Cluster', color_column=None, marker_colors=None, icon_colors=['white'], icon_names=['info'], spin=False, add_legend=True, max_cluster_radius=80, **kwargs)
¶
Adds a marker cluster to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | DataFrame
|
A csv or Pandas DataFrame containing x, y, z values. |
required |
x
|
str
|
The column name for the x values. Defaults to "longitude". |
'longitude'
|
y
|
str
|
The column name for the y values. Defaults to "latitude". |
'latitude'
|
popup
|
list
|
A list of column names to be used as the popup. Defaults to None. |
None
|
layer_name
|
str
|
The name of the layer. Defaults to "Marker Cluster". |
'Marker Cluster'
|
color_column
|
str
|
The column name for the color values. Defaults to None. |
None
|
marker_colors
|
list
|
A list of colors to be used for the markers. Defaults to None. |
None
|
icon_colors
|
list
|
A list of colors to be used for the icons. Defaults to ['white']. |
['white']
|
icon_names
|
list
|
A list of names to be used for the icons. More icons can be found at https://fontawesome.com/v4/icons. Defaults to ['info']. |
['info']
|
spin
|
bool
|
If True, the icon will spin. Defaults to False. |
False
|
add_legend
|
bool
|
If True, a legend will be added to the map. Defaults to True. |
True
|
max_cluster_radius
|
int
|
The maximum cluster radius. Defaults to 80. |
80
|
**kwargs
|
Other keyword arguments to pass to ipyleaflet.MarkerCluster(). For a list of available options, see https://github.com/Leaflet/Leaflet.markercluster. |
{}
|
Source code in leafmap/leafmap.py
3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 | |
add_raster(source, indexes=None, colormap=None, vmin=None, vmax=None, nodata=None, attribution=None, layer_name='Raster', layer_index=None, zoom_to_layer=True, visible=True, opacity=1.0, array_args={}, client_args={'cors_all': False}, overwrite=False, **kwargs)
¶
Add a local raster dataset to the map.
If you are using this function in JupyterHub on a remote server (e.g., Binder, Microsoft Planetary Computer) and
if the raster does not render properly, try installing jupyter-server-proxy using pip install jupyter-server-proxy,
then running the following code before calling this function. For more info, see https://bit.ly/3JbmF93.
1 2 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
The path to the GeoTIFF file or the URL of the Cloud Optimized GeoTIFF. |
required |
indexes
|
int
|
The band(s) to use. Band indexing starts at 1. Defaults to None. |
None
|
colormap
|
str
|
The name of the colormap from |
None
|
vmin
|
float
|
The minimum value to use when colormapping the palette when plotting a single band. Defaults to None. |
None
|
vmax
|
float
|
The maximum value to use when colormapping the palette when plotting a single band. Defaults to None. |
None
|
nodata
|
float
|
The value from the band to use to interpret as not valid data. Defaults to None. |
None
|
attribution
|
str
|
Attribution for the source raster. This defaults to a message about it being a local file.. Defaults to None. |
None
|
layer_name
|
str
|
The layer name to use. Defaults to 'Raster'. |
'Raster'
|
layer_index
|
int
|
The index of the layer. Defaults to None. |
None
|
zoom_to_layer
|
bool
|
Whether to zoom to the extent of the layer. Defaults to True. |
True
|
visible
|
bool
|
Whether the layer is visible. Defaults to True. |
True
|
opacity
|
float
|
The opacity of the layer. Defaults to 1.0. |
1.0
|
array_args
|
dict
|
Additional arguments to pass to |
{}
|
client_args
|
dict
|
Additional arguments to pass to localtileserver.TileClient. Defaults to { "cors_all": False }. |
{'cors_all': False}
|
overwrite
|
bool
|
Whether to overwrite an existing layer with the same name. Defaults to False. |
False
|
Source code in leafmap/leafmap.py
2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 | |
add_remote_tile(source, band=None, palette=None, vmin=None, vmax=None, nodata=None, attribution=None, layer_name=None, **kwargs)
¶
Add a remote Cloud Optimized GeoTIFF (COG) to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
The path to the remote Cloud Optimized GeoTIFF. |
required |
band
|
int
|
The band to use. Band indexing starts at 1. Defaults to None. |
None
|
palette
|
str
|
The name of the color palette from |
None
|
vmin
|
float
|
The minimum value to use when colormapping the palette when plotting a single band. Defaults to None. |
None
|
vmax
|
float
|
The maximum value to use when colormapping the palette when plotting a single band. Defaults to None. |
None
|
nodata
|
float
|
The value from the band to use to interpret as not valid data. Defaults to None. |
None
|
attribution
|
str
|
Attribution for the source raster. This defaults to a message about it being a local file.. Defaults to None. |
None
|
layer_name
|
str
|
The layer name to use. Defaults to None. |
None
|
Source code in leafmap/leafmap.py
2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 | |
add_search_control(url, marker=None, zoom=None, position='topleft', **kwargs)
¶
Adds a search control to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The url to the search API. For example, "https://nominatim.openstreetmap.org/search?format=json&q={s}". |
required |
marker
|
Marker
|
The marker to be used for the search result. Defaults to None. |
None
|
zoom
|
int
|
The zoom level to be used for the search result. Defaults to None. |
None
|
position
|
str
|
The position of the search control. Defaults to "topleft". |
'topleft'
|
kwargs
|
dict
|
Additional keyword arguments to be passed to the search control. See https://ipyleaflet.readthedocs.io/en/latest/api_reference/search_control.html |
{}
|
Source code in leafmap/leafmap.py
3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 | |
add_shp(in_shp, layer_name='Untitled', style={}, hover_style={}, style_callback=None, fill_colors=None, info_mode='on_hover', zoom_to_layer=False, encoding='utf-8', **kwargs)
¶
Adds a shapefile to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_shp
|
str
|
The input file path or HTTP URL (*.zip) to the shapefile. |
required |
layer_name
|
str
|
The layer name to be used.. Defaults to "Untitled". |
'Untitled'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
None
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer after adding it to the map. Defaults to False. |
False
|
encoding
|
str
|
The encoding of the shapefile. Defaults to "utf-8". |
'utf-8'
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
The provided shapefile could not be found. |
Source code in leafmap/leafmap.py
2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 | |
add_stac_gui(position='topright', opened=True)
¶
Add the STAC search widget to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
str
|
The position of the widget. Defaults to "topright". |
'topright'
|
opened
|
bool
|
Whether the widget is open. Defaults to True. |
True
|
Source code in leafmap/leafmap.py
4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 | |
add_stac_layer(url=None, collection=None, item=None, assets=None, bands=None, titiler_endpoint=None, name='STAC Layer', attribution='', opacity=1.0, shown=True, fit_bounds=True, layer_index=None, **kwargs)
¶
Adds a STAC TileLayer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
HTTP URL to a STAC item, e.g., https://canada-spot-ortho.s3.amazonaws.com/canada_spot_orthoimages/canada_spot5_orthoimages/S5_2007/S5_11055_6057_20070622/S5_11055_6057_20070622.json |
None
|
collection
|
str
|
The Microsoft Planetary Computer STAC collection ID, e.g., landsat-8-c2-l2. |
None
|
item
|
str
|
The Microsoft Planetary Computer STAC item ID, e.g., LC08_L2SP_047027_20201204_02_T1. |
None
|
assets
|
str | list
|
The Microsoft Planetary Computer STAC asset ID, e.g., ["SR_B7", "SR_B5", "SR_B4"]. |
None
|
bands
|
list
|
A list of band names, e.g., ["SR_B7", "SR_B5", "SR_B4"] |
None
|
titiler_endpoint
|
str
|
TiTiler endpoint, e.g., "https://giswqs-titiler-endpoint.hf.space", "https://planetarycomputer.microsoft.com/api/data/v1", "planetary-computer", "pc". Defaults to None. |
None
|
name
|
str
|
The layer name to use for the layer. Defaults to 'STAC Layer'. |
'STAC Layer'
|
attribution
|
str
|
The attribution to use. Defaults to ''. |
''
|
opacity
|
float
|
The opacity of the layer. Defaults to 1. |
1.0
|
shown
|
bool
|
A flag indicating whether the layer should be on by default. Defaults to True. |
True
|
fit_bounds
|
bool
|
A flag indicating whether the map should be zoomed to the layer extent. Defaults to True. |
True
|
layer_index
|
int
|
The index at which to add the layer. Defaults to None. |
None
|
Source code in leafmap/leafmap.py
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 | |
add_text(text, fontsize=20, fontcolor='black', bold=False, padding='5px', background=True, bg_color='white', border_radius='5px', position='bottomright', **kwargs)
¶
Add text to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to add. |
required |
fontsize
|
int
|
The font size. Defaults to 20. |
20
|
fontcolor
|
str
|
The font color. Defaults to "black". |
'black'
|
bold
|
bool
|
Whether to use bold font. Defaults to False. |
False
|
padding
|
str
|
The padding. Defaults to "5px". |
'5px'
|
background
|
bool
|
Whether to use background. Defaults to True. |
True
|
bg_color
|
str
|
The background color. Defaults to "white". |
'white'
|
border_radius
|
str
|
The border radius. Defaults to "5px". |
'5px'
|
position
|
str
|
The position of the widget. Defaults to "bottomright". |
'bottomright'
|
Source code in leafmap/leafmap.py
4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 | |
add_tile_layer(url, name, attribution, opacity=1.0, shown=True, layer_index=None, **kwargs)
¶
Adds a TileLayer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the tile layer. |
required |
name
|
str
|
The layer name to use for the layer. |
required |
attribution
|
str
|
The attribution to use. |
required |
opacity
|
float
|
The opacity of the layer. Defaults to 1. |
1.0
|
shown
|
bool
|
A flag indicating whether the layer should be on by default. Defaults to True. |
True
|
layer_index
|
int
|
The index at which to add the layer. Defaults to None. |
None
|
Source code in leafmap/leafmap.py
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 | |
add_time_slider(layers={}, labels=None, time_interval=1, position='bottomright', slider_length='150px', zoom_to_layer=False, tile_args=None, **kwargs)
¶
Adds a time slider to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layers
|
dict
|
The dictionary containing a set of XYZ tile layers. |
{}
|
labels
|
list
|
The list of labels to be used for the time series. Defaults to None. |
None
|
time_interval
|
int
|
Time interval in seconds. Defaults to 1. |
1
|
position
|
str
|
Position to place the time slider, can be any of ['topleft', 'topright', 'bottomleft', 'bottomright']. Defaults to "bottomright". |
'bottomright'
|
slider_length
|
str
|
Length of the time slider. Defaults to "150px". |
'150px'
|
zoom_to_layer
|
bool
|
Whether to zoom to the extent of the selected layer. Defaults to False. |
False
|
tile_args
|
dict
|
Additional arguments to pass to the get_local_tile_layer function. Defaults to None. |
None
|
Source code in leafmap/leafmap.py
4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 | |
add_vector(filename, layer_name='Untitled', bbox=None, mask=None, rows=None, style={}, hover_style={}, style_callback=None, fill_colors=None, info_mode='on_hover', zoom_to_layer=False, encoding='utf-8', **kwargs)
¶
Adds any geopandas-supported vector dataset to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
Either the absolute or relative path to the file or URL to be opened, or any object with a read() method (such as an open file or StringIO). |
required |
layer_name
|
str
|
The layer name to use. Defaults to "Untitled". |
'Untitled'
|
bbox
|
tuple | GeoDataFrame or GeoSeries | shapely Geometry
|
Filter features by given bounding box, GeoSeries, GeoDataFrame or a shapely geometry. CRS mis-matches are resolved if given a GeoSeries or GeoDataFrame. Cannot be used with mask. Defaults to None. |
None
|
mask
|
dict | GeoDataFrame or GeoSeries | shapely Geometry
|
Filter for features that intersect with the given dict-like geojson geometry, GeoSeries, GeoDataFrame or shapely geometry. CRS mis-matches are resolved if given a GeoSeries or GeoDataFrame. Cannot be used with bbox. Defaults to None. |
None
|
rows
|
int or slice
|
Load in specific rows by passing an integer (first n rows) or a slice() object.. Defaults to None. |
None
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
None
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
'on_hover'
|
encoding
|
str
|
The encoding to use to read the file. Defaults to "utf-8". |
'utf-8'
|
Source code in leafmap/leafmap.py
3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 | |
add_vector_tile(url, styles={}, layer_name='Vector Tile', **kwargs)
¶
Adds a VectorTileLayer to the map. It wraps the ipyleaflet.VectorTileLayer class. See https://ipyleaflet.readthedocs.io/en/latest/layers/vector_tile.html
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the tile layer |
required |
styles
|
(dict, optional)
|
Style dict, specific to the vector tile source. |
{}
|
layer_name
|
str
|
The layer name to use for the layer. Defaults to 'Vector Tile'. |
'Vector Tile'
|
kwargs
|
Additional keyword arguments to pass to the ipyleaflet.VectorTileLayer class. |
{}
|
Source code in leafmap/leafmap.py
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 | |
add_velocity(data, zonal_speed, meridional_speed, latitude_dimension='lat', longitude_dimension='lon', level_dimension='lev', level_index=0, time_index=0, velocity_scale=0.01, max_velocity=20, display_options={}, name='Velocity', color_scale=None)
¶
Add a velocity layer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | Dataset
|
The data to use for the velocity layer. It can be a file path to a NetCDF file or an xarray Dataset. |
required |
zonal_speed
|
str
|
Name of the zonal speed in the dataset. See https://en.wikipedia.org/wiki/Zonal_and_meridional_flow. |
required |
meridional_speed
|
str
|
Name of the meridional speed in the dataset. See https://en.wikipedia.org/wiki/Zonal_and_meridional_flow. |
required |
latitude_dimension
|
str
|
Name of the latitude dimension in the dataset. Defaults to 'lat'. |
'lat'
|
longitude_dimension
|
str
|
Name of the longitude dimension in the dataset. Defaults to 'lon'. |
'lon'
|
level_dimension
|
str
|
Name of the level dimension in the dataset. Defaults to 'lev'. |
'lev'
|
level_index
|
int
|
The index of the level dimension to display. Defaults to 0. |
0
|
time_index
|
int
|
The index of the time dimension to display. Defaults to 0. |
0
|
velocity_scale
|
float
|
The scale of the velocity. Defaults to 0.01. |
0.01
|
max_velocity
|
int
|
The maximum velocity to display. Defaults to 20. |
20
|
display_options
|
dict
|
The display options for the velocity layer. Defaults to {}. See https://bit.ly/3uf8t6w. |
{}
|
name
|
str
|
Layer name to use . Defaults to 'Velocity'. |
'Velocity'
|
color_scale
|
list
|
List of RGB color values for the velocity vector color scale. Defaults to []. See https://bit.ly/3uf8t6w. |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If the xarray package is not installed. |
ValueError
|
If the data is not a NetCDF file or an xarray Dataset. |
Source code in leafmap/leafmap.py
4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 | |
add_wayback_layer(date=None, name=None, attribution='Esri', quiet=False, **kwargs)
¶
Adds a Wayback layer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
str
|
The date of the layer. Defaults to None. |
None
|
name
|
str
|
The name of the layer. Defaults to None. |
None
|
attribution
|
str
|
The attribution of the layer. Defaults to "Esri". |
'Esri'
|
**kwargs
|
Additional keyword arguments to pass to the add_tile_layer method. |
{}
|
Source code in leafmap/leafmap.py
6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 | |
add_wayback_layers(left_date='2014-02-20', right_date=None, widget_width='120px', add_layer_control=False, **kwargs)
¶
Adds a time series comparison of Wayback (ArcGIS Wayback) layers to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left_date
|
str
|
The initial date for the left layer in "YYYY-MM-DD" format. Defaults to "2014-02-20". |
'2014-02-20'
|
right_date
|
str
|
The initial date for the right layer in "YYYY-MM-DD" format. Defaults to None. |
None
|
widget_width
|
str
|
The width of the date pickers. Defaults to "120px". |
'120px'
|
add_layer_control
|
bool
|
If True, adds a layer control to the map. Defaults to True. |
False
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the cog_tile function. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/leafmap.py
6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 | |
add_wayback_time_slider(**kwargs)
¶
Add a time slider for Wayback layers.
Source code in leafmap/leafmap.py
6318 6319 6320 6321 6322 6323 | |
add_widget(content, position='bottomright', add_header=False, opened=True, show_close_button=True, widget_icon='gear', close_button_icon='times', widget_args={}, close_button_args={}, display_widget=None, **kwargs)
¶
Add a widget (e.g., text, HTML, figure) to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str | Widget | object
|
The widget to add. |
required |
position
|
str
|
The position of the widget. Defaults to "bottomright". |
'bottomright'
|
add_header
|
bool
|
Whether to add a header with close buttons to the widget. Defaults to False. |
False
|
opened
|
bool
|
Whether to open the toolbar. Defaults to True. |
True
|
show_close_button
|
bool
|
Whether to show the close button. Defaults to True. |
True
|
widget_icon
|
str
|
The icon name for the toolbar button. Defaults to 'gear'. |
'gear'
|
close_button_icon
|
str
|
The icon name for the close button. Defaults to "times". |
'times'
|
widget_args
|
dict
|
Additional arguments to pass to the toolbar button. Defaults to {}. |
{}
|
close_button_args
|
dict
|
Additional arguments to pass to the close button. Defaults to {}. |
{}
|
display_widget
|
Widget
|
The widget to be displayed when the toolbar is clicked. |
None
|
**kwargs
|
Additional arguments to pass to the HTML or Output widgets |
{}
|
Source code in leafmap/leafmap.py
4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 | |
add_wms_layer(url, layers, name=None, attribution='', format='image/png', transparent=True, opacity=1.0, shown=True, **kwargs)
¶
Add a WMS layer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the WMS web service. |
required |
layers
|
str
|
Comma-separated list of WMS layers to show. |
required |
name
|
str
|
The layer name to use on the layer control. Defaults to None. |
None
|
attribution
|
str
|
The attribution of the data layer. Defaults to ''. |
''
|
format
|
str
|
WMS image format (use ‘image/png’ for layers with transparency). Defaults to 'image/png'. |
'image/png'
|
transparent
|
bool
|
If True, the WMS service will return images with transparency. Defaults to True. |
True
|
opacity
|
float
|
The opacity of the layer. Defaults to 1.0. |
1.0
|
shown
|
bool
|
A flag indicating whether the layer should be on by default. Defaults to True. |
True
|
Source code in leafmap/leafmap.py
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 | |
add_xy_data(in_csv, x='longitude', y='latitude', label=None, layer_name='Marker cluster')
¶
Adds points from a CSV file containing lat/lon information and display data on the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_csv
|
str
|
The file path to the input CSV file. |
required |
x
|
str
|
The name of the column containing longitude coordinates. Defaults to "longitude". |
'longitude'
|
y
|
str
|
The name of the column containing latitude coordinates. Defaults to "latitude". |
'latitude'
|
label
|
str
|
The name of the column containing label information to used for marker popup. Defaults to None. |
None
|
layer_name
|
str
|
The layer name to use. Defaults to "Marker cluster". |
'Marker cluster'
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
The specified input csv does not exist. |
ValueError
|
The specified x column does not exist. |
ValueError
|
The specified y column does not exist. |
ValueError
|
The specified label column does not exist. |
Source code in leafmap/leafmap.py
3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 | |
add_xyz_service(provider, **kwargs)
¶
Add a XYZ tile layer to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
str
|
A tile layer name starts with xyz or qms. For example, xyz.OpenTopoMap, |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
The provider is not valid. It must start with xyz or qms. |
Source code in leafmap/leafmap.py
4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 | |
basemap_demo()
¶
A demo for using leafmap basemaps.
Source code in leafmap/leafmap.py
1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 | |
batch_edit_lines(data, style=None, hover_style=None, highlight_style=None, changed_style=None, display_props=None, name='GeoJSON', text_width='250px', zoom_to_layer=True, **kwargs)
¶
Batch editing lines on the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[str, GeoDataFrame, Dict[str, Any]]
|
The data to be edited, either as a file path, GeoDataFrame, or GeoJSON dictionary. |
required |
style
|
Optional[Dict[str, Any]]
|
The style dictionary for the polygons. Defaults to None. |
None
|
hover_style
|
Optional[Dict[str, Any]]
|
The hover style dictionary for the polygons. Defaults to None. |
None
|
name
|
str
|
The name of the GeoJSON layer. Defaults to "GeoJSON". |
'GeoJSON'
|
widget_width
|
str
|
The width of the widgets. Defaults to "250px". |
required |
info_mode
|
str
|
The mode for displaying information, either "on_click" or "on_hover". Defaults to "on_click". |
required |
zoom_to_layer
|
bool
|
Whether to zoom to the layer bounds. Defaults to True. |
True
|
**kwargs
|
Any
|
Additional keyword arguments for the GeoJSON layer. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the data is not a GeoDataFrame or a GeoJSON dictionary. |
Source code in leafmap/leafmap.py
5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 | |
batch_edit_points(data, style=None, hover_style=None, changed_style=None, display_props=None, name='Points', text_width='250px', zoom_to_layer=True, **kwargs)
¶
Batch editing points (CircleMarkers) on the map from GeoJSON data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[str, dict]
|
The GeoJSON data or path to the GeoJSON file. |
required |
style
|
Optional[Dict[str, Any]]
|
Style for the CircleMarkers. |
None
|
hover_style
|
Optional[Dict[str, Any]]
|
Style for the CircleMarkers on hover. |
None
|
changed_style
|
Optional[Dict[str, Any]]
|
Style for the CircleMarkers when changed. |
None
|
display_props
|
Optional[List[str]]
|
List of properties to display in the attribute editor. |
None
|
name
|
str
|
Name of the layer group. |
'Points'
|
text_width
|
str
|
Width of the text widgets in the attribute editor. |
'250px'
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer bounds. |
True
|
**kwargs
|
Any
|
Additional keyword arguments for the LayerGroup. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the data is not a GeoDataFrame or a GeoJSON dictionary. |
ValueError
|
If the GeoJSON data does not contain only Point geometries. |
Source code in leafmap/leafmap.py
5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 | |
batch_edit_polygons(data, style=None, hover_style=None, highlight_style=None, changed_style=None, display_props=None, name='GeoJSON', text_width='250px', zoom_to_layer=True, **kwargs)
¶
Batch editing polygons on the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[str, GeoDataFrame, Dict[str, Any]]
|
The data to be edited, either as a file path, GeoDataFrame, or GeoJSON dictionary. |
required |
style
|
Optional[Dict[str, Any]]
|
The style dictionary for the polygons. Defaults to None. |
None
|
hover_style
|
Optional[Dict[str, Any]]
|
The hover style dictionary for the polygons. Defaults to None. |
None
|
name
|
str
|
The name of the GeoJSON layer. Defaults to "GeoJSON". |
'GeoJSON'
|
widget_width
|
str
|
The width of the widgets. Defaults to "250px". |
required |
info_mode
|
str
|
The mode for displaying information, either "on_click" or "on_hover". Defaults to "on_click". |
required |
zoom_to_layer
|
bool
|
Whether to zoom to the layer bounds. Defaults to True. |
True
|
**kwargs
|
Any
|
Additional keyword arguments for the GeoJSON layer. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the data is not a GeoDataFrame or a GeoJSON dictionary. |
Source code in leafmap/leafmap.py
5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 | |
clear_drawings()
¶
Clear drawings on the map.
Source code in leafmap/leafmap.py
4887 4888 4889 4890 4891 4892 | |
edit_lines(data, style=None, hover_style=None, name='GeoJSON', widget_width='250px', info_mode='on_click', zoom_to_layer=True, **kwargs)
¶
Edit lines on the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[str, GeoDataFrame, Dict[str, Any]]
|
The data to be edited, either as a file path, GeoDataFrame, or GeoJSON dictionary. |
required |
style
|
Optional[Dict[str, Any]]
|
The style dictionary for the lines. Defaults to None. |
None
|
hover_style
|
Optional[Dict[str, Any]]
|
The hover style dictionary for the lines. Defaults to None. |
None
|
name
|
str
|
The name of the GeoJSON layer. Defaults to "GeoJSON". |
'GeoJSON'
|
widget_width
|
str
|
The width of the widgets. Defaults to "250px". |
'250px'
|
info_mode
|
str
|
The mode for displaying information, either "on_click" or "on_hover". Defaults to "on_click". |
'on_click'
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer bounds. Defaults to True. |
True
|
**kwargs
|
Any
|
Additional keyword arguments for the GeoJSON layer. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the data is not a GeoDataFrame or a GeoJSON dictionary. |
Source code in leafmap/leafmap.py
5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 | |
edit_points(data, display_props=None, widget_width='250px', name='Points', radius=5, color='white', weight=1, fill_color='#3388ff', fill_opacity=0.6, **kwargs)
¶
Edit points on a map by creating interactive circle markers with popups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[str, GeoDataFrame, Dict[str, Any]]
|
The data source, which can be a file path, GeoDataFrame, or GeoJSON dictionary. |
required |
display_props
|
Optional[List[str]]
|
List of properties to display in the popup. Defaults to None. |
None
|
widget_width
|
str
|
Width of the widget in the popup. Defaults to "250px". |
'250px'
|
name
|
str
|
Name of the layer group. Defaults to "Points". |
'Points'
|
radius
|
int
|
Initial radius of the circle markers. Defaults to 5. |
5
|
color
|
str
|
Outline color of the circle markers. Defaults to "white". |
'white'
|
weight
|
int
|
Outline weight of the circle markers. Defaults to 1. |
1
|
fill_color
|
str
|
Fill color of the circle markers. Defaults to "#3388ff". |
'#3388ff'
|
fill_opacity
|
float
|
Fill opacity of the circle markers. Defaults to 0.6. |
0.6
|
**kwargs
|
Any
|
Additional arguments for the CircleMarker. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/leafmap.py
4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 | |
edit_polygons(data, style=None, hover_style=None, name='GeoJSON', widget_width='250px', info_mode='on_click', zoom_to_layer=True, **kwargs)
¶
Edit polygons on the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[str, GeoDataFrame, Dict[str, Any]]
|
The data to be edited, either as a file path, GeoDataFrame, or GeoJSON dictionary. |
required |
style
|
Optional[Dict[str, Any]]
|
The style dictionary for the polygons. Defaults to None. |
None
|
hover_style
|
Optional[Dict[str, Any]]
|
The hover style dictionary for the polygons. Defaults to None. |
None
|
name
|
str
|
The name of the GeoJSON layer. Defaults to "GeoJSON". |
'GeoJSON'
|
widget_width
|
str
|
The width of the widgets. Defaults to "250px". |
'250px'
|
info_mode
|
str
|
The mode for displaying information, either "on_click" or "on_hover". Defaults to "on_click". |
'on_click'
|
zoom_to_layer
|
bool
|
Whether to zoom to the layer bounds. Defaults to True. |
True
|
**kwargs
|
Any
|
Additional keyword arguments for the GeoJSON layer. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the data is not a GeoDataFrame or a GeoJSON dictionary. |
Source code in leafmap/leafmap.py
5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 | |
edit_vector(data, **kwargs)
¶
Edit a vector layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict | str
|
The data to edit. It can be a GeoJSON dictionary or a file path. |
required |
Source code in leafmap/leafmap.py
4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 | |
find_layer(name)
¶
Finds layer by name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the layer to find. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
object |
ipyleaflet layer object. |
Source code in leafmap/leafmap.py
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | |
find_layer_index(name)
¶
Finds layer index by name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the layer to find. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Index of the layer with the specified name |
Source code in leafmap/leafmap.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 | |
get_bbox()
¶
Get the bounds of the map as a list of [(]minx, miny, maxx, maxy].
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
The bounds of the map as a list of [(]minx, miny, maxx, maxy]. |
Source code in leafmap/leafmap.py
4783 4784 4785 4786 4787 4788 4789 4790 4791 | |
get_draw_props(n=None, return_df=False)
¶
Get the properties of the draw features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The maximum number of attributes to return. Defaults to None. |
None
|
return_df
|
bool
|
If True, return a pandas dataframe. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: A pandas dataframe containing the properties of the draw features. |
Source code in leafmap/leafmap.py
4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 | |
get_layer_names()
¶
Gets layer names as a list.
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
A list of layer names. |
Source code in leafmap/leafmap.py
300 301 302 303 304 305 306 307 308 309 310 311 312 | |
get_pc_collections()
¶
Get the list of Microsoft Planetary Computer collections.
Source code in leafmap/leafmap.py
4161 4162 4163 4164 | |
get_scale()
¶
Returns the approximate pixel scale of the current map view, in meters.
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Map resolution in meters. |
Source code in leafmap/leafmap.py
287 288 289 290 291 292 293 294 295 296 297 298 | |
image_overlay(url, bounds, name)
¶
Overlays an image from the Internet or locally on the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
http URL or local file path to the image. |
required |
bounds
|
tuple
|
bounding box of the image in the format of (lower_left(lat, lon), upper_right(lat, lon)), such as ((13, -130), (32, -100)). |
required |
name
|
str
|
name of the layer to show on the layer control. |
required |
Source code in leafmap/leafmap.py
2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 | |
layer_opacity(name, value=1.0)
¶
Changes layer opacity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the layer to change opacity. |
required |
value
|
float
|
The opacity value to set. Defaults to 1.0. |
1.0
|
Source code in leafmap/leafmap.py
520 521 522 523 524 525 526 527 528 529 530 531 | |
marker_cluster(event='click', add_marker=True)
¶
Captures user inputs and add markers to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
str
|
[description]. Defaults to 'click'. |
'click'
|
add_marker
|
bool
|
If True, add markers to the map. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
object |
a marker cluster. |
Source code in leafmap/leafmap.py
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 | |
oam_search(bbox=None, start_date=None, end_date=None, limit=100, info_mode='on_click', layer_args={}, add_image=True, **kwargs)
¶
Search OpenAerialMap for images within a bounding box and time range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
list | str
|
The bounding box [xmin, ymin, xmax, ymax] to search within. Defaults to None. |
None
|
start_date
|
str
|
The start date to search within, such as "2015-04-20T00:00:00.000Z". Defaults to None. |
None
|
end_date
|
str
|
The end date to search within, such as "2015-04-21T00:00:00.000Z". Defaults to None. |
None
|
limit
|
int
|
The maximum number of results to return. Defaults to 100. |
100
|
info_mode
|
str
|
The mode to use for the info popup. Can be 'on_hover' or 'on_click'. Defaults to 'on_click'. |
'on_click'
|
layer_args
|
dict
|
The layer arguments for add_gdf() function. Defaults to {}. |
{}
|
add_image
|
bool
|
Whether to add the first 10 images to the map. Defaults to True. |
True
|
**kwargs
|
Additional keyword arguments to pass to the API. See https://hotosm.github.io/oam-api/ |
{}
|
Source code in leafmap/leafmap.py
4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 | |
remove(widget)
¶
Removes a widget to the map.
Source code in leafmap/leafmap.py
4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 | |
remove_labels()
¶
Removes all labels from the map.
Source code in leafmap/leafmap.py
3957 3958 3959 3960 3961 | |
save_draw_features(out_file, crs='EPSG:4326', **kwargs)
¶
Save the draw features to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_file
|
str
|
The output file path. |
required |
crs
|
str
|
The CRS of the output GeoJSON. Defaults to "EPSG:4326". |
'EPSG:4326'
|
Source code in leafmap/leafmap.py
4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 | |
save_edits(filename, drop_style=True, crs='EPSG:4326', **kwargs)
¶
Save the edited GeoJSON data to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The name of the file to save the edited GeoJSON data. |
required |
drop_style
|
bool
|
Whether to drop the style properties from the GeoJSON data. Defaults to True. |
True
|
crs
|
str
|
The CRS of the GeoJSON data. Defaults to "EPSG:4326". |
'EPSG:4326'
|
**kwargs
|
Any
|
Additional arguments passed to the GeoDataFrame |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/leafmap.py
5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 | |
set_catalog_source(source)
¶
Set the catalog source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
catalog_source
|
str
|
The catalog source. Defaults to "landsat". |
required |
Source code in leafmap/leafmap.py
4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 | |
set_center(lon, lat, zoom=None)
¶
Centers the map view at a given coordinates with the given zoom level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lon
|
float
|
The longitude of the center, in degrees. |
required |
lat
|
float
|
The latitude of the center, in degrees. |
required |
zoom
|
int
|
The zoom level, from 1 to 24. Defaults to None. |
None
|
Source code in leafmap/leafmap.py
257 258 259 260 261 262 263 264 265 266 267 | |
split_map(left_layer='TERRAIN', right_layer='OpenTopoMap', left_args={}, right_args={}, left_array_args={}, right_array_args={}, zoom_control=True, fullscreen_control=True, layer_control=True, add_close_button=False, left_label=None, right_label=None, left_position='bottomleft', right_position='bottomright', widget_layout=None, draggable=True)
¶
Adds split map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left_layer
|
str
|
The left tile layer. Can be a local file path, HTTP URL, or a basemap name. Defaults to 'TERRAIN'. |
'TERRAIN'
|
right_layer
|
str
|
The right tile layer. Can be a local file path, HTTP URL, or a basemap name. Defaults to 'OpenTopoMap'. |
'OpenTopoMap'
|
left_args
|
dict
|
The arguments for the left tile layer. Defaults to {}. |
{}
|
right_args
|
dict
|
The arguments for the right tile layer. Defaults to {}. |
{}
|
left_array_args
|
dict
|
The arguments for array_to_image for the left layer. Defaults to {}. |
{}
|
right_array_args
|
dict
|
The arguments for array_to_image for the right layer. Defaults to {}. |
{}
|
zoom_control
|
bool
|
Whether to add zoom control. Defaults to True. |
True
|
fullscreen_control
|
bool
|
Whether to add fullscreen control. Defaults to True. |
True
|
layer_control
|
bool
|
Whether to add layer control. Defaults to True. |
True
|
add_close_button
|
bool
|
Whether to add a close button. Defaults to False. |
False
|
left_label
|
str
|
The label for the left layer. Defaults to None. |
None
|
right_label
|
str
|
The label for the right layer. Defaults to None. |
None
|
left_position
|
str
|
The position for the left label. Defaults to "bottomleft". |
'bottomleft'
|
right_position
|
str
|
The position for the right label. Defaults to "bottomright". |
'bottomright'
|
widget_layout
|
dict
|
The layout for the widget. Defaults to None. |
None
|
draggable
|
bool
|
Whether the split map is draggable. Defaults to True. |
True
|
Source code in leafmap/leafmap.py
1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 | |
static_map(width=950, height=600, out_file=None, **kwargs)
¶
Display an ipyleaflet static map in a Jupyter Notebook.
Args m (ipyleaflet.Map): An ipyleaflet map. width (int, optional): Width of the map. Defaults to 950. height (int, optional): Height of the map. Defaults to 600. read_only (bool, optional): Whether to hide the side panel to disable map customization. Defaults to False. out_file (str, optional): Output html file path. Defaults to None.
Source code in leafmap/leafmap.py
4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 | |
to_html(outfile=None, title='My Map', width='100%', height='880px', add_layer_control=True, **kwargs)
¶
Saves the map as an HTML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outfile
|
str
|
The output file path to the HTML file. |
None
|
title
|
str
|
The title of the HTML file. Defaults to 'My Map'. |
'My Map'
|
width
|
str
|
The width of the map in pixels or percentage. Defaults to '100%'. |
'100%'
|
height
|
str
|
The height of the map in pixels. Defaults to '880px'. |
'880px'
|
add_layer_control
|
bool
|
Whether to add the LayersControl. Defaults to True. |
True
|
Source code in leafmap/leafmap.py
2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 | |
to_image(outfile=None, monitor=1)
¶
Saves the map as a PNG or JPG image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outfile
|
str
|
The output file path to the image. Defaults to None. |
None
|
monitor
|
int
|
The monitor to take the screenshot. Defaults to 1. |
1
|
Source code in leafmap/leafmap.py
2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 | |
to_streamlit(width=None, height=600, scrolling=False, **kwargs)
¶
Renders map figure in a Streamlit app.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
width
|
int
|
Width of the map. Defaults to None. |
None
|
height
|
int
|
Height of the map. Defaults to 600. |
600
|
responsive
|
bool
|
Whether to make the map responsive. Defaults to True. |
required |
scrolling
|
bool
|
If True, show a scrollbar when the content is larger than the iframe. Otherwise, do not show a scrollbar. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
|
streamlit.components: components.html object. |
Source code in leafmap/leafmap.py
2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 | |
toolbar_reset()
¶
Reset the toolbar so that no tool is selected.
Source code in leafmap/leafmap.py
2394 2395 2396 2397 2398 | |
update_draw_features()
¶
Update the draw features by removing features that have been edited and no longer exist.
Source code in leafmap/leafmap.py
4194 4195 4196 4197 4198 4199 4200 4201 | |
update_draw_props(df)
¶
Update the draw features properties.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
A pandas dataframe containing the properties of the draw features. |
required |
Source code in leafmap/leafmap.py
4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 | |
update_layer_manager()
¶
Update the Layer Manager.
Source code in leafmap/leafmap.py
4906 4907 4908 4909 4910 4911 4912 | |
user_roi_bounds(decimals=4)
¶
Get the bounds of the user drawn ROI as a tuple of (minx, miny, maxx, maxy).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decimals
|
int
|
The number of decimals to round the coordinates to. Defaults to 4. |
4
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
list
|
The bounds of the user drawn ROI as a tuple of (minx, miny, maxx, maxy). |
Source code in leafmap/leafmap.py
4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 | |
video_overlay(url, bounds, layer_name=None, **kwargs)
¶
Overlays a video from the Internet on the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
http URL of the video, such as "https://www.mapbox.com/bites/00188/patricia_nasa.webm" |
required |
bounds
|
tuple
|
bounding box of the video in the format of (lower_left(lat, lon), upper_right(lat, lon)), such as ((13, -130), (32, -100)). |
required |
layer_name
|
str
|
name of the layer to show on the layer control. |
None
|
Source code in leafmap/leafmap.py
2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 | |
zoom_to_bounds(bounds)
¶
Zooms to a bounding box in the form of [minx, miny, maxx, maxy].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
list | tuple
|
A list/tuple containing minx, miny, maxx, maxy values for the bounds. |
required |
Source code in leafmap/leafmap.py
269 270 271 272 273 274 275 276 | |
zoom_to_gdf(gdf)
¶
Zooms to the bounding box of a GeoPandas GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
A GeoPandas GeoDataFrame. |
required |
Source code in leafmap/leafmap.py
278 279 280 281 282 283 284 285 | |
PlanetaryComputerEndpoint
¶
Bases: TitilerEndpoint
This class contains the methods for the Microsoft Planetary Computer endpoint.
Source code in leafmap/stac.py
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 | |
__init__(endpoint='https://planetarycomputer.microsoft.com/api/data/v1', name='item', TileMatrixSetId='WebMercatorQuad')
¶
Initialize the PlanetaryComputerEndpoint object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The endpoint of the titiler server. Defaults to "https://planetarycomputer.microsoft.com/api/data/v1". |
'https://planetarycomputer.microsoft.com/api/data/v1'
|
name
|
str
|
The name to be used in the file path. Defaults to "item". |
'item'
|
TileMatrixSetId
|
str
|
The TileMatrixSetId to be used in the file path. Defaults to "WebMercatorQuad". |
'WebMercatorQuad'
|
Source code in leafmap/stac.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
The_national_map_USGS
¶
The national map is a collection of topological datasets, maintained by the USGS.
It provides an API endpoint which can be used to find downloadable links for the products offered. - Full description of datasets available can retrieved. This consists of metadata such as detail description and publication dates. - A wide range of dataformats are available
This class is a tiny wrapper to find and download files using the API.
More complete documentation for the API can be found at https://apps.nationalmap.gov/tnmaccess/#/
Source code in leafmap/common.py
6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 | |
datasets
property
¶
Returns a list of dataset tags (most common human readable self description for specific datasets).
datasets_full
property
¶
Full description of datasets provided. Returns a JSON or empty list.
prodFormats
property
¶
Return all datatypes available in any of the collections. Note that "All" is only peculiar to one dataset.
download_tiles(region=None, out_dir=None, download_args={}, geopandas_args={}, API={})
¶
Download the US National Elevation Datasets (NED) for a region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str | list
|
An URL|filepath to a vector dataset Or a list of bounds in the form of [minx, miny, maxx, maxy]. Alternatively you could use API parameters such as polygon or bbox. |
None
|
out_dir
|
str
|
The directory to download the files to. Defaults to None, which uses the current working directory. |
None
|
download_args
|
dict
|
A dictionary of arguments to pass to the download_file function. Defaults to {}. |
{}
|
geopandas_args
|
dict
|
A dictionary of arguments to pass to the geopandas.read_file() function. Used for reading a region URL|filepath. |
{}
|
API
|
dict
|
A dictionary of arguments to pass to the self.find_details() function. Exposes most of the documented API. Defaults to {}. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/common.py
6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 | |
find_details(bbox=None, polygon=None, datasets=None, prodFormats=None, prodExtents=None, q=None, dateType=None, start=None, end=None, offset=0, max=None, outputFormat='JSON', polyType=None, polyCode=None, extentQuery=None)
¶
Possible search parameters (kwargs) support by API
Parameter Values Description
bbox 'minx, miny, maxx, maxy' Geographic longitude/latitude values expressed in decimal degrees in a comma-delimited list. polygon '[x,y x,y x,y x,y x,y]' Polygon, longitude/latitude values expressed in decimal degrees in a space-delimited list. datasets See: Datasets (Optional) Dataset tag name (sbDatasetTag) From https://apps.nationalmap.gov/tnmaccess/#/product prodFormats See: Product Formats (Optional) Dataset-specific format
Product Extents (Optional)
Dataset-specific extent
q free text Text input which can be used to filter by product titles and text descriptions. dateType dateCreated | lastUpdated | Publication Type of date to search by. start 'YYYY-MM-DD' Start date end 'YYYY-MM-DD' End date (required if start date is provided) offset integer Offset into paginated results - default=0 max integer Number of results returned outputFormat JSON | CSV | pjson Default=JSON polyType state | huc2 | huc4 | huc8 Well Known Polygon Type. Use this parameter to deliver data by state or HUC (hydrologic unit codes defined by the Watershed Boundary Dataset/WBD) polyCode state FIPS code or huc number Well Known Polygon Code. This value needs to coordinate with the polyType parameter. extentQuery integer A Polygon code in the science base system, typically from an uploaded shapefile
Source code in leafmap/common.py
6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 | |
find_tiles(region=None, return_type='list', geopandas_args={}, API={})
¶
Find a list of downloadable files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str | list
|
An URL|filepath to a vector dataset Or a list of bounds in the form of [minx, miny, maxx, maxy]. Alternatively you could use API parameters such as polygon or bbox. |
None
|
return_type
|
str
|
list | dict. Defaults to list. Changes the return output type and content. |
'list'
|
geopandas_args
|
dict
|
A dictionary of arguments to pass to the geopandas.read_file() function. Used for reading a region URL|filepath. |
{}
|
API
|
dict
|
A dictionary of arguments to pass to the self.find_details() function. Exposes most of the documented API parameters. Defaults to {}. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[List[str], Dict]
|
A list of download URLs if return_type is 'list', otherwise a dictionary with URLs and related metadata. |
Source code in leafmap/common.py
6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 | |
parse_region(region, geopandas_args={})
¶
Translate a Vector dataset to its bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str | list
|
an URL|filepath to a vector dataset to a polygon |
required |
geopandas_args
|
dict
|
A dictionary of arguments to pass to the geopandas.read_file() function. Used for reading a region URL|filepath. |
{}
|
Source code in leafmap/common.py
6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 | |
TitilerEndpoint
¶
This class contains the methods for the titiler endpoint.
Source code in leafmap/stac.py
14 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
__init__(endpoint=None, name='stac', TileMatrixSetId='WebMercatorQuad')
¶
Initialize the TiTilerEndpoint object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The endpoint of the titiler server. Defaults to "https://giswqs-titiler-endpoint.hf.space". |
None
|
name
|
str
|
The name to be used in the file path. Defaults to "stac". |
'stac'
|
TileMatrixSetId
|
str
|
The TileMatrixSetId to be used in the file path. Defaults to "WebMercatorQuad". |
'WebMercatorQuad'
|
Source code in leafmap/stac.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
WhiteboxTools
¶
Bases: WhiteboxTools
This class inherits the whitebox WhiteboxTools class.
Source code in leafmap/common.py
37 38 39 40 41 | |
add_crs(filename, epsg)
¶
Add a CRS to a raster dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The filename of the raster dataset. |
required |
epsg
|
int | str
|
The EPSG code of the CRS. |
required |
Source code in leafmap/common.py
6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 | |
add_image_to_gif(in_gif, out_gif, in_image, xy=None, image_size=(80, 80), circle_mask=False)
¶
Adds an image logo to a GIF image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_gif
|
str
|
Input file path to the GIF image. |
required |
out_gif
|
str
|
Output file path to the GIF image. |
required |
in_image
|
str
|
Input file path to the image. |
required |
xy
|
tuple
|
Top left corner of the text. It can be formatted like this: (10, 10) or ('15%', '25%'). Defaults to None. |
None
|
image_size
|
tuple
|
Resize image. Defaults to (80, 80). |
(80, 80)
|
circle_mask
|
bool
|
Whether to apply a circle mask to the image. This only works with non-png images. Defaults to False. |
False
|
Source code in leafmap/common.py
8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 | |
add_mask_to_image(image, mask, output, color='red')
¶
Overlay a binary mask (e.g., roads, building footprints, etc) on an image. Credits to Xingjian Shi for the sample code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
str
|
A local path or HTTP URL to an image. |
required |
mask
|
str
|
A local path or HTTP URL to a binary mask. |
required |
output
|
str
|
A local path to the output image. |
required |
color
|
str
|
Color of the mask. Defaults to 'red'. |
'red'
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If rasterio and detectron2 are not installed. |
Source code in leafmap/common.py
7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 | |
add_progress_bar_to_gif(in_gif, out_gif, progress_bar_color='blue', progress_bar_height=5, duration=100, loop=0)
¶
Adds a progress bar to a GIF image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_gif
|
str
|
The file path to the input GIF image. |
required |
out_gif
|
str
|
The file path to the output GIF image. |
required |
progress_bar_color
|
str
|
Color for the progress bar. Defaults to 'white'. |
'blue'
|
progress_bar_height
|
int
|
Height of the progress bar. Defaults to 5. |
5
|
duration
|
int
|
controls how long each frame will be displayed for, in milliseconds. It is the inverse of the frame rate. Setting it to 100 milliseconds gives 10 frames per second. You can decrease the duration to give a smoother animation. Defaults to 100. |
100
|
loop
|
int
|
controls how many times the animation repeats. The default, 1, means that the animation will play once and then stop (displaying the last frame). A value of 0 means that the animation will repeat forever. Defaults to 0. |
0
|
Source code in leafmap/common.py
8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 | |
add_text_to_gif(in_gif, out_gif, xy=None, text_sequence=None, font_type='arial.ttf', font_size=20, font_color='#000000', add_progress_bar=True, progress_bar_color='white', progress_bar_height=5, duration=100, loop=0)
¶
Adds animated text to a GIF image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_gif
|
str
|
The file path to the input GIF image. |
required |
out_gif
|
str
|
The file path to the output GIF image. |
required |
xy
|
tuple
|
Top left corner of the text. It can be formatted like this: (10, 10) or ('15%', '25%'). Defaults to None. |
None
|
text_sequence
|
(int, str, list)
|
Text to be drawn. It can be an integer number, a string, or a list of strings. Defaults to None. |
None
|
font_type
|
str
|
Font type. Defaults to "arial.ttf". |
'arial.ttf'
|
font_size
|
int
|
Font size. Defaults to 20. |
20
|
font_color
|
str
|
Font color. It can be a string (e.g., 'red'), rgb tuple (e.g., (255, 127, 0)), or hex code (e.g., '#ff00ff'). Defaults to '#000000'. |
'#000000'
|
add_progress_bar
|
bool
|
Whether to add a progress bar at the bottom of the GIF. Defaults to True. |
True
|
progress_bar_color
|
str
|
Color for the progress bar. Defaults to 'white'. |
'white'
|
progress_bar_height
|
int
|
Height of the progress bar. Defaults to 5. |
5
|
duration
|
int
|
controls how long each frame will be displayed for, in milliseconds. It is the inverse of the frame rate. Setting it to 100 milliseconds gives 10 frames per second. You can decrease the duration to give a smoother animation.. Defaults to 100. |
100
|
loop
|
int
|
controls how many times the animation repeats. The default, 1, means that the animation will play once and then stop (displaying the last frame). A value of 0 means that the animation will repeat forever. Defaults to 0. |
0
|
Source code in leafmap/common.py
7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 | |
add_unique_class(data, column, class_column='class', mapping=None)
¶
Add a unique integer class column to a vector dataset based on an existing column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str or GeoDataFrame
|
Input vector data as file path or GeoDataFrame. |
required |
column
|
str
|
The column name used for generating unique classes. |
required |
class_column
|
str
|
The name of the new column to store integer classes. Default is "class". |
'class'
|
mapping
|
dict
|
A dictionary mapping original values to integer classes. If not provided, a mapping will be generated automatically starting from 1. |
None
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
The updated GeoDataFrame with the new class column. |
Source code in leafmap/common.py
19476 19477 19478 19479 19480 19481 19482 19483 19484 19485 19486 19487 19488 19489 19490 19491 19492 19493 19494 19495 19496 19497 19498 19499 19500 19501 19502 19503 19504 19505 19506 19507 19508 | |
adjust_longitude(in_fc)
¶
Adjusts longitude if it is less than -180 or greater than 180.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_fc
|
dict
|
The input dictionary containing coordinates. |
required |
Returns:
| Type | Description |
|---|---|
Optional[dict]
|
A dictionary containing the converted longitudes. |
Source code in leafmap/common.py
1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 | |
arc_active_map()
¶
Get the active map in ArcGIS Pro.
Returns:
| Type | Description |
|---|---|
Optional[Any]
|
The active map in ArcGIS Pro. |
Source code in leafmap/common.py
9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 | |
arc_active_view()
¶
Get the active view in ArcGIS Pro.
Returns:
| Type | Description |
|---|---|
Optional[Any]
|
The active view in ArcGIS Pro. |
Source code in leafmap/common.py
9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 | |
arc_add_layer(url, name=None, shown=True, opacity=1.0)
¶
Add a layer to the active map in ArcGIS Pro.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the tile layer to add. |
required |
name
|
str
|
The name of the layer. Defaults to None. |
None
|
shown
|
bool
|
Whether the layer is shown. Defaults to True. |
True
|
opacity
|
float
|
The opacity of the layer. Defaults to 1.0. |
1.0
|
Source code in leafmap/common.py
9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 | |
arc_zoom_to_bounds(bounds)
¶
Zoom to a bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
list
|
The bounding box to zoom to in the form [xmin, ymin, xmax, ymax] or [(ymin, xmin), (ymax, xmax)]. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
description |
Source code in leafmap/common.py
9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 | |
arc_zoom_to_extent(xmin, ymin, xmax, ymax)
¶
Zoom to an extent in ArcGIS Pro.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xmin
|
float
|
The minimum x value of the extent. |
required |
ymin
|
float
|
The minimum y value of the extent. |
required |
xmax
|
float
|
The maximum x value of the extent. |
required |
ymax
|
float
|
The maximum y value of the extent. |
required |
Source code in leafmap/common.py
9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 | |
array_to_image(array, output=None, source=None, dtype=None, compress='deflate', transpose=True, cellsize=None, crs=None, transform=None, driver='COG', colormap=None, **kwargs)
¶
Save a NumPy array as a GeoTIFF using the projection information from an existing GeoTIFF file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray
|
The NumPy array to be saved as a GeoTIFF. |
required |
output
|
str
|
The path to the output image. If None, a temporary file will be created. Defaults to None. |
None
|
source
|
str
|
The path to an existing GeoTIFF file with map projection information. Defaults to None. |
None
|
dtype
|
dtype
|
The data type of the output array. Defaults to None. |
None
|
compress
|
str
|
The compression method. Can be one of the following: "deflate", "lzw", "packbits", "jpeg". Defaults to "deflate". |
'deflate'
|
transpose
|
bool
|
Whether to transpose the array from (bands, rows, columns) to (rows, columns, bands). Defaults to True. |
True
|
cellsize
|
float
|
The resolution of the output image in meters. Defaults to None. |
None
|
crs
|
str
|
The CRS of the output image. Defaults to None. |
None
|
transform
|
tuple
|
The affine transformation matrix, can be rio.transform() or a tuple like (0.5, 0.0, -180.25, 0.0, -0.5, 83.780361). Defaults to None. |
None
|
driver
|
str
|
The driver to use for creating the output file, such as 'GTiff'. Defaults to "COG". |
'COG'
|
colormap
|
dict
|
A dictionary defining the colormap (value: (R, G, B, A)). |
None
|
**kwargs
|
Any
|
Additional keyword arguments to be passed to the rasterio.open() function. |
{}
|
Source code in leafmap/common.py
11779 11780 11781 11782 11783 11784 11785 11786 11787 11788 11789 11790 11791 11792 11793 11794 11795 11796 11797 11798 11799 11800 11801 11802 11803 11804 11805 11806 11807 11808 11809 11810 11811 11812 11813 11814 11815 11816 11817 11818 11819 11820 11821 11822 11823 11824 11825 11826 11827 11828 11829 11830 11831 11832 11833 11834 11835 11836 11837 11838 11839 11840 11841 11842 11843 11844 11845 11846 11847 11848 11849 11850 11851 11852 11853 11854 11855 11856 11857 11858 11859 11860 11861 11862 11863 11864 11865 11866 11867 11868 11869 11870 11871 11872 11873 11874 11875 11876 11877 11878 11879 11880 11881 11882 11883 11884 11885 11886 11887 11888 11889 11890 11891 11892 11893 11894 11895 11896 11897 11898 11899 11900 11901 11902 11903 11904 11905 11906 11907 11908 11909 11910 11911 11912 11913 11914 11915 11916 11917 11918 11919 11920 11921 11922 11923 11924 11925 11926 11927 11928 11929 11930 11931 11932 11933 11934 11935 11936 11937 11938 11939 11940 11941 11942 11943 11944 11945 11946 11947 11948 11949 11950 11951 11952 11953 11954 11955 11956 11957 11958 11959 11960 11961 11962 11963 11964 11965 | |
array_to_memory_file(array, source=None, dtype=None, compress='deflate', transpose=True, cellsize=None, crs=None, transform=None, driver='COG', colormap=None, **kwargs)
¶
Convert a NumPy array to a memory file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray
|
The input NumPy array. |
required |
source
|
str
|
Path to the source file to extract metadata from. Defaults to None. |
None
|
dtype
|
str
|
The desired data type of the array. Defaults to None. |
None
|
compress
|
str
|
The compression method for the output file. Defaults to "deflate". |
'deflate'
|
transpose
|
bool
|
Whether to transpose the array from (bands, rows, columns) to (rows, columns, bands). Defaults to True. |
True
|
cellsize
|
float
|
The cell size of the array if source is not provided. Defaults to None. |
None
|
crs
|
str
|
The coordinate reference system of the array if source is not provided. Defaults to None. |
None
|
transform
|
tuple
|
The affine transformation matrix if source is not provided. Can be rio.transform() or a tuple like (0.5, 0.0, -180.25, 0.0, -0.5, 83.780361). Defaults to None. |
None
|
driver
|
str
|
The driver to use for creating the output file, such as 'GTiff'. Defaults to "COG". |
'COG'
|
colormap
|
dict
|
A dictionary defining the colormap (value: (R, G, B, A)). |
None
|
**kwargs
|
Any
|
Additional keyword arguments to be passed to the rasterio.open() function. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The rasterio dataset reader object for the converted array. |
Source code in leafmap/common.py
11609 11610 11611 11612 11613 11614 11615 11616 11617 11618 11619 11620 11621 11622 11623 11624 11625 11626 11627 11628 11629 11630 11631 11632 11633 11634 11635 11636 11637 11638 11639 11640 11641 11642 11643 11644 11645 11646 11647 11648 11649 11650 11651 11652 11653 11654 11655 11656 11657 11658 11659 11660 11661 11662 11663 11664 11665 11666 11667 11668 11669 11670 11671 11672 11673 11674 11675 11676 11677 11678 11679 11680 11681 11682 11683 11684 11685 11686 11687 11688 11689 11690 11691 11692 11693 11694 11695 11696 11697 11698 11699 11700 11701 11702 11703 11704 11705 11706 11707 11708 11709 11710 11711 11712 11713 11714 11715 11716 11717 11718 11719 11720 11721 11722 11723 11724 11725 11726 11727 11728 11729 11730 11731 11732 11733 11734 11735 11736 11737 11738 11739 11740 11741 11742 11743 11744 11745 11746 11747 11748 11749 11750 11751 11752 11753 11754 11755 11756 11757 11758 11759 11760 11761 11762 11763 11764 11765 11766 11767 11768 11769 11770 11771 11772 11773 11774 11775 11776 | |
assign_continuous_colors(df, column, cmap=None, colors=None, labels=None, scheme='Quantiles', k=5, legend_kwds=None, classification_kwds=None, to_rgb=True, return_type='array', return_legend=False)
¶
Assigns continuous colors to a DataFrame column based on a specified scheme.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
A pandas DataFrame. |
required |
column
|
str
|
The name of the column to assign colors. |
required |
cmap
|
str
|
The name of the colormap to use. |
None
|
colors
|
list
|
A list of custom colors. |
None
|
labels
|
list
|
A list of custom labels for the legend. |
None
|
scheme
|
str
|
The scheme for classifying the data. Default is 'Quantiles'. |
'Quantiles'
|
k
|
int
|
The number of classes for classification. |
5
|
legend_kwds
|
dict
|
Additional keyword arguments for configuring the legend. |
None
|
classification_kwds
|
dict
|
Additional keyword arguments for configuring the classification. |
None
|
to_rgb
|
bool
|
Whether to convert colors to RGB values. Default is True. |
True
|
return_type
|
str
|
The type of the returned values. Default is 'array'. |
'array'
|
return_legend
|
bool
|
Whether to return the legend. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
Union[ndarray, Tuple[ndarray, dict]]
|
The assigned colors as a numpy array or a tuple containing the colors and the legend, depending on the value of return_legend. |
Source code in leafmap/common.py
15323 15324 15325 15326 15327 15328 15329 15330 15331 15332 15333 15334 15335 15336 15337 15338 15339 15340 15341 15342 15343 15344 15345 15346 15347 15348 15349 15350 15351 15352 15353 15354 15355 15356 15357 15358 15359 15360 15361 15362 15363 15364 15365 15366 15367 15368 15369 15370 15371 15372 | |
assign_discrete_colors(df, column, cmap, to_rgb=True, return_type='array')
¶
Assigns unique colors to each category in a categorical column of a dataframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The input dataframe. |
required |
column
|
str
|
The name of the categorical column. |
required |
cmap
|
dict
|
A dictionary mapping categories to colors. |
required |
to_rgb
|
bool
|
Whether to convert the colors to RGB values. Defaults to True. |
True
|
return_type
|
str
|
The type of the returned values. Can be 'list' or 'array'. Defaults to 'array'. |
'array'
|
Returns:
| Type | Description |
|---|---|
Union[List, ndarray]
|
A list of colors for each category in the categorical column. |
Source code in leafmap/common.py
15289 15290 15291 15292 15293 15294 15295 15296 15297 15298 15299 15300 15301 15302 15303 15304 15305 15306 15307 15308 15309 15310 15311 15312 15313 15314 15315 15316 15317 15318 15319 15320 | |
bar_chart(data=None, x=None, y=None, color=None, descending=True, sort_column=None, max_rows=None, x_label=None, y_label=None, title=None, legend_title=None, width=None, height=500, layout_args={}, **kwargs)
¶
Create a bar chart with plotly.express,
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame | array-like | dict | str (local file path or HTTP URL) This argument needs to be passed for column names (and not keyword names) to be used. Array-like and dict are transformed internally to a pandas DataFrame. Optional: if missing, a DataFrame gets constructed under the hood using the other arguments. |
None
|
|
x
|
str or int or Series or array-like
Either a name of a column in |
None
|
|
y
|
str or int or Series or array-like
Either a name of a column in |
None
|
|
color
|
str or int or Series or array-like
Either a name of a column in |
None
|
|
descending
|
bool
|
Whether to sort the data in descending order. Defaults to True. |
True
|
sort_column
|
str
|
The column to sort the data. Defaults to None. |
None
|
max_rows
|
int
|
Maximum number of rows to display. Defaults to None. |
None
|
x_label
|
str
|
Label for the x axis. Defaults to None. |
None
|
y_label
|
str
|
Label for the y axis. Defaults to None. |
None
|
title
|
str
|
Title for the plot. Defaults to None. |
None
|
legend_title
|
str
|
Title for the legend. Defaults to None. |
None
|
width
|
int
|
Width of the plot in pixels. Defaults to None. |
None
|
height
|
int
|
Height of the plot in pixels. Defaults to 500. |
500
|
layout_args
|
dict
|
Layout arguments for the plot to be passed to fig.update_layout(), such as {'title':'Plot Title', 'title_x':0.5}. Defaults to None. |
{}
|
**kwargs
|
Any additional arguments to pass to plotly.express.bar(), such as: pattern_shape: str or int or Series or array-like
Either a name of a column in |
{}
|
Returns:
| Type | Description |
|---|---|
|
plotly.graph_objs._figure.Figure: A plotly figure object. |
Source code in leafmap/plot.py
9 10 11 12 13 14 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 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 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 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 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 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 | |
basemap_xyz_tiles()
¶
Returns a dictionary containing a set of basemaps that are XYZ tile layers.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
A dictionary of XYZ tile layers. |
Source code in leafmap/common.py
2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 | |
bbox_to_gdf(bbox, crs='epsg:4326')
¶
Convert a bounding box to a GeoPandas GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
list
|
A bounding box in the format of [minx, miny, maxx, maxy]. |
required |
crs
|
str
|
The CRS of the bounding box. Defaults to 'epsg:4326'. |
'epsg:4326'
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
A GeoDataFrame with a single polygon. |
Source code in leafmap/common.py
7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 | |
bbox_to_geojson(bounds)
¶
Convert coordinates of a bounding box to a geojson.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
list | tuple
|
A list of coordinates representing [left, bottom, right, top] or m.bounds. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A geojson feature. |
Source code in leafmap/common.py
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 | |
bbox_to_polygon(bbox)
¶
Convert a bounding box to a shapely Polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
list
|
A bounding box in the format of [minx, miny, maxx, maxy]. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A shapely Polygon. |
Source code in leafmap/common.py
7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 | |
blend_images(img1, img2, alpha=0.5, output=False, show=True, figsize=(12, 10), axis='off', **kwargs)
¶
Blends two images together using the addWeighted function from the OpenCV library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img1
|
ndarray
|
The first input image on top represented as a NumPy array. |
required |
img2
|
ndarray
|
The second input image at the bottom represented as a NumPy array. |
required |
alpha
|
float
|
The weighting factor for the first image in the blend. By default, this is set to 0.5. |
0.5
|
output
|
str
|
The path to the output image. Defaults to False. |
False
|
show
|
bool
|
Whether to display the blended image. Defaults to True. |
True
|
figsize
|
tuple
|
The size of the figure. Defaults to (12, 10). |
(12, 10)
|
axis
|
str
|
The axis of the figure. Defaults to "off". |
'off'
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the cv2.addWeighted() function. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The blended image as a NumPy array. |
Source code in leafmap/common.py
14132 14133 14134 14135 14136 14137 14138 14139 14140 14141 14142 14143 14144 14145 14146 14147 14148 14149 14150 14151 14152 14153 14154 14155 14156 14157 14158 14159 14160 14161 14162 14163 14164 14165 14166 14167 14168 14169 14170 14171 14172 14173 14174 14175 14176 14177 14178 14179 14180 14181 14182 14183 14184 14185 14186 14187 14188 14189 14190 14191 14192 14193 14194 14195 14196 14197 14198 14199 14200 14201 14202 14203 14204 14205 14206 14207 14208 14209 | |
bounds_to_xy_range(bounds)
¶
Convert bounds to x and y range to be used as input to bokeh map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bounds
|
Union[List[Union[Tuple[float, float], float]], Tuple[float, float, float, float]]
|
A list of bounds in the form [(south, west), (north, east)] or [xmin, ymin, xmax, ymax]. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Tuple[float, float], Tuple[float, float]]
|
Tuple[Tuple[float, float], Tuple[float, float]]: A tuple of (x_range, y_range). |
Source code in leafmap/common.py
7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 | |
center_zoom_to_xy_range(center, zoom)
¶
Convert center and zoom to x and y range to be used as input to bokeh map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
center
|
tuple
|
A tuple of (latitude, longitude). |
required |
zoom
|
int
|
The zoom level. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Tuple[float, float], Tuple[float, float]]
|
A tuple of (x_range, y_range). |
Source code in leafmap/common.py
7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 | |
cesium_to_streamlit(html, width=800, height=600, responsive=True, scrolling=False, token_name=None, token_value=None, **kwargs)
¶
Renders an cesium HTML file in a Streamlit app. This method is a static Streamlit Component, meaning, no information is passed back from Leaflet on browser interaction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
html
|
str
|
The HTML file to render. It can a local file path or a URL. |
required |
width
|
int
|
Width of the map. Defaults to 800. |
800
|
height
|
int
|
Height of the map. Defaults to 600. |
600
|
responsive
|
bool
|
Whether to make the map responsive. Defaults to True. |
True
|
scrolling
|
bool
|
Whether to allow the map to scroll. Defaults to False. |
False
|
token_name
|
str
|
The name of the token in the HTML file to be replaced. Defaults to None. |
None
|
token_value
|
str
|
The value of the token to pass to the HTML file. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
A Streamlit components.html object. |
Source code in leafmap/common.py
3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 | |
check_cmap(cmap)
¶
Check the colormap and return a list of colors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmap
|
str | list | Box
|
The colormap to check. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of colors. |
Source code in leafmap/common.py
5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 | |
check_color(in_color)
¶
Checks the input color and returns the corresponding hex color code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_color
|
str or tuple or list
|
It 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 leafmap/common.py
643 644 645 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 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 | |
check_dir(dir_path, make_dirs=True)
¶
Checks if a directory exists and creates it if it does not.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dir_path
|
[str
|
The path to the directory. |
required |
make_dirs
|
bool
|
Whether to create the directory if it does not exist. Defaults to True. |
True
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the directory could not be found. |
TypeError
|
If the input directory path is not a string. |
Returns:
| Type | Description |
|---|---|
str
|
The path to the directory. |
Source code in leafmap/common.py
4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 | |
check_file_path(file_path, make_dirs=True)
¶
Gets the absolute file path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
The path to the file. |
required |
make_dirs
|
bool
|
Whether to create the directory if it does not exist. Defaults to True. |
True
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the directory could not be found. |
TypeError
|
If the input directory path is not a string. |
Returns:
| Type | Description |
|---|---|
str
|
The absolute path to the file. |
Source code in leafmap/common.py
4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 | |
check_html_string(html_string)
¶
Check if an HTML string contains local images and convert them to base64.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
html_string
|
str
|
The HTML string. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The HTML string with local images converted to base64. |
Source code in leafmap/common.py
11210 11211 11212 11213 11214 11215 11216 11217 11218 11219 11220 11221 11222 11223 11224 11225 11226 11227 11228 11229 11230 11231 11232 11233 11234 | |
check_titiler_endpoint(titiler_endpoint=None)
¶
Returns the default titiler endpoint.
Returns:
| Type | Description |
|---|---|
Any
|
The titiler endpoint. |
Source code in leafmap/stac.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
check_url(url)
¶
Check if an HTTP URL is working.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the URL is working (returns a 200 status code), False otherwise. |
Source code in leafmap/common.py
15158 15159 15160 15161 15162 15163 15164 15165 15166 15167 15168 15169 15170 15171 15172 15173 15174 | |
classify(data, column, cmap=None, colors=None, labels=None, scheme='Quantiles', k=5, legend_kwds=None, classification_kwds=None)
¶
Classify a dataframe column using a variety of classification schemes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | DataFrame | GeoDataFrame
|
The data to classify. It can be a filepath to a vector dataset, a pandas dataframe, or a geopandas geodataframe. |
required |
column
|
str
|
The column to classify. |
required |
cmap
|
str
|
The name of a colormap recognized by matplotlib. Defaults to None. |
None
|
colors
|
list
|
A list of colors to use for the classification. Defaults to None. |
None
|
labels
|
list
|
A list of labels to use for the legend. Defaults to None. |
None
|
scheme
|
str
|
Name of a choropleth classification scheme (requires mapclassify). Name of a choropleth classification scheme (requires mapclassify). A mapclassify.MapClassifier object will be used under the hood. Supported are all schemes provided by mapclassify (e.g. 'BoxPlot', 'EqualInterval', 'FisherJenks', 'FisherJenksSampled', 'HeadTailBreaks', 'JenksCaspall', 'JenksCaspallForced', 'JenksCaspallSampled', 'MaxP', 'MaximumBreaks', 'NaturalBreaks', 'Quantiles', 'Percentiles', 'StdMean', 'UserDefined'). Arguments can be passed in classification_kwds. |
'Quantiles'
|
k
|
int
|
Number of classes (ignored if scheme is None or if column is categorical). Default to 5. |
5
|
legend_kwds
|
dict
|
Keyword arguments to pass to :func: |
None
|
classification_kwds
|
dict
|
Keyword arguments to pass to mapclassify. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[Any, Dict[str, Any]]
|
A pandas dataframe with the classification applied and a legend dictionary. |
Source code in leafmap/common.py
5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 | |
clip_image(image, mask, output, to_cog=True)
¶
Clip an image by mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
str
|
Path to the image file in GeoTIFF format. |
required |
mask
|
str | list | dict
|
The mask used to extract the image. It can be a path to vector datasets (e.g., GeoJSON, Shapefile), a list of coordinates, or m.user_roi. |
required |
output
|
str
|
Path to the output file. |
required |
to_cog
|
bool
|
Flags to indicate if you want to convert the output to COG. Defaults to True. |
True
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If the fiona or rasterio package is not installed. |
FileNotFoundError
|
If the image is not found. |
ValueError
|
If the mask is not a valid GeoJSON or raster file. |
FileNotFoundError
|
If the mask file is not found. |
Source code in leafmap/common.py
5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 | |
clip_raster(image, geometry, geom_crs=None, dst_crs=None, resolution=None, driver='COG', compress='DEFLATE', bands=None, match_raster=None, output=None, verbose=True, **kwargs)
¶
Clip a raster by a geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
str
|
Path to the image file in GeoTIFF format. |
required |
geometry
|
str | GeoDataFrame | dict | list
|
The geometry to clip the raster by. It can be a path to vector datasets (e.g., GeoJSON, Shapefile), a geopandas.GeoDataFrame, a dictionary, or a list of 4 numbers (minx, miny, maxx, maxy) representing a bounding box. |
required |
geom_crs
|
str
|
The coordinate reference system of the geometry. Defaults to None. |
None
|
dst_crs
|
str
|
The coordinate reference system of the output raster. Defaults to None. |
None
|
resolution
|
int
|
The resolution of the output raster. Defaults to None. If a single value is provided, the resolution will be the same in both x and y directions. If a tuple of two values is provided, the first value will be the resolution in the x direction and the second value will be the resolution in the y direction. |
None
|
driver
|
str
|
The driver of the output raster. Defaults to "COG". |
'COG'
|
compress
|
str
|
The compression of the output raster. Defaults to "DEFLATE". |
'DEFLATE'
|
bands
|
list
|
The indices of the bands to clip. Defaults to None. Start from 1. |
None
|
match_raster
|
str
|
Path to the raster to match the resolution and CRS of the output raster. Defaults to None. |
None
|
output
|
str
|
Path to the output raster file. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to rasterio.reproject. |
{}
|
Source code in leafmap/common.py
5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 | |
clip_vector(input_gdf, clip_geom=None, bbox=None, output=None)
¶
Clip a vector dataset using either a bounding box or another vector dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_gdf
|
str | Path | GeoDataFrame
|
The input vector data, either as a file path or a GeoDataFrame. |
required |
clip_geom
|
str | Path | GeoDataFrame
|
A vector dataset used for clipping, either as a file path or GeoDataFrame. |
None
|
bbox
|
tuple
|
Bounding box defined as (minx, miny, maxx, maxy). |
None
|
output
|
str | Path
|
File path to save the clipped result. If None, the result is not saved. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The clipped GeoDataFrame. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If both |
ValueError
|
If |
Source code in leafmap/common.py
19419 19420 19421 19422 19423 19424 19425 19426 19427 19428 19429 19430 19431 19432 19433 19434 19435 19436 19437 19438 19439 19440 19441 19442 19443 19444 19445 19446 19447 19448 19449 19450 19451 19452 19453 19454 19455 19456 19457 19458 19459 19460 19461 19462 19463 19464 19465 19466 19467 19468 19469 19470 19471 19472 19473 | |
close_duckdb_connections(database_path=None, quiet=True)
¶
Close DuckDB connections for a specific database or all databases.
This function closes all connections in the connection pool for the specified database, allowing other programs to access the database file. This is useful when you're done using the database and want to release the file lock.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database_path
|
str
|
Path to the DuckDB database file. If None, closes connections for all databases. Defaults to None. |
None
|
quiet
|
bool
|
If True, suppress status messages. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
|
None |
Example
import leafmap
After using add_duckdb_layer¶
m = leafmap.Map() m.add_duckdb_layer("tiles.db")
Later, close the connections¶
leafmap.close_duckdb_connections()
Or close connections for a specific database¶
leafmap.close_duckdb_connections("tiles.db")
Source code in leafmap/common.py
13406 13407 13408 13409 13410 13411 13412 13413 13414 13415 13416 13417 13418 13419 13420 13421 13422 13423 13424 13425 13426 13427 13428 13429 13430 13431 13432 13433 13434 13435 13436 13437 13438 13439 13440 13441 13442 13443 13444 13445 13446 13447 13448 13449 13450 13451 13452 13453 13454 13455 13456 13457 13458 13459 13460 13461 13462 13463 13464 13465 13466 13467 13468 13469 13470 13471 13472 13473 13474 13475 13476 13477 13478 | |
cog_bands(url, titiler_endpoint=None)
¶
Get band names of a Cloud Optimized GeoTIFF (COG).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
HTTP URL to a COG, e.g., https://opendata.digitalglobe.com/events/mauritius-oil-spill/post-event/2020-08-12/105001001F1B5B00/105001001F1B5B00.tif |
required |
titiler_endpoint
|
str
|
TiTiler endpoint. Defaults to "https://giswqs-titiler-endpoint.hf.space". |
None
|
Returns:
| Type | Description |
|---|---|
List
|
A list of band names. |
Source code in leafmap/stac.py
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 | |
cog_bounds(url, titiler_endpoint=None)
¶
Get the bounding box of a Cloud Optimized GeoTIFF (COG).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
HTTP URL to a COG, e.g., https://opendata.digitalglobe.com/events/mauritius-oil-spill/post-event/2020-08-12/105001001F1B5B00/105001001F1B5B00.tif |
required |
titiler_endpoint
|
str
|
TiTiler endpoint. Defaults to "https://giswqs-titiler-endpoint.hf.space". |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List
|
A list of values representing [left, bottom, right, top] |
Source code in leafmap/stac.py
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 | |
cog_center(url, titiler_endpoint=None)
¶
Get the centroid of a Cloud Optimized GeoTIFF (COG).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
HTTP URL to a COG, e.g., https://opendata.digitalglobe.com/events/mauritius-oil-spill/post-event/2020-08-12/105001001F1B5B00/105001001F1B5B00.tif |
required |
titiler_endpoint
|
str
|
TiTiler endpoint. Defaults to "https://giswqs-titiler-endpoint.hf.space". |
None
|
Returns:
| Type | Description |
|---|---|
Tuple
|
A tuple representing (longitude, latitude). |
Source code in leafmap/stac.py
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 | |
cog_info(url, titiler_endpoint=None, return_geojson=False)
¶
Get band statistics of a Cloud Optimized GeoTIFF (COG).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
HTTP URL to a COG, e.g., https://opendata.digitalglobe.com/events/mauritius-oil-spill/post-event/2020-08-12/105001001F1B5B00/105001001F1B5B00.tif |
required |
titiler_endpoint
|
str
|
TiTiler endpoint. Defaults to "https://giswqs-titiler-endpoint.hf.space". |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List
|
A dictionary of band info. |
Source code in leafmap/stac.py
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 | |
cog_mosaic(links, titiler_endpoint=None, username='anonymous', layername=None, overwrite=False, verbose=True, **kwargs)
¶
Creates a COG mosaic from a list of COG URLs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
links
|
list
|
A list containing COG HTTP URLs. |
required |
titiler_endpoint
|
str
|
TiTiler endpoint. Defaults to "https://giswqs-titiler-endpoint.hf.space". |
None
|
username
|
str
|
User name for the titiler endpoint. Defaults to "anonymous". |
'anonymous'
|
layername
|
[type]
|
Layer name to use. Defaults to None. |
None
|
overwrite
|
bool
|
Whether to overwrite the layer name if existing. Defaults to False. |
False
|
verbose
|
bool
|
Whether to print out descriptive information. Defaults to True. |
True
|
Raises:
| Type | Description |
|---|---|
Exception
|
If the COG mosaic fails to create. |
Returns:
| Type | Description |
|---|---|
str
|
The tile URL for the COG mosaic. |
Source code in leafmap/stac.py
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 353 354 355 356 357 358 359 360 361 362 363 | |
cog_mosaic_from_file(filepath, skip_rows=0, titiler_endpoint=None, username='anonymous', layername=None, overwrite=False, verbose=True, **kwargs)
¶
Creates a COG mosaic from a csv/txt file stored locally for through HTTP URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Local path or HTTP URL to the csv/txt file containing COG URLs. |
required |
skip_rows
|
int
|
The number of rows to skip in the file. Defaults to 0. |
0
|
titiler_endpoint
|
str
|
TiTiler endpoint. Defaults to "https://giswqs-titiler-endpoint.hf.space". |
None
|
username
|
str
|
User name for the titiler endpoint. Defaults to "anonymous". |
'anonymous'
|
layername
|
[type]
|
Layer name to use. Defaults to None. |
None
|
overwrite
|
bool
|
Whether to overwrite the layer name if existing. Defaults to False. |
False
|
verbose
|
bool
|
Whether to print out descriptive information. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
The tile URL for the COG mosaic. |
Source code in leafmap/stac.py
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 408 | |
cog_pixel_value(lon, lat, url, bidx, titiler_endpoint=None, verbose=True, **kwargs)
¶
Get pixel value from COG.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lon
|
float
|
Longitude of the pixel. |
required |
lat
|
float
|
Latitude of the pixel. |
required |
url
|
str
|
HTTP URL to a COG, e.g., 'https://github.com/opengeos/data/releases/download/raster/Libya-2023-07-01.tif' |
required |
bidx
|
str
|
Dataset band indexes (e.g bidx=1, bidx=1&bidx=2&bidx=3). Defaults to None. |
required |
titiler_endpoint
|
str
|
TiTiler endpoint, e.g., "https://giswqs-titiler-endpoint.hf.space", "planetary-computer", "pc". Defaults to None. |
None
|
verbose
|
bool
|
Print status messages. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List
|
A dictionary of band info. |
Source code in leafmap/stac.py
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 | |
cog_stats(url, titiler_endpoint=None)
¶
Get band statistics of a Cloud Optimized GeoTIFF (COG).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
HTTP URL to a COG, e.g., https://opendata.digitalglobe.com/events/mauritius-oil-spill/post-event/2020-08-12/105001001F1B5B00/105001001F1B5B00.tif |
required |
titiler_endpoint
|
str
|
TiTiler endpoint. Defaults to "https://giswqs-titiler-endpoint.hf.space". |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
list |
List
|
A dictionary of band statistics. |
Source code in leafmap/stac.py
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 | |
cog_tile(url, bands=None, titiler_endpoint=None, **kwargs)
¶
Get a tile layer from a Cloud Optimized GeoTIFF (COG). Source code adapted from https://developmentseed.org/titiler/examples/notebooks/Working_with_CloudOptimizedGeoTIFF_simple/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
HTTP URL to a COG, e.g., https://opendata.digitalglobe.com/events/mauritius-oil-spill/post-event/2020-08-12/105001001F1B5B00/105001001F1B5B00.tif. Default to None |
required |
bands
|
list
|
List of bands to use. Defaults to None. |
None
|
titiler_endpoint
|
str
|
TiTiler endpoint. Defaults to "https://giswqs-titiler-endpoint.hf.space". |
None
|
**kwargs
|
Any
|
Additional arguments to pass to the titiler endpoint. For more information about the available arguments, see https://developmentseed.org/titiler/endpoints/cog/#tiles.
For example, to apply a rescaling to multiple bands, use something like |
{}
|
Returns:
| Type | Description |
|---|---|
Tuple
|
The COG tile layer URL and bounds. |
Source code in leafmap/stac.py
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 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 243 244 245 246 247 248 249 250 251 252 253 | |
cog_tile_vmin_vmax(url, bands=None, titiler_endpoint=None, percentile=True, **kwargs)
¶
Get a tile layer from a Cloud Optimized GeoTIFF (COG) and return the minimum and maximum values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
HTTP URL to a COG, e.g., https://opendata.digitalglobe.com/events/mauritius-oil-spill/post-event/2020-08-12/105001001F1B5B00/105001001F1B5B00.tif |
required |
bands
|
list
|
List of bands to use. Defaults to None. |
None
|
titiler_endpoint
|
str
|
TiTiler endpoint. Defaults to "https://giswqs-titiler-endpoint.hf.space". |
None
|
percentile
|
bool
|
Whether to use percentiles or not. Defaults to True. |
True
|
Source code in leafmap/stac.py
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 | |
cog_validate(source, verbose=False)
¶
Validate Cloud Optimized Geotiff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
A dataset path or URL. Will be opened in "r" mode. |
required |
verbose
|
bool
|
Whether to print the output of the validation. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If the rio-cogeo package is not installed. |
FileNotFoundError
|
If the provided file could not be found. |
Returns:
| Type | Description |
|---|---|
Tuple[bool, List[str], List[str]]
|
A tuple containing the validation results (True if src_path is a valid COG, list of validation errors, and a list of validation warnings). |
Source code in leafmap/common.py
4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 | |
color_code_dataframe(data, legend_dict)
¶
Converts values in a dataframe to color codes based on a legend dictionary.
This function takes a dataframe (or path to a dataframe) and a legend dictionary and returns a new dataframe with values replaced by their corresponding color codes. It supports both numeric range legends and categorical legends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[str, DataFrame, GeoDataFrame]
|
Input data source, can be: - Path to a CSV file or geospatial file - pandas DataFrame - geopandas GeoDataFrame |
required |
legend_dict
|
Dict[str, str]
|
Dictionary mapping values to colors, can be: - Numeric ranges ("[ 100000, 200000]") mapped to color codes - Categorical values ("low", "medium") mapped to color codes - Can include a "Nodata" key for None/NaN values |
required |
Returns:
| Type | Description |
|---|---|
Union[DataFrame, GeoDataFrame]
|
A new dataframe with values replaced by color codes, preserving the |
Union[DataFrame, GeoDataFrame]
|
input data type (DataFrame or GeoDataFrame) |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input data type is not supported |
ValueError
|
If the file format is not supported |
Examples:
1 2 3 4 5 6 7 | |
1 2 3 4 5 6 7 8 9 | |
Source code in leafmap/common.py
18566 18567 18568 18569 18570 18571 18572 18573 18574 18575 18576 18577 18578 18579 18580 18581 18582 18583 18584 18585 18586 18587 18588 18589 18590 18591 18592 18593 18594 18595 18596 18597 18598 18599 18600 18601 18602 18603 18604 18605 18606 18607 18608 18609 18610 18611 18612 18613 18614 18615 18616 18617 18618 18619 18620 18621 18622 18623 18624 18625 18626 18627 18628 18629 18630 18631 18632 18633 18634 18635 18636 18637 18638 18639 18640 18641 18642 18643 18644 18645 18646 18647 18648 18649 18650 18651 18652 18653 18654 18655 18656 18657 18658 18659 18660 18661 18662 18663 18664 18665 18666 18667 18668 18669 18670 18671 18672 18673 18674 18675 18676 18677 18678 18679 18680 18681 18682 18683 18684 18685 18686 18687 18688 18689 18690 18691 18692 18693 18694 18695 18696 18697 18698 18699 18700 18701 18702 18703 18704 18705 18706 18707 18708 18709 18710 18711 18712 18713 18714 18715 18716 18717 18718 18719 18720 18721 18722 18723 18724 18725 18726 18727 18728 18729 18730 18731 18732 18733 18734 18735 18736 18737 18738 18739 18740 18741 18742 18743 18744 18745 18746 18747 18748 18749 18750 18751 18752 18753 18754 18755 18756 18757 18758 18759 18760 18761 18762 18763 18764 | |
configure_jupyterhub(base_url=None)
¶
Auto-configure leafmap for JupyterHub environments.
This function automatically detects if running in a JupyterHub environment and configures the necessary environment variables for tile server proxying. It will be called automatically by add_duckdb_layer, so you typically don't need to call it manually.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
The base URL of your JupyterHub instance (e.g., "https://jupyter.example.com"). Required for MapLibre vector tiles due to URL validation requirements. If not provided, vector tiles may not work. |
None
|
Example
import leafmap
Specify your JupyterHub URL for vector tile support¶
leafmap.configure_jupyterhub("https://your-jupyterhub-domain.com")
Now add_duckdb_layer will work correctly¶
Note
MapLibre GL JS's vector tile sources require absolute URLs (with http:// or https://). Raster tiles (add_raster) work with relative URLs, but vector tiles (add_duckdb_layer) do not. This is a limitation of MapLibre GL JS, not leafmap.
Source code in leafmap/common.py
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 | |
connect_points_as_line(gdf, sort_column=None, crs='EPSG:4326', single_line=True)
¶
Connects points in a GeoDataFrame into either a single LineString or multiple LineStrings based on a specified sort column or the index if no column is provided. The resulting GeoDataFrame will have the specified CRS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
A GeoDataFrame containing point geometries. |
required |
sort_column
|
Optional[str]
|
Column name to sort the points by (e.g., 'timestamp'). If None, the index is used for sorting. Defaults to None. |
None
|
crs
|
str
|
The coordinate reference system (CRS) for the resulting GeoDataFrame. Defaults to "EPSG:4326". |
'EPSG:4326'
|
single_line
|
bool
|
If True, generates a single LineString connecting all points. If False, generates multiple LineStrings, each connecting two consecutive points. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
A new GeoDataFrame containing either a single LineString or multiple LineString geometries. based on the single_line parameter, with the specified CRS. |
Example
line_gdf = connect_points_as_line(gdf, 'timestamp', crs="EPSG:3857", single_line=True) line_gdf = connect_points_as_line(gdf, single_line=False) # Uses index and defaults to EPSG:4326
Source code in leafmap/common.py
17965 17966 17967 17968 17969 17970 17971 17972 17973 17974 17975 17976 17977 17978 17979 17980 17981 17982 17983 17984 17985 17986 17987 17988 17989 17990 17991 17992 17993 17994 17995 17996 17997 17998 17999 18000 18001 18002 18003 18004 18005 18006 18007 18008 18009 18010 18011 18012 | |
connect_postgis(database, host='localhost', user=None, password=None, port=5432, use_env_var=False)
¶
Connects to a PostGIS database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
database
|
str
|
Name of the database |
required |
host
|
str
|
Hosting server for the database. Defaults to "localhost". |
'localhost'
|
user
|
str
|
User name to access the database. Defaults to None. |
None
|
password
|
str
|
Password to access the database. Defaults to None. |
None
|
port
|
int
|
Port number to connect to at the server host. Defaults to 5432. |
5432
|
use_env_var
|
bool
|
Whether to use environment variables. It set to True, user and password are treated as an environment variables with default values user="SQL_USER" and password="SQL_PASSWORD". Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If user is not specified. |
ValueError
|
If password is not specified. |
Returns:
| Type | Description |
|---|---|
Any
|
A SQLAlchemy engine connection string or engine object. |
Source code in leafmap/common.py
1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 | |
construct_bbox(*args, buffer=0.001, crs='EPSG:4326', return_gdf=False)
¶
Construct a bounding box (bbox) geometry based on either a centroid point or bbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Union[float, Tuple[float, float, float, float]]
|
Coordinates for the geometry. - If 2 arguments are provided, it is interpreted as a centroid (x, y) with a buffer. - If 4 arguments are provided, it is interpreted as a bbox (minx, miny, maxx, maxy). |
()
|
buffer
|
float
|
The buffer distance around the centroid point (default is 0.01 degrees). |
0.001
|
crs
|
str
|
The coordinate reference system (default is "EPSG:4326"). |
'EPSG:4326'
|
return_gdf
|
bool
|
Whether to return a GeoDataFrame (default is False). |
False
|
Returns:
| Type | Description |
|---|---|
Union[Polygon, GeoDataFrame]
|
The constructed bounding box (Polygon). |
Source code in leafmap/common.py
17244 17245 17246 17247 17248 17249 17250 17251 17252 17253 17254 17255 17256 17257 17258 17259 17260 17261 17262 17263 17264 17265 17266 17267 17268 17269 17270 17271 17272 17273 17274 17275 17276 17277 17278 17279 17280 17281 17282 17283 17284 17285 | |
convert_coordinates(x, y, source_crs, target_crs='epsg:4326')
¶
Convert coordinates from the source EPSG code to the target EPSG code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
The x-coordinate of the point. |
required |
y
|
float
|
The y-coordinate of the point. |
required |
source_crs
|
str
|
The EPSG code of the source coordinate system. |
required |
target_crs
|
str
|
The EPSG code of the target coordinate system. Defaults to '4326' (EPSG code for WGS84). |
'epsg:4326'
|
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
A tuple containing the converted longitude and latitude. |
Source code in leafmap/common.py
16283 16284 16285 16286 16287 16288 16289 16290 16291 16292 16293 16294 16295 16296 16297 16298 16299 16300 16301 16302 16303 16304 16305 16306 16307 | |
convert_lidar(source, destination=None, point_format_id=None, file_version=None, **kwargs)
¶
Converts a Las from one point format to another Automatically upgrades the file version if source file version is not compatible with the new point_format_id
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | LasBase
|
The source data to be converted. |
required |
destination
|
str
|
The destination file path. Defaults to None. |
None
|
point_format_id
|
int
|
The new point format id (the default is None, which won't change the source format id). |
None
|
file_version
|
str
|
The new file version. None by default which means that the file_version may be upgraded for compatibility with the new point_format. The file version will not be downgraded. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The converted LasData object. |
Source code in leafmap/common.py
5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 | |
convert_to_cog(images, output_dir, prefix='', suffix='_cog', extra_options=None)
¶
Convert all .tif files in a directory to Cloud Optimized GeoTIFFs (COGs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
str | list
|
Input directory containing .tif files, or a list of .tif file paths. |
required |
output_dir
|
str
|
Path to the output directory where COGs will be saved. |
required |
prefix
|
str
|
Prefix to add to the output filenames. |
''
|
suffix
|
str
|
Suffix to add to the output filenames before the .tif extension. |
'_cog'
|
extra_options
|
List[str]
|
Additional gdal_translate options. Example: ["-co", "TILED=YES", "-co", "BLOCKSIZE=512"] |
None
|
Source code in leafmap/common.py
19511 19512 19513 19514 19515 19516 19517 19518 19519 19520 19521 19522 19523 19524 19525 19526 19527 19528 19529 19530 19531 19532 19533 19534 19535 19536 19537 19538 19539 19540 19541 19542 19543 19544 19545 19546 19547 19548 19549 19550 19551 | |
convert_to_gdf(data, geometry=None, lat=None, lon=None, crs='EPSG:4326', included=None, excluded=None, obj_to_str=False, open_args=None, **kwargs)
¶
Convert data to a GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[DataFrame, str]
|
The input data, either as a DataFrame or a file path. |
required |
geometry
|
Optional[str]
|
The column name containing geometry data. Defaults to None. |
None
|
lat
|
Optional[str]
|
The column name containing latitude data. Defaults to None. |
None
|
lon
|
Optional[str]
|
The column name containing longitude data. Defaults to None. |
None
|
crs
|
str
|
The coordinate reference system to use. Defaults to "EPSG:4326". |
'EPSG:4326'
|
included
|
Optional[List[str]]
|
List of columns to include. Defaults to None. |
None
|
excluded
|
Optional[List[str]]
|
List of columns to exclude. Defaults to None. |
None
|
obj_to_str
|
bool
|
Whether to convert object dtype columns to string. Defaults to False. |
False
|
open_args
|
Optional[Dict[str, Any]]
|
Additional arguments for file opening functions. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional keyword arguments for GeoDataFrame creation. |
{}
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
The converted GeoDataFrame. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the file format is unsupported or required columns are not provided. |
Source code in leafmap/common.py
16995 16996 16997 16998 16999 17000 17001 17002 17003 17004 17005 17006 17007 17008 17009 17010 17011 17012 17013 17014 17015 17016 17017 17018 17019 17020 17021 17022 17023 17024 17025 17026 17027 17028 17029 17030 17031 17032 17033 17034 17035 17036 17037 17038 17039 17040 17041 17042 17043 17044 17045 17046 17047 17048 17049 17050 17051 17052 17053 17054 17055 17056 17057 17058 17059 17060 17061 17062 17063 17064 17065 17066 17067 17068 17069 17070 17071 17072 17073 17074 17075 17076 17077 17078 17079 17080 17081 17082 17083 17084 17085 17086 17087 17088 17089 17090 17091 17092 17093 17094 17095 17096 17097 | |
coords_to_geojson(coords)
¶
Convert a list of bbox coordinates representing [left, bottom, right, top] to geojson FeatureCollection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
list
|
A list of bbox coordinates representing [left, bottom, right, top]. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
A geojson FeatureCollection. |
Source code in leafmap/common.py
1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 | |
coords_to_vector(coords, output=None, crs='EPSG:4326', **kwargs)
¶
Convert a list of coordinates to a GeoDataFrame or a vector file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
list
|
A list of coordinates in the format of [(x1, y1), (x2, y2), ...]. |
required |
output
|
str
|
The path to the output vector file. Defaults to None. |
None
|
crs
|
str
|
The CRS of the coordinates. Defaults to "EPSG:4326". |
'EPSG:4326'
|
Returns:
| Type | Description |
|---|---|
Any
|
A GeoDataFrame of the coordinates. |
Source code in leafmap/common.py
11179 11180 11181 11182 11183 11184 11185 11186 11187 11188 11189 11190 11191 11192 11193 11194 11195 11196 11197 11198 11199 11200 11201 11202 11203 11204 11205 11206 11207 | |
coords_to_xy(src_fp, coords, coord_crs='epsg:4326', request_payer='bucket-owner', env_args={}, open_args={}, **kwargs)
¶
Converts a list of coordinates to pixel coordinates, i.e., (col, row) coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src_fp
|
str
|
The source raster file path. |
required |
coords
|
list
|
A list of coordinates in the format of [[x1, y1], [x2, y2], ...] |
required |
coord_crs
|
str
|
The coordinate CRS of the input coordinates. Defaults to "epsg:4326". |
'epsg:4326'
|
request_payer
|
str
|
Specifies who pays for the download from S3. Can be "bucket-owner" or "requester". Defaults to "bucket-owner". |
'bucket-owner'
|
env_args
|
dict
|
Additional keyword arguments to pass to rasterio.Env. |
{}
|
open_args
|
dict
|
Additional keyword arguments to pass to rasterio.open. |
{}
|
**kwargs
|
Any
|
Additional keyword arguments to pass to rasterio.transform.rowcol. |
{}
|
Returns:
| Type | Description |
|---|---|
list
|
A list of pixel coordinates in the format of [[x1, y1], [x2, y2], ...] |
Source code in leafmap/common.py
10314 10315 10316 10317 10318 10319 10320 10321 10322 10323 10324 10325 10326 10327 10328 10329 10330 10331 10332 10333 10334 10335 10336 10337 10338 10339 10340 10341 10342 10343 10344 10345 10346 10347 10348 10349 10350 10351 10352 10353 10354 10355 10356 10357 10358 10359 10360 10361 10362 10363 10364 10365 10366 10367 | |
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. Defaults to ''. |
''
|
where
|
str
|
Where to add the new code cell. It can be one of the following: above, below, at_bottom. Defaults to 'below'. |
'below'
|
Source code in leafmap/common.py
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
create_download_link(filename, title='Click here to download: ', basename=None)
¶
Downloads a file from voila. Adopted from https://github.com/voila-dashboards/voila/issues/578
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str
|
The file path to the file to download |
required |
title
|
str
|
str. Defaults to "Click here to download: ". |
'Click here to download: '
|
Returns:
| Type | Description |
|---|---|
Any
|
HTML download URL. |
Source code in leafmap/common.py
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 | |
create_legend(title='Legend', labels=None, colors=None, legend_dict=None, builtin_legend=None, opacity=1.0, position='bottomright', draggable=True, output=None, style={}, shape_type='rectangle')
¶
Create a legend in HTML format. Reference: https://bit.ly/3oV6vnH
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Title of the legend. Defaults to 'Legend'. Defaults to "Legend". |
'Legend'
|
colors
|
list
|
A list of legend colors. Defaults to None. |
None
|
labels
|
list
|
A list of legend labels. Defaults to None. |
None
|
legend_dict
|
dict
|
A dictionary containing legend items as keys and color as values. If provided, legend_keys and legend_colors will be ignored. Defaults to None. |
None
|
builtin_legend
|
str
|
Name of the builtin legend to add to the map. Defaults to None. |
None
|
opacity
|
float
|
The opacity of the legend. Defaults to 1.0. |
1.0
|
position
|
str
|
The position of the legend, can be one of the following: "topleft", "topright", "bottomleft", "bottomright". Defaults to "bottomright". |
'bottomright'
|
draggable
|
bool
|
If True, the legend can be dragged to a new position. Defaults to True. |
True
|
output
|
str
|
The output file path (*.html) to save the legend. Defaults to None. |
None
|
style
|
dict
|
Additional keyword arguments to style the legend, such as position, bottom, right, z-index, border, background-color, border-radius, padding, font-size, etc. The default style is: style = { 'position': 'fixed', 'z-index': '9999', 'border': '2px solid grey', 'background-color': 'rgba(255, 255, 255, 0.8)', 'border-radius': '5px', 'padding': '10px', 'font-size': '14px', 'bottom': '20px', 'right': '5px' } |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The HTML code of the legend. |
Source code in leafmap/common.py
7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 | |
create_lines_from_points(src_points, dst_points, col='id', distance_col='distance', decimal_places=2, return_gdf=False)
¶
Create LineString features between matching point features from two GeoJSON FeatureCollections based on a shared column (default is 'id').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src_points
|
Union[dict, str, GeoDataFrame]
|
Source GeoJSON FeatureCollection with point features. |
required |
dst_points
|
Union[dict, str, GeoDataFrame]
|
Destination GeoJSON FeatureCollection with point features. |
required |
col
|
str
|
The property name to match features between the two collections. |
'id'
|
distance_col
|
str
|
The name of the column to store the distance between the points. |
'distance'
|
decimal_places
|
int
|
The number of decimal places to round the distance to. |
2
|
return_gdf
|
bool
|
If True, returns a GeoDataFrame instead of a dictionary. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
dict
|
A GeoJSON FeatureCollection containing LineString features. |
Source code in leafmap/common.py
19079 19080 19081 19082 19083 19084 19085 19086 19087 19088 19089 19090 19091 19092 19093 19094 19095 19096 19097 19098 19099 19100 19101 19102 19103 19104 19105 19106 19107 19108 19109 19110 19111 19112 19113 19114 19115 19116 19117 19118 19119 19120 19121 19122 19123 19124 19125 19126 19127 19128 19129 19130 19131 19132 19133 19134 19135 19136 19137 19138 19139 19140 19141 19142 19143 19144 19145 | |
create_mosaicjson(images, output)
¶
Create a mosaicJSON file from a list of images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
str | list
|
A list of image URLs or a URL to a text file containing a list of image URLs. |
required |
output
|
str
|
The output mosaicJSON file path. |
required |
Source code in leafmap/stac.py
2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 | |
create_timelapse(images, out_gif, ext='.tif', bands=None, size=None, bbox=None, fps=5, loop=0, add_progress_bar=True, progress_bar_color='blue', progress_bar_height=5, add_text=False, text_xy=None, text_sequence=None, font_type='arial.ttf', font_size=20, font_color='black', mp4=False, quiet=True, reduce_size=False, clean_up=True, **kwargs)
¶
Creates a timelapse gif from a list of images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
images
|
list | str
|
The list of images or input directory to create the gif from. For example, '/path/to/images/*.tif' or ['/path/to/image1.tif', '/path/to/image2.tif', ...] |
required |
out_gif
|
str
|
File path to the output gif. |
required |
ext
|
str
|
The extension of the images. Defaults to '.tif'. |
'.tif'
|
bands
|
list
|
The bands to use for the gif. For example, [0, 1, 2] for RGB, and [0] for grayscale. Defaults to None. |
None
|
size
|
tuple
|
The size of the gif. For example, (500, 500). Defaults to None, using the original size. |
None
|
bbox
|
list
|
The bounding box of the gif. For example, [xmin, ymin, xmax, ymax]. Defaults to None, using the original bounding box. |
None
|
fps
|
int
|
The frames per second of the gif. Defaults to 5. |
5
|
loop
|
int
|
The number of times to loop the gif. Defaults to 0, looping forever. |
0
|
add_progress_bar
|
bool
|
Whether to add a progress bar to the gif. Defaults to True. |
True
|
progress_bar_color
|
str
|
The color of the progress bar, can be color name or hex code. Defaults to 'blue'. |
'blue'
|
progress_bar_height
|
int
|
The height of the progress bar. Defaults to 5. |
5
|
add_text
|
bool
|
Whether to add text to the gif. Defaults to False. |
False
|
text_xy
|
tuple
|
The x, y coordinates of the text. For example, ('10%', '10%'). Defaults to None, using the bottom left corner. |
None
|
text_sequence
|
list
|
The sequence of text to add to the gif. For example, ['year 1', 'year 2', ...]. |
None
|
font_type
|
str
|
The font type of the text, can be 'arial.ttf' or 'alibaba.otf', or any system font. Defaults to 'arial.ttf'. |
'arial.ttf'
|
font_size
|
int
|
The font size of the text. Defaults to 20. |
20
|
font_color
|
str
|
The color of the text, can be color name or hex code. Defaults to 'black'. |
'black'
|
mp4
|
bool
|
Whether to convert the gif to mp4. Defaults to False. |
False
|
quiet
|
bool
|
Whether to print the progress. Defaults to False. |
True
|
reduce_size
|
bool
|
Whether to reduce the size of the gif using ffmpeg. Defaults to False. |
False
|
clean_up
|
bool
|
Whether to clean up the temporary files. Defaults to True. |
True
|
Source code in leafmap/common.py
8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 | |
csv_points_to_shp(in_csv, out_shp, latitude='latitude', longitude='longitude')
¶
Converts a csv file containing points (latitude, longitude) into a shapefile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_csv
|
str
|
File path or HTTP URL to the input csv file. For example, https://raw.githubusercontent.com/opengeos/data/main/world/world_cities.csv |
required |
out_shp
|
str
|
File path to the output shapefile. |
required |
latitude
|
str
|
Column name for the latitude column. Defaults to 'latitude'. |
'latitude'
|
longitude
|
str
|
Column name for the longitude column. Defaults to 'longitude'. |
'longitude'
|
Source code in leafmap/common.py
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 | |
csv_to_df(in_csv, **kwargs)
¶
Converts a CSV file to pandas dataframe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_csv
|
str
|
File path to the input CSV. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
A pandas DataFrame. |
Source code in leafmap/common.py
1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 | |
csv_to_gdf(in_csv, latitude='latitude', longitude='longitude', geometry=None, crs='EPSG:4326', encoding='utf-8', **kwargs)
¶
Creates points for a CSV file and converts them to a GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_csv
|
str
|
The file path to the input CSV file. |
required |
latitude
|
str
|
The name of the column containing latitude coordinates. Defaults to "latitude". |
'latitude'
|
longitude
|
str
|
The name of the column containing longitude coordinates. Defaults to "longitude". |
'longitude'
|
geometry
|
str
|
The name of the column containing geometry. Defaults to None. |
None
|
crs
|
str
|
The coordinate reference system. Defaults to "EPSG:4326". |
'EPSG:4326'
|
encoding
|
str
|
The encoding of characters. Defaults to "utf-8". |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
A GeoDataFrame. |
Source code in leafmap/common.py
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 | |
csv_to_geojson(in_csv, out_geojson=None, latitude='latitude', longitude='longitude', encoding='utf-8')
¶
Creates points for a CSV file and exports data as a GeoJSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_csv
|
str
|
The file path to the input CSV file. |
required |
out_geojson
|
str
|
The file path to the exported GeoJSON. Default to None. |
None
|
latitude
|
str
|
The name of the column containing latitude coordinates. Defaults to "latitude". |
'latitude'
|
longitude
|
str
|
The name of the column containing longitude coordinates. Defaults to "longitude". |
'longitude'
|
encoding
|
str
|
The encoding of characters. Defaults to "utf-8". |
'utf-8'
|
Source code in leafmap/common.py
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 | |
csv_to_shp(in_csv, out_shp, latitude='latitude', longitude='longitude', encoding='utf-8')
¶
Converts a csv file with latlon info to a point shapefile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_csv
|
str
|
The input csv file containing longitude and latitude columns. |
required |
out_shp
|
str
|
The file path to the output shapefile. |
required |
latitude
|
str
|
The column name of the latitude column. Defaults to 'latitude'. |
'latitude'
|
longitude
|
str
|
The column name of the longitude column. Defaults to 'longitude'. |
'longitude'
|
Source code in leafmap/common.py
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 | |
csv_to_vector(in_csv, output, latitude='latitude', longitude='longitude', geometry=None, crs='EPSG:4326', encoding='utf-8', **kwargs)
¶
Creates points for a CSV file and converts them to a vector dataset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_csv
|
str
|
The file path to the input CSV file. |
required |
output
|
str
|
The file path to the output vector dataset. |
required |
latitude
|
str
|
The name of the column containing latitude coordinates. Defaults to "latitude". |
'latitude'
|
longitude
|
str
|
The name of the column containing longitude coordinates. Defaults to "longitude". |
'longitude'
|
geometry
|
str
|
The name of the column containing geometry. Defaults to None. |
None
|
crs
|
str
|
The coordinate reference system. Defaults to "EPSG:4326". |
'EPSG:4326'
|
encoding
|
str
|
The encoding of characters. Defaults to "utf-8". |
'utf-8'
|
**kwargs
|
Any
|
Additional keyword arguments to pass to gdf.to_file(). |
{}
|
Source code in leafmap/common.py
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 | |
d2s_tile(url, titiler_endpoint=None, **kwargs)
¶
Generate a D2S tile URL with optional API key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The base URL for the tile. |
required |
titiler_endpoint
|
str
|
The endpoint for the titiler service. Defaults to "https://tt.d2s.org". |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the cog_stats function. |
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The modified URL with the API key if required, otherwise the original URL. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the API key is required but not set in the environment variables. |
Source code in leafmap/common.py
16963 16964 16965 16966 16967 16968 16969 16970 16971 16972 16973 16974 16975 16976 16977 16978 16979 16980 16981 16982 16983 16984 16985 16986 16987 16988 16989 16990 16991 16992 | |
delete_shp(in_shp, verbose=False)
¶
Deletes a shapefile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_shp
|
str
|
The input shapefile to delete. |
required |
verbose
|
bool
|
Whether to print out descriptive text. Defaults to True. |
False
|
Source code in leafmap/common.py
1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 | |
df_to_gdf(df, geometry='geometry', src_crs='EPSG:4326', dst_crs=None, **kwargs)
¶
Converts a pandas DataFrame to a GeoPandas GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The pandas DataFrame to convert. |
required |
geometry
|
str
|
The name of the geometry column in the DataFrame. |
'geometry'
|
src_crs
|
str
|
The coordinate reference system (CRS) of the GeoDataFrame. Default is "EPSG:4326". |
'EPSG:4326'
|
dst_crs
|
str
|
The target CRS of the GeoDataFrame. Default is None |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The converted GeoPandas GeoDataFrame. |
Source code in leafmap/common.py
15129 15130 15131 15132 15133 15134 15135 15136 15137 15138 15139 15140 15141 15142 15143 15144 15145 15146 15147 15148 15149 15150 15151 15152 15153 15154 15155 | |
df_to_geojson(df, out_geojson=None, latitude='latitude', longitude='longitude', encoding='utf-8')
¶
Creates points for a Pandas DataFrame and exports data as a GeoJSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The input Pandas DataFrame. |
required |
out_geojson
|
str
|
The file path to the exported GeoJSON. Default to None. |
None
|
latitude
|
str
|
The name of the column containing latitude coordinates. Defaults to "latitude". |
'latitude'
|
longitude
|
str
|
The name of the column containing longitude coordinates. Defaults to "longitude". |
'longitude'
|
encoding
|
str
|
The encoding of characters. Defaults to "utf-8". |
'utf-8'
|
Source code in leafmap/common.py
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 | |
dict_to_json(data, file_path, indent=4)
¶
Writes a dictionary to a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
A dictionary. |
required |
file_path
|
str
|
The path to the JSON file. |
required |
indent
|
int
|
The indentation of the JSON file. Defaults to 4. |
4
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input data is not a dictionary. |
Source code in leafmap/common.py
4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 | |
disjoint(input_features, selecting_features, output=None, **kwargs)
¶
Find the features in the input_features that do not intersect the selecting_features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_features
|
str | GeoDataFrame
|
The input features to select from. Can be a file path or a GeoDataFrame. |
required |
selecting_features
|
str | GeoDataFrame
|
The features in the Input Features parameter will be selected based on their relationship to the features from this layer. |
required |
output
|
are
|
The output path to save the GeoDataFrame in a vector format (e.g., shapefile). Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The path to the output file or the GeoDataFrame. |
Source code in leafmap/common.py
9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 | |
display_html(html, width='100%', height=500)
¶
Displays an HTML file or HTML string in a Jupyter Notebook.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
html
|
Union[str, bytes]
|
Path to an HTML file or an HTML string. |
required |
width
|
str
|
Width of the displayed iframe. Default is '100%'. |
'100%'
|
height
|
int
|
Height of the displayed iframe. Default is 500. |
500
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/common.py
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 | |
download_data_catalogs(out_dir=None, quiet=True, overwrite=False)
¶
Download geospatial data catalogs from https://github.com/giswqs/geospatial-data-catalogs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_dir
|
str
|
The output directory. Defaults to None. |
None
|
quiet
|
bool
|
Whether to suppress the download progress bar. Defaults to True. |
True
|
overwrite
|
bool
|
Whether to overwrite the existing data catalog. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The path to the downloaded data catalog. |
Source code in leafmap/stac.py
1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 | |
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, subfolder=False)
¶
Download a file from URL, including Google Drive shared URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Google Drive URL is also supported. Defaults to None. |
None
|
output
|
str
|
Output filename. Default is basename of URL. |
None
|
quiet
|
bool
|
Suppress terminal output. Default is False. |
False
|
proxy
|
str
|
Proxy. Defaults to None. |
None
|
speed
|
float
|
Download byte size per second (e.g., 256KB/s = 256 * 1024). Defaults to None. |
None
|
use_cookies
|
bool
|
Flag to use cookies. Defaults to True. |
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. Default is True.. Defaults to True. |
True
|
id
|
str
|
Google Drive's file ID. Defaults to None. |
None
|
fuzzy
|
bool
|
Fuzzy extraction of Google Drive's file Id. Defaults to False. |
False
|
resume
|
bool
|
Resume the download from existing tmp file if possible. Defaults to False. |
False
|
unzip
|
bool
|
Unzip the file. Defaults to True. |
True
|
overwrite
|
bool
|
Overwrite the file if it already exists. Defaults to False. |
False
|
subfolder
|
bool
|
Create a subfolder with the same name as the file. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
The output file path. |
Source code in leafmap/common.py
5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 | |
download_file_lite(url, output=None, binary=False, overwrite=False, **kwargs)
async
¶
Download a file using Pyodide. This function is only available on JupyterLite. Call the function with await, such as await download_file_lite(url).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the file. |
required |
output
|
str
|
The local path to save the file. Defaults to None. |
None
|
binary
|
bool
|
Whether the file is binary. Defaults to False. |
False
|
overwrite
|
bool
|
Whether to overwrite the file if it exists. Defaults to False. |
False
|
Source code in leafmap/common.py
7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 | |
download_files(urls, out_dir=None, filenames=None, quiet=False, proxy=None, speed=None, use_cookies=True, verify=True, id=None, fuzzy=False, resume=False, unzip=True, overwrite=False, subfolder=False, multi_part=False)
¶
Download files from URLs, including Google Drive shared URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
urls
|
list
|
The list of urls to download. Google Drive URL is also supported. |
required |
out_dir
|
str
|
The output directory. Defaults to None. |
None
|
filenames
|
list
|
Output filename. Default is basename of URL. |
None
|
quiet
|
bool
|
Suppress terminal output. Default is False. |
False
|
proxy
|
str
|
Proxy. Defaults to None. |
None
|
speed
|
float
|
Download byte size per second (e.g., 256KB/s = 256 * 1024). Defaults to None. |
None
|
use_cookies
|
bool
|
Flag to use cookies. Defaults to True. |
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. Default is True.. Defaults to True. |
True
|
id
|
str
|
Google Drive's file ID. Defaults to None. |
None
|
fuzzy
|
bool
|
Fuzzy extraction of Google Drive's file Id. Defaults to False. |
False
|
resume
|
bool
|
Resume the download from existing tmp file if possible. Defaults to False. |
False
|
unzip
|
bool
|
Unzip the file. Defaults to True. |
True
|
overwrite
|
bool
|
Overwrite the file if it already exists. Defaults to False. |
False
|
subfolder
|
bool
|
Create a subfolder with the same name as the file. Defaults to False. |
False
|
multi_part
|
bool
|
If the file is a multi-part file. Defaults to False. |
False
|
1 2 3 4 | |
Source code in leafmap/common.py
5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 | |
download_folder(url=None, id=None, output=None, quiet=False, proxy=None, speed=None, use_cookies=True, remaining_ok=False)
¶
Downloads the entire folder from URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
URL of the Google Drive folder. Must be of the format 'https://drive.google.com/drive/folders/{url}'. Defaults to None. |
None
|
id
|
str
|
Google Drive's folder ID. Defaults to None. |
None
|
output
|
str
|
String containing the path of the output folder. Defaults to current working directory. |
None
|
quiet
|
bool
|
Suppress terminal output. Defaults to False. |
False
|
proxy
|
str
|
Proxy. Defaults to None. |
None
|
speed
|
float
|
Download byte size per second (e.g., 256KB/s = 256 * 1024). Defaults to None. |
None
|
use_cookies
|
bool
|
Flag to use cookies. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
Optional[List[str]]
|
List of files downloaded, or None if failed. |
Source code in leafmap/common.py
5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 | |
download_from_url(url, out_file_name=None, out_dir='.', unzip=True, verbose=True)
¶
Download a file from a URL (e.g., https://github.com/opengeos/whitebox-python/raw/master/examples/testdata.zip)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The HTTP URL to download. |
required |
out_file_name
|
str
|
The output file name to use. Defaults to None. |
None
|
out_dir
|
str
|
The output directory to use. Defaults to '.'. |
'.'
|
unzip
|
bool
|
Whether to unzip the downloaded file if it is a zip file. Defaults to True. |
True
|
verbose
|
bool
|
Whether to display or not the output of the function |
True
|
Source code in leafmap/common.py
726 727 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 | |
download_google_buildings(location, out_dir=None, merge_output=None, head=None, keep_geojson=False, overwrite=False, quiet=False, **kwargs)
¶
Download Google Open Building dataset for a specific location. Check the dataset links from https://sites.research.google/open-buildings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
str
|
The location name for which to download the dataset. |
required |
out_dir
|
Optional[str]
|
The output directory to save the downloaded files. If not provided, the current working directory is used. |
None
|
merge_output
|
Optional[str]
|
Optional. The output file path for merging the downloaded files into a single GeoDataFrame. |
None
|
head
|
Optional[int]
|
Optional. The number of files to download. If not provided, all files will be downloaded. |
None
|
keep_geojson
|
bool
|
Optional. If True, the GeoJSON files will be kept after converting them to CSV files. |
False
|
overwrite
|
bool
|
Optional. If True, overwrite the existing files. |
False
|
quiet
|
bool
|
Optional. If True, suppresses the download progress messages. |
False
|
**kwargs
|
Any
|
Additional keyword arguments to be passed to the |
{}
|
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of file paths of the downloaded files. |
Source code in leafmap/common.py
12259 12260 12261 12262 12263 12264 12265 12266 12267 12268 12269 12270 12271 12272 12273 12274 12275 12276 12277 12278 12279 12280 12281 12282 12283 12284 12285 12286 12287 12288 12289 12290 12291 12292 12293 12294 12295 12296 12297 12298 12299 12300 12301 12302 12303 12304 12305 12306 12307 12308 12309 12310 12311 12312 12313 12314 12315 12316 12317 12318 12319 12320 12321 12322 12323 12324 12325 12326 12327 12328 12329 12330 12331 12332 12333 12334 12335 12336 12337 12338 12339 12340 12341 12342 12343 12344 12345 12346 12347 12348 12349 12350 12351 12352 12353 12354 | |
download_mapillary_image(image_id, output=None, resolution='original', access_token=None, quiet=True, **kwargs)
¶
Downloads a Mapillary image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_id
|
str
|
The ID of the Mapillary image. |
required |
output
|
str
|
The output file path. Defaults to None. |
None
|
resolution
|
str
|
The resolution of the image. Can be 256, 1024, 2048, or original. Defaults to "original". |
'original'
|
access_token
|
str
|
The access token for the Mapillary API. Defaults to None. |
None
|
quiet
|
bool
|
Whether to suppress output. Defaults to True. |
True
|
**kwargs
|
Any
|
Additional keyword arguments for the download. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/common.py
18362 18363 18364 18365 18366 18367 18368 18369 18370 18371 18372 18373 18374 18375 18376 18377 18378 18379 18380 18381 18382 18383 18384 18385 18386 18387 18388 18389 18390 18391 18392 | |
download_mapillary_images(image_ids, output_dir=None, resolution='original', **kwargs)
¶
Downloads multiple Mapillary images.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_ids
|
List[str]
|
A list of Mapillary image IDs. |
required |
output_dir
|
str
|
The directory to save the images. Defaults to the current working directory. |
None
|
resolution
|
str
|
The resolution of the images. Defaults to "original". |
'original'
|
**kwargs
|
Any
|
Additional keyword arguments for the download. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/common.py
18395 18396 18397 18398 18399 18400 18401 18402 18403 18404 18405 18406 18407 18408 18409 18410 18411 18412 18413 18414 18415 18416 18417 18418 18419 18420 18421 18422 | |
download_ms_buildings(location, out_dir=None, merge_output=None, head=None, quiet=False, **kwargs)
¶
Download Microsoft Buildings dataset for a specific location. Check the dataset links from https://minedbuildings.blob.core.windows.net/global-buildings/dataset-links.csv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
str
|
The location name for which to download the dataset. |
required |
out_dir
|
str
|
The output directory to save the downloaded files. If not provided, the current working directory is used. |
None
|
merge_output
|
str
|
The output file path for merging the downloaded files into a single GeoDataFrame. |
None
|
head
|
int
|
The number of files to download. If not provided, all files will be downloaded. |
None
|
quiet
|
bool
|
If True, suppresses the download progress messages. |
False
|
**kwargs
|
Any
|
Additional keyword arguments to be passed to the |
{}
|
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of file paths of the downloaded files. |
Source code in leafmap/common.py
12188 12189 12190 12191 12192 12193 12194 12195 12196 12197 12198 12199 12200 12201 12202 12203 12204 12205 12206 12207 12208 12209 12210 12211 12212 12213 12214 12215 12216 12217 12218 12219 12220 12221 12222 12223 12224 12225 12226 12227 12228 12229 12230 12231 12232 12233 12234 12235 12236 12237 12238 12239 12240 12241 12242 12243 12244 12245 12246 12247 12248 12249 12250 12251 12252 12253 12254 12255 12256 | |
download_ned(region, out_dir=None, return_url=False, download_args={}, geopandas_args={}, query={})
¶
Download the US National Elevation Datasets (NED) for a region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str | list
|
A filepath to a vector dataset or a list of bounds in the form of [minx, miny, maxx, maxy]. |
required |
out_dir
|
str
|
The directory to download the files to. Defaults to None, which uses the current working directory. |
None
|
return_url
|
bool
|
Whether to return the download URLs of the files. Defaults to False. |
False
|
download_args
|
dict
|
A dictionary of arguments to pass to the download_file function. Defaults to {}. |
{}
|
geopandas_args
|
dict
|
A dictionary of arguments to pass to the geopandas.read_file() function. Used for reading a region URL|filepath. |
{}
|
query
|
dict
|
A dictionary of arguments to pass to the The_national_map_USGS.find_details() function. See https://apps.nationalmap.gov/tnmaccess/#/product for more information. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[None, List]
|
A list of the download URLs of the files if return_url is True. |
Source code in leafmap/common.py
6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 | |
download_nlcd(years, out_dir=None, quiet=False, **kwargs)
¶
Downloads NLCD (National Land Cover Database) files for the specified years.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
years
|
List[int]
|
A list of years for which to download the NLCD files. |
required |
out_dir
|
str
|
The directory where the downloaded files will be saved. Defaults to the current working directory. |
None
|
quiet
|
bool
|
If True, suppresses download progress messages. Defaults to False. |
False
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the download_file function. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/common.py
17932 17933 17934 17935 17936 17937 17938 17939 17940 17941 17942 17943 17944 17945 17946 17947 17948 17949 17950 17951 17952 17953 17954 17955 17956 17957 17958 17959 17960 17961 17962 | |
download_tnm(region=None, out_dir=None, return_url=False, download_args={}, geopandas_args={}, API={})
¶
Download the US National Elevation Datasets (NED) for a region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str | list
|
An URL|filepath to a vector dataset Or a list of bounds in the form of [minx, miny, maxx, maxy]. Alternatively you could use API parameters such as polygon or bbox. |
None
|
out_dir
|
str
|
The directory to download the files to. Defaults to None, which uses the current working directory. |
None
|
return_url
|
bool
|
Whether to return the download URLs of the files. Defaults to False. |
False
|
download_args
|
dict
|
A dictionary of arguments to pass to the download_file function. Defaults to {}. |
{}
|
geopandas_args
|
dict
|
A dictionary of arguments to pass to the geopandas.read_file() function. Used for reading a region URL|filepath. |
{}
|
API
|
dict
|
A dictionary of arguments to pass to the The_national_map_USGS.find_details() function. Exposes most of the documented API. Defaults to {} |
{}
|
Returns:
| Type | Description |
|---|---|
Union[None, List]
|
A list of the download URLs of the files if return_url is True. |
Source code in leafmap/common.py
6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 | |
edit_download_html(htmlWidget, filename, title='Click here to download: ')
¶
Downloads a file from voila. Adopted from https://github.com/voila-dashboards/voila/issues/578#issuecomment-617668058
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
htmlWidget
|
object
|
The HTML widget to display the URL. |
required |
filename
|
str
|
File path to download. |
required |
title
|
str
|
Download description. Defaults to "Click here to download: ". |
'Click here to download: '
|
Source code in leafmap/common.py
833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 | |
ee_initialize(key_data=None, token_name='EE_SERVICE_ACCOUNT')
¶
Initialize the Earth Engine API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_data
|
Optional[str]
|
The key data to use for authentication. Must be a JSON string containing service account credentials, with at least a 'client_email' field (e.g., the contents of a Google service account key file). |
None
|
token_name
|
str
|
The name of the environment variable to use for authentication. |
'EE_SERVICE_ACCOUNT'
|
Source code in leafmap/common.py
20070 20071 20072 20073 20074 20075 20076 20077 20078 20079 20080 20081 20082 20083 20084 20085 20086 20087 20088 20089 20090 20091 20092 20093 20094 20095 20096 20097 | |
ee_tile_url(ee_object=None, vis_params={}, asset_id=None, ee_initialize=False, project_id=None, **kwargs)
¶
Adds a Google Earth Engine tile layer to the map based on the tile layer URL from https://github.com/opengeos/ee-tile-layers/blob/main/datasets.tsv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ee_object
|
object
|
The Earth Engine object to display. |
None
|
vis_params
|
dict
|
Visualization parameters. For example, {'min': 0, 'max': 100}. |
{}
|
asset_id
|
str
|
The ID of the Earth Engine asset. |
None
|
ee_initialize
|
bool
|
Whether to initialize the Earth Engine |
False
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/common.py
16912 16913 16914 16915 16916 16917 16918 16919 16920 16921 16922 16923 16924 16925 16926 16927 16928 16929 16930 16931 16932 16933 16934 16935 16936 16937 16938 16939 16940 16941 16942 16943 16944 16945 16946 16947 16948 16949 16950 16951 16952 16953 16954 16955 16956 16957 16958 16959 16960 | |
evaluate_model(df, y_col='y', y_pred_col='y_pred', metrics=None, drop_na=True, filter_nonzero=True)
¶
Evaluates the model performance on the given dataframe with customizable options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
A pandas DataFrame with columns for actual and predicted values. |
required |
y_col
|
str
|
Column name for the actual values. |
'y'
|
y_pred_col
|
str
|
Column name for the predicted values. |
'y_pred'
|
metrics
|
list
|
A list of metrics to calculate. Available options: - 'r2': R-squared - 'r': Pearson correlation coefficient - 'rmse': Root Mean Squared Error - 'mae': Mean Absolute Error - 'mape': Mean Absolute Percentage Error Defaults to all metrics if None. |
None
|
drop_na
|
bool
|
Whether to drop rows with NaN in the actual values column. |
True
|
filter_nonzero
|
bool
|
Whether to filter out rows where actual values are zero. |
True
|
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary of the selected performance metrics. |
Source code in leafmap/common.py
18052 18053 18054 18055 18056 18057 18058 18059 18060 18061 18062 18063 18064 18065 18066 18067 18068 18069 18070 18071 18072 18073 18074 18075 18076 18077 18078 18079 18080 18081 18082 18083 18084 18085 18086 18087 18088 18089 18090 18091 18092 18093 18094 18095 18096 18097 18098 18099 18100 18101 18102 18103 18104 18105 18106 18107 18108 18109 18110 18111 18112 18113 18114 18115 18116 18117 | |
execute_maplibre_notebook_dir(in_dir, out_dir, delete_html=True, replace_api_key=True, recursive=False, keep_notebook=False, index_html=True, ignore_files=None)
¶
Executes Jupyter notebooks found in a specified directory, optionally replacing API keys and deleting HTML outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_dir
|
str
|
The input directory containing Jupyter notebooks to be executed. |
required |
out_dir
|
str
|
The output directory where the executed notebooks and their HTML outputs will be saved. |
required |
delete_html
|
bool
|
If True, deletes any existing HTML files in the output directory before execution. Defaults to True. |
True
|
replace_api_key
|
bool
|
If True, replaces the API key in the output HTML. Defaults to True. set "MAPTILER_KEY" and "MAPTILER_KEY_PUBLIC" to your MapTiler API key and public key, respectively. |
True
|
recursive
|
bool
|
If True, searches for notebooks in the input directory recursively. Defaults to False. |
False
|
keep_notebook
|
bool
|
If True, keeps the executed notebooks in the output directory. Defaults to False. |
False
|
index_html
|
bool
|
If True, generates an index.html file in the output directory listing all files. Defaults to True. |
True
|
ignore_files
|
list
|
A list of notebook files to ignore during execution. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/common.py
16563 16564 16565 16566 16567 16568 16569 16570 16571 16572 16573 16574 16575 16576 16577 16578 16579 16580 16581 16582 16583 16584 16585 16586 16587 16588 16589 16590 16591 16592 16593 16594 16595 16596 16597 16598 16599 16600 16601 16602 16603 16604 16605 16606 16607 16608 16609 16610 16611 16612 16613 16614 16615 16616 16617 16618 16619 16620 16621 16622 16623 16624 16625 16626 16627 16628 16629 16630 16631 16632 16633 16634 16635 16636 16637 16638 16639 16640 16641 16642 16643 | |
execute_notebook(in_file)
¶
Executes a Jupyter notebook and save output cells
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_file
|
str
|
Input Jupyter notebook. |
required |
Source code in leafmap/common.py
16531 16532 16533 16534 16535 16536 16537 16538 16539 | |
execute_notebook_dir(in_dir)
¶
Executes all Jupyter notebooks in the given directory recursively and save output cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_dir
|
str
|
Input folder containing notebooks. |
required |
Source code in leafmap/common.py
16543 16544 16545 16546 16547 16548 16549 16550 16551 16552 16553 16554 16555 16556 16557 16558 16559 16560 | |
explode(coords)
¶
Explode a GeoJSON geometry's coordinates object and yield coordinate tuples. As long as the input is conforming, the type of the geometry doesn't matter. From Fiona 1.4.8
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords
|
list
|
A list of coordinates. |
required |
Yields:
| Type | Description |
|---|---|
Any
|
Coordinate tuples extracted from the input. |
Source code in leafmap/common.py
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 | |
extract_archive(archive, outdir=None, **kwargs)
¶
Extracts a multipart archive.
This function uses the patoolib library to extract a multipart archive. If the patoolib library is not installed, it attempts to install it. If the archive does not end with ".zip", it appends ".zip" to the archive name. If the extraction fails (for example, if the files already exist), it skips the extraction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
archive
|
str
|
The path to the archive file. |
required |
outdir
|
str
|
The directory where the archive should be extracted. |
None
|
**kwargs
|
Any
|
Arbitrary keyword arguments for the patoolib.extract_archive function. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
Exception
|
An exception is raised if the extraction fails for reasons other than the files already existing. |
1 2 3 4 | |
Source code in leafmap/common.py
16310 16311 16312 16313 16314 16315 16316 16317 16318 16319 16320 16321 16322 16323 16324 16325 16326 16327 16328 16329 16330 16331 16332 16333 16334 16335 16336 16337 16338 16339 16340 16341 16342 16343 16344 16345 16346 16347 16348 16349 16350 16351 16352 16353 16354 | |
extract_parquet_by_bbox(input_parquet, bbox, output_file, geometry='geometry', driver='PARQUET')
¶
Extract buildings that intersect with a specific bounding box in San Diego.
Uses DuckDB with spatial extension to query buildings that intersect with a bounding box and saves the results to a Parquet file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_parquet
|
str
|
Path to the input Parquet file. |
required |
bbox
|
tuple | list
|
Bounding box as (minx, miny, maxx, maxy). |
required |
output_file
|
str
|
Output file path for resulting Parquet/GeoParquet file. |
required |
geometry
|
str
|
Geometry column name. Defaults to "geometry". |
'geometry'
|
driver
|
str
|
Output driver, e.g., "PARQUET". Defaults to "PARQUET". |
'PARQUET'
|
Returns:
| Type | Description |
|---|---|
None
|
The function writes the results to the output file. |
Source code in leafmap/common.py
14795 14796 14797 14798 14799 14800 14801 14802 14803 14804 14805 14806 14807 14808 14809 14810 14811 14812 14813 14814 14815 14816 14817 14818 14819 14820 14821 14822 14823 14824 14825 14826 14827 14828 14829 14830 14831 14832 14833 14834 14835 14836 14837 14838 14839 14840 14841 14842 14843 14844 14845 14846 14847 14848 | |
filter_bounds(data, bbox, within=False, align=True, **kwargs)
¶
Filters a GeoDataFrame or GeoSeries by a bounding box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | GeoDataFrame
|
The input data to filter. Can be a file path or a GeoDataFrame. |
required |
bbox
|
list | GeoDataFrame
|
The bounding box to filter by. Can be a list of 4 coordinates or a file path or a GeoDataFrame. |
required |
within
|
bool
|
Whether to filter by the bounding box or the bounding box's interior. Defaults to False. |
False
|
align
|
bool
|
If True, automatically aligns GeoSeries based on their indices. If False, the order of elements is preserved. |
True
|
Returns:
| Type | Description |
|---|---|
Any
|
The filtered data. |
Source code in leafmap/common.py
9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 | |
filter_date(data, start_date=None, end_date=None, date_field='date', date_args={}, **kwargs)
¶
Filters a DataFrame, GeoDataFrame or GeoSeries by a date range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
str | DataFrame | GeoDataFrame
|
The input data to filter. Can be a file path or a DataFrame or GeoDataFrame. |
required |
start_date
|
str
|
The start date, e.g., 2023-01-01. Defaults to None. |
None
|
end_date
|
str
|
The end date, e.g., 2023-12-31. Defaults to None. |
None
|
date_field
|
str
|
The name of the date field. Defaults to "date". |
'date'
|
date_args
|
dict
|
Additional arguments for pd.to_datetime. Defaults to {}. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The filtered data. |
Source code in leafmap/common.py
9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 | |
filter_geom_type(data, geom_type, output=None, **kwargs)
¶
Filters a GeoDataFrame based on the geometry type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[str, dict, GeoDataFrame]
|
The GeoDataFrame to filter. |
required |
geom_type
|
str
|
The geometry type to filter by. |
required |
output
|
Optional[str]
|
The file path to save the filtered GeoDataFrame. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the GeoDataFrame.read_file method. |
{}
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
The filtered GeoDataFrame. |
Source code in leafmap/common.py
19037 19038 19039 19040 19041 19042 19043 19044 19045 19046 19047 19048 19049 19050 19051 19052 19053 19054 19055 19056 19057 19058 19059 19060 19061 19062 19063 19064 19065 19066 19067 19068 19069 19070 19071 19072 19073 19074 19075 19076 | |
find_closest_date(target_date, date_list, fmt='%Y-%m-%d')
¶
Finds the closest date string in a list of date strings to a given target date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_date
|
str
|
The reference date string to compare against. |
required |
date_list
|
List[str]
|
A list of date strings to search. |
required |
fmt
|
str
|
The date format used for parsing. Defaults to "%Y-%m-%d". |
'%Y-%m-%d'
|
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Optional[str]: The date string from |
Source code in leafmap/common.py
19935 19936 19937 19938 19939 19940 19941 19942 19943 19944 19945 19946 19947 19948 19949 19950 19951 19952 19953 19954 19955 19956 19957 19958 19959 19960 19961 19962 19963 19964 19965 19966 19967 19968 19969 19970 19971 19972 19973 | |
find_files(input_dir, ext=None, fullpath=True, recursive=True, include_hidden=False)
¶
Find files in a directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dir
|
str
|
The input directory. |
required |
ext
|
str
|
The file extension to match. Defaults to None. |
None
|
fullpath
|
bool
|
Whether to return the full path. Defaults to True. |
True
|
recursive
|
bool
|
Whether to search recursively. Defaults to True. |
True
|
include_hidden
|
bool
|
Whether to include hidden files. Defaults to False. |
False
|
Source code in leafmap/common.py
6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 | |
flatten_dict(my_dict, parent_key=False, sep='.')
¶
Flattens a nested dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
my_dict
|
dict
|
The dictionary to flatten. |
required |
parent_key
|
bool
|
Whether to include the parent key. Defaults to False. |
False
|
sep
|
str
|
The separator to use. Defaults to '.'. |
'.'
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
The flattened dictionary. |
Source code in leafmap/stac.py
2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 | |
gdb_layer_names(gdb_path)
¶
Get a list of layer names in a File Geodatabase (GDB).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdb_path
|
str
|
The path to the File Geodatabase (GDB). |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of layer names in the GDB. |
Source code in leafmap/common.py
14383 14384 14385 14386 14387 14388 14389 14390 14391 14392 14393 14394 14395 14396 14397 14398 14399 14400 14401 14402 14403 14404 14405 14406 14407 14408 14409 14410 | |
gdb_to_vector(gdb_path, out_dir, layers=None, filenames=None, gdal_driver='GPKG', file_extension=None, overwrite=False, quiet=False, **kwargs)
¶
Converts layers from a File Geodatabase (GDB) to a vector format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdb_path
|
str
|
The path to the File Geodatabase (GDB). |
required |
out_dir
|
str
|
The output directory to save the converted files. |
required |
layers
|
Optional[List[str]]
|
A list of layer names to convert. If None, all layers will be converted. Default is None. |
None
|
filenames
|
Optional[List[str]]
|
A list of output file names. If None, the layer names will be used as the file names. Default is None. |
None
|
gdal_driver
|
str
|
The GDAL driver name for the output vector format. Default is "GPKG". |
'GPKG'
|
file_extension
|
Optional[str]
|
The file extension for the output files. If None, it will be determined automatically based on the gdal_driver. Default is None. |
None
|
overwrite
|
bool
|
Whether to overwrite the existing output files. Default is False. |
False
|
quiet
|
bool
|
If True, suppress the log output. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/common.py
14293 14294 14295 14296 14297 14298 14299 14300 14301 14302 14303 14304 14305 14306 14307 14308 14309 14310 14311 14312 14313 14314 14315 14316 14317 14318 14319 14320 14321 14322 14323 14324 14325 14326 14327 14328 14329 14330 14331 14332 14333 14334 14335 14336 14337 14338 14339 14340 14341 14342 14343 14344 14345 14346 14347 14348 14349 14350 14351 14352 14353 14354 14355 14356 14357 14358 14359 14360 14361 14362 14363 14364 14365 14366 14367 14368 14369 14370 14371 14372 14373 14374 14375 14376 14377 14378 14379 14380 | |
gdf_bounds(gdf, return_geom=False)
¶
Returns the bounding box of a GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
A GeoDataFrame. |
required |
return_geom
|
bool
|
Whether to return the bounding box as a GeoDataFrame. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
|
A bounding box in the form of a list (minx, miny, maxx, maxy) or GeoDataFrame. |
Source code in leafmap/common.py
4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 | |
gdf_centroid(gdf, return_geom=False)
¶
Returns the centroid of a GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
A GeoDataFrame. |
required |
return_geom
|
bool
|
Whether to return the bounding box as a GeoDataFrame. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
|
A bounding box in the form of a list (lon, lat) or GeoDataFrame. |
Source code in leafmap/common.py
4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 | |
gdf_geom_type(gdf, first_only=True)
¶
Returns the geometry type of a GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
A GeoDataFrame. |
required |
first_only
|
bool
|
Whether to return the geometry type of the f irst feature in the GeoDataFrame. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
|
The geometry type of the GeoDataFrame, such as Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon. For more info, see https://shapely.readthedocs.io/en/stable/manual.html |
Source code in leafmap/common.py
4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 | |
gdf_to_bokeh(gdf)
¶
Function to convert a GeoPandas GeoDataFrame to a Bokeh ColumnDataSource object.
:param: (GeoDataFrame) gdf: GeoPandas GeoDataFrame with polygon(s) under the column name 'geometry.'
:return: ColumnDataSource for Bokeh.
Source code in leafmap/common.py
7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 | |
gdf_to_df(gdf, drop_geom=True)
¶
Converts a GeoDataFrame to a pandas DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
A GeoDataFrame. |
required |
drop_geom
|
bool
|
Whether to drop the geometry column. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
|
A pandas DataFrame containing the GeoDataFrame. |
Source code in leafmap/common.py
4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 | |
gdf_to_geojson(gdf, out_geojson=None, epsg=None, tuple_to_list=False, encoding='utf-8')
¶
Converts a GeoDataFame to GeoJSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
A GeoPandas GeoDataFrame. |
required |
out_geojson
|
str
|
File path to he output GeoJSON. Defaults to None. |
None
|
epsg
|
str
|
An EPSG string, e.g., "4326". Defaults to None. |
None
|
tuple_to_list
|
bool
|
Whether to convert tuples to lists. Defaults to False. |
False
|
encoding
|
str
|
The encoding to use for the GeoJSON. Defaults to "utf-8". |
'utf-8'
|
Raises:
| Type | Description |
|---|---|
TypeError
|
When the output file extension is incorrect. |
Exception
|
When the conversion fails. |
Returns:
| Type | Description |
|---|---|
Optional[dict]
|
When out_json is None returns a dict. |
Source code in leafmap/common.py
1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 | |
gedi_download_file(url, filename=None, username=None, password=None)
¶
Downloads a file from the given URL and saves it to the specified filename. If no filename is provided, the name of the file from the URL will be used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL of the file to download. e.g., https://daac.ornl.gov/daacdata/gedi/GEDI_L4A_AGB_Density_V2_1/data/GEDI04_A_2019298202754_O04921_01_T02899_02_002_02_V002.h5 |
required |
filename
|
str
|
The name of the file to save the downloaded content to. Defaults to None. |
None
|
username
|
str
|
Username for authentication. Can also be set using the EARTHDATA_USERNAME environment variable. Defaults to None. Create an account at https://urs.earthdata.nasa.gov |
None
|
password
|
str
|
Password for authentication. Can also be set using the EARTHDATA_PASSWORD environment variable. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/common.py
15741 15742 15743 15744 15745 15746 15747 15748 15749 15750 15751 15752 15753 15754 15755 15756 15757 15758 15759 15760 15761 15762 15763 15764 15765 15766 15767 15768 15769 15770 15771 15772 15773 15774 15775 15776 15777 15778 15779 15780 15781 15782 15783 15784 15785 15786 15787 15788 15789 15790 15791 15792 15793 15794 15795 | |
gedi_download_files(urls, outdir=None, filenames=None, username=None, password=None, overwrite=False)
¶
Downloads files from the given URLs and saves them to the specified directory. If no directory is provided, the current directory will be used. If no filenames are provided, the names of the files from the URLs will be used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
urls
|
List[str]
|
The URLs of the files to download. e.g., ["https://example.com/file1.txt", "https://example.com/file2.txt"] |
required |
outdir
|
str
|
The directory to save the downloaded files to. Defaults to None. |
None
|
filenames
|
str
|
The names of the files to save the downloaded content to. Defaults to None. |
None
|
username
|
str
|
Username for authentication. Can also be set using the EARTHDATA_USERNAME environment variable. Defaults to None. Create an account at https://urs.earthdata.nasa.gov |
None
|
password
|
str
|
Password for authentication. Can also be set using the EARTHDATA_PASSWORD environment variable. Defaults to None. |
None
|
overwrite
|
bool
|
Whether to overwrite the existing output files. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/common.py
15798 15799 15800 15801 15802 15803 15804 15805 15806 15807 15808 15809 15810 15811 15812 15813 15814 15815 15816 15817 15818 15819 15820 15821 15822 15823 15824 15825 15826 15827 15828 15829 15830 15831 15832 15833 15834 15835 15836 15837 15838 15839 15840 15841 15842 15843 15844 15845 15846 15847 15848 15849 15850 15851 15852 15853 15854 15855 15856 15857 15858 15859 15860 15861 15862 15863 15864 15865 15866 15867 15868 15869 15870 15871 15872 15873 15874 15875 15876 15877 15878 15879 15880 15881 15882 15883 15884 15885 | |
gedi_search(roi, start_date=None, end_date=None, add_roi=False, return_type='gdf', output=None, sort_filesize=False, **kwargs)
¶
Searches for GEDI data using the Common Metadata Repository (CMR) API. The source code for this function is adapted from https://github.com/ornldaac/gedi_tutorials. Credits to ORNL DAAC and Rupesh Shrestha.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
roi
|
Any
|
A list, tuple, or file path representing the bounding box coordinates in the format (min_lon, min_lat, max_lon, max_lat), or a GeoDataFrame containing the region of interest geometry. |
required |
start_date
|
Optional[str]
|
The start date of the temporal range to search for data in the format 'YYYY-MM-DD'. |
None
|
end_date
|
Optional[str]
|
The end date of the temporal range to search for data in the format 'YYYY-MM-DD'. |
None
|
add_roi
|
bool
|
A boolean value indicating whether to include the region of interest as a granule in the search results. Default is False. |
False
|
return_type
|
str
|
The type of the search results to return. Must be one of 'df' (DataFrame), 'gdf' (GeoDataFrame), or 'csv' (CSV file). Default is 'gdf'. |
'gdf'
|
output
|
Optional[str]
|
The file path to save the CSV output when return_type is 'csv'. Optional and only applicable when return_type is 'csv'. |
None
|
sort_filesize
|
bool
|
A boolean value indicating whether to sort the search results. |
False
|
**kwargs
|
Any
|
Additional keyword arguments to be passed to the CMR API. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[DataFrame, None]
|
The search results as a pandas DataFrame (return_type='df'), geopandas GeoDataFrame |
Union[DataFrame, None]
|
(return_type='gdf'), or a CSV file (return_type='csv'). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If roi is not a list, tuple, or file path. |
Source code in leafmap/common.py
15375 15376 15377 15378 15379 15380 15381 15382 15383 15384 15385 15386 15387 15388 15389 15390 15391 15392 15393 15394 15395 15396 15397 15398 15399 15400 15401 15402 15403 15404 15405 15406 15407 15408 15409 15410 15411 15412 15413 15414 15415 15416 15417 15418 15419 15420 15421 15422 15423 15424 15425 15426 15427 15428 15429 15430 15431 15432 15433 15434 15435 15436 15437 15438 15439 15440 15441 15442 15443 15444 15445 15446 15447 15448 15449 15450 15451 15452 15453 15454 15455 15456 15457 15458 15459 15460 15461 15462 15463 15464 15465 15466 15467 15468 15469 15470 15471 15472 15473 15474 15475 15476 15477 15478 15479 15480 15481 15482 15483 15484 15485 15486 15487 15488 15489 15490 15491 15492 15493 15494 15495 15496 15497 15498 15499 15500 15501 15502 15503 15504 15505 15506 15507 15508 15509 15510 15511 15512 15513 15514 15515 15516 15517 15518 15519 15520 15521 15522 15523 15524 15525 15526 15527 15528 15529 15530 15531 15532 15533 15534 15535 15536 15537 15538 15539 15540 15541 15542 15543 15544 15545 15546 15547 15548 15549 15550 15551 15552 15553 15554 15555 15556 15557 15558 15559 15560 15561 15562 15563 15564 15565 15566 15567 15568 15569 15570 15571 15572 15573 15574 15575 15576 15577 15578 15579 15580 15581 15582 15583 15584 15585 15586 15587 15588 15589 15590 15591 | |
gedi_subset(spatial=None, start_date=None, end_date=None, out_dir=None, collection=None, variables=['all'], max_results=None, username=None, password=None, overwrite=False, **kwargs)
¶
Subsets GEDI data using the Harmony API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spatial
|
Union[str, GeoDataFrame, List[float]]
|
Spatial extent for subsetting. Can be a file path to a shapefile, a GeoDataFrame, or a list of bounding box coordinates [minx, miny, maxx, maxy]. Defaults to None. |
None
|
start_date
|
str
|
Start date for subsetting in 'YYYY-MM-DD' format. Defaults to None. |
None
|
end_date
|
str
|
End date for subsetting in 'YYYY-MM-DD' format. Defaults to None. |
None
|
out_dir
|
str
|
Output directory to save the subsetted files. Defaults to None, which will use the current working directory. |
None
|
collection
|
Collection
|
GEDI data collection. If not provided, the default collection with DOI '10.3334/ORNLDAAC/2056' will be used. Defaults to None. |
None
|
variables
|
List[str]
|
List of variable names to subset. Defaults to ['all'], which subsets all available variables. |
['all']
|
max_results
|
int
|
Maximum number of results to return. Defaults to None, which returns all results. |
None
|
username
|
str
|
Earthdata username. Defaults to None, which will attempt to read from the 'EARTHDATA_USERNAME' environment variable. |
None
|
password
|
str
|
Earthdata password. Defaults to None, which will attempt to read from the 'EARTHDATA_PASSWORD' environment variable. |
None
|
overwrite
|
bool
|
Whether to overwrite existing files in the output directory. Defaults to False. |
False
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the Harmony API request. |
{}
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If the 'harmony' package is not installed. |
ValueError
|
If the 'spatial', 'start_date', or 'end_date' arguments are not valid. |
Returns:
| Type | Description |
|---|---|
|
None. |
Source code in leafmap/common.py
15594 15595 15596 15597 15598 15599 15600 15601 15602 15603 15604 15605 15606 15607 15608 15609 15610 15611 15612 15613 15614 15615 15616 15617 15618 15619 15620 15621 15622 15623 15624 15625 15626 15627 15628 15629 15630 15631 15632 15633 15634 15635 15636 15637 15638 15639 15640 15641 15642 15643 15644 15645 15646 15647 15648 15649 15650 15651 15652 15653 15654 15655 15656 15657 15658 15659 15660 15661 15662 15663 15664 15665 15666 15667 15668 15669 15670 15671 15672 15673 15674 15675 15676 15677 15678 15679 15680 15681 15682 15683 15684 15685 15686 15687 15688 15689 15690 15691 15692 15693 15694 15695 15696 15697 15698 15699 15700 15701 15702 15703 15704 15705 15706 15707 15708 15709 15710 15711 15712 15713 15714 15715 15716 15717 15718 15719 15720 15721 15722 15723 15724 15725 15726 15727 15728 15729 15730 15731 15732 15733 15734 15735 15736 15737 15738 | |
generate_index_html(directory, output='index.html')
¶
Generates an HTML file named 'index.html' in the specified directory, listing all files in that directory as clickable links.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str
|
The path to the directory for which to generate the index.html file. |
required |
output
|
str
|
The name of the output HTML file. Defaults to "index.html". |
'index.html'
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in leafmap/common.py
16646 16647 16648 16649 16650 16651 16652 16653 16654 16655 16656 16657 16658 16659 16660 16661 16662 16663 16664 16665 16666 16667 16668 16669 16670 16671 16672 16673 16674 16675 16676 16677 16678 16679 16680 16681 16682 16683 16684 16685 16686 16687 16688 16689 | |
generate_latlon_grid(extent, dx=0.1, dy=0.1, crs='EPSG:4326', output=None)
¶
Generate a rectangular lat/lon grid as polygons over a given extent.
Parameters¶
extent : tuple (xmin, ymin, xmax, ymax) in degrees, e.g. (-180, -60, 180, 85) dx : float Longitude interval in degrees (cell width) dy : float Latitude interval in degrees (cell height) crs : str or dict Coordinate reference system for the output GeoDataFrame
Returns¶
GeoDataFrame Columns: id, lon_min, lat_min, lon_max, lat_max, geometry
Source code in leafmap/common.py
20100 20101 20102 20103 20104 20105 20106 20107 20108 20109 20110 20111 20112 20113 20114 20115 20116 20117 20118 20119 20120 20121 20122 20123 20124 20125 20126 20127 20128 20129 20130 20131 20132 20133 20134 20135 20136 20137 20138 20139 20140 20141 20142 20143 20144 20145 20146 20147 20148 20149 20150 20151 20152 20153 20154 20155 20156 20157 20158 20159 20160 20161 20162 20163 20164 20165 20166 20167 20168 20169 20170 20171 20172 | |
geojson_bounds(geojson)
¶
Calculate the bounds of a GeoJSON object.
This function uses the shapely library to calculate the bounds of a GeoJSON object. If the shapely library is not installed, it will print a message and return None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geojson
|
dict
|
A dictionary representing a GeoJSON object. |
required |
Returns:
| Type | Description |
|---|---|
Optional[list]
|
A list of bounds (minx, miny, maxx, maxy) if shapely is installed, None otherwise. |
Source code in leafmap/common.py
16506 16507 16508 16509 16510 16511 16512 16513 16514 16515 16516 16517 16518 16519 16520 16521 16522 16523 16524 16525 16526 16527 16528 | |
geojson_layer(in_geojson, layer_name='GeoJSON', style={}, hover_style={}, style_callback=None, fill_colors=None, encoding='utf-8', **kwargs)
¶
Adds a GeoJSON file to the map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_geojson
|
str | dict
|
The file path or http URL to the input GeoJSON or a dictionary containing the geojson. |
required |
layer_name
|
str
|
The layer name to be used.. Defaults to "GeoJSON". |
'GeoJSON'
|
style
|
dict
|
A dictionary specifying the style to be used. Defaults to {}. |
{}
|
hover_style
|
dict
|
Hover style dictionary. Defaults to {}. |
{}
|
style_callback
|
function
|
Styling function that is called for each feature, and should return the feature style. This styling function takes the feature as argument. Defaults to None. |
None
|
fill_colors
|
list
|
The random colors to use for filling polygons. Defaults to ["black"]. |
None
|
info_mode
|
str
|
Displays the attributes by either on_hover or on_click. Any value other than "on_hover" or "on_click" will be treated as None. Defaults to "on_hover". |
required |
zoom_to_layer
|
bool
|
Whether to zoom to the layer after adding it to the map. Defaults to False. |
required |
encoding
|
str
|
The encoding of the GeoJSON file. Defaults to "utf-8". |
'utf-8'
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
The provided GeoJSON file could not be found. |
Source code in leafmap/leafmap.py
6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 | |
geojson_to_df(in_geojson, encoding='utf-8', drop_geometry=True)
¶
Converts a GeoJSON object to a pandas DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_geojson
|
str | dict
|
The input GeoJSON file or dict. |
required |
encoding
|
str
|
The encoding of the GeoJSON object. Defaults to "utf-8". |
'utf-8'
|
drop_geometry
|
bool
|
Whether to drop the geometry column. Defaults to True. |
True
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the input GeoJSON file could not be found. |
Returns:
| Type | Description |
|---|---|
|
A pandas DataFrame containing the GeoJSON object. |
Source code in leafmap/common.py
3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 | |
geojson_to_gdf(in_geojson, encoding='utf-8', **kwargs)
¶
Converts a GeoJSON object to a geopandas GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_geojson
|
str | dict
|
The input GeoJSON file or GeoJSON object as a dict. |
required |
encoding
|
str
|
The encoding of the GeoJSON object. Defaults to "utf-8". |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
|
A GeoPandas GeoDataFrame containing the GeoJSON object. |
Source code in leafmap/common.py
3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 | |
geojson_to_gpkg(in_geojson, out_gpkg, **kwargs)
¶
Converts a GeoJSON object to GeoPackage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_geojson
|
str | dict
|
The input GeoJSON file or dict. |
required |
out_gpkg
|
str
|
The output GeoPackage path. |
required |
Source code in leafmap/common.py
4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 | |
geojson_to_mbtiles(input_file, output_file, layer_name=None, options=None, quiet=False)
¶
Converts vector data to .mbtiles using Tippecanoe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_file
|
str
|
Path to the input vector data file (e.g., .geojson). |
required |
output_file
|
str
|
Path to the output .mbtiles file. |
required |
layer_name
|
Optional[str]
|
Optional name for the layer. Defaults to None. |
None
|
options
|
Optional[List[str]]
|
List of additional arguments for tippecanoe. For example '-zg' for auto maxzoom. Defaults to None. |
None
|
quiet
|
bool
|
If True, suppress the log output. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Output from the Tippecanoe command, or None if there was an error or if Tippecanoe is not installed. |
Raises:
| Type | Description |
|---|---|
CalledProcessError
|
If there's an error executing the tippecanoe command. |
Source code in leafmap/common.py
13532 13533 13534 13535 13536 13537 13538 13539 13540 13541 13542 13543 13544 13545 13546 13547 13548 13549 13550 13551 13552 13553 13554 13555 13556 13557 13558 13559 13560 13561 13562 13563 13564 13565 13566 13567 13568 13569 13570 13571 13572 13573 13574 13575 13576 13577 13578 13579 13580 13581 13582 13583 13584 13585 13586 13587 13588 13589 13590 13591 13592 13593 13594 13595 | |
geojson_to_pmtiles(input_file, output_file=None, layer_name=None, projection='EPSG:4326', overwrite=False, options=None, quiet=False)
¶
Converts vector data to PMTiles using Tippecanoe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_file
|
str
|
Path to the input vector data file (e.g., .geojson). |
required |
output_file
|
str
|
Path to the output .mbtiles file. |
None
|
layer_name
|
Optional[str]
|
Optional name for the layer. Defaults to None. |
None
|
projection
|
Optional[str]
|
Projection for the output PMTiles file. Defaults to "EPSG:4326". |
'EPSG:4326'
|
overwrite
|
bool
|
If True, overwrite the existing output file. Defaults to False. |
False
|
options
|
Optional[List[str]]
|
List of additional arguments for tippecanoe. Defaults to None. To reduce the size of the output file, use '-zg' or '-z max-zoom'. |
None
|
quiet
|
bool
|
If True, suppress the log output. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Output from the Tippecanoe command, or None if there was an error or if Tippecanoe is not installed. |
Raises:
| Type | Description |
|---|---|
CalledProcessError
|
If there's an error executing the tippecanoe command. |
Source code in leafmap/common.py
13665 13666 13667 13668 13669 13670 13671 13672 13673 13674 13675 13676 13677 13678 13679 13680 13681 13682 13683 13684 13685 13686 13687 13688 13689 13690 13691 13692 13693 13694 13695 13696 13697 13698 13699 13700 13701 13702 13703 13704 13705 13706 13707 13708 13709 13710 13711 13712 13713 13714 13715 13716 13717 13718 13719 13720 13721 13722 13723 13724 13725 13726 13727 13728 13729 13730 13731 13732 13733 13734 13735 13736 13737 13738 13739 13740 13741 13742 13743 13744 13745 13746 13747 | |
geojson_to_shp(in_geojson, out_shp, **kwargs)
¶
Converts a GeoJSON object to GeoPandas GeoDataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_geojson
|
str | dict
|
The input GeoJSON file or dict. |
required |
out_shp
|
str
|
The output shapefile path. |
required |
Source code in leafmap/common.py
3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 | |
geojsonl_to_parquet_batch(input_dir, output_dir, batch_size=50, file_ext='.json', filename_predix='batch_', **kwargs)
¶
Convert JSON Lines files to multiple GeoParquet files, with each GeoParquet file containing data from a specified number of JSON Lines files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dir
|
str
|
Directory containing JSON Lines files to convert |
required |
output_dir
|
str
|
Directory for output GeoParquet files |
required |
batch_size
|
int
|
Number of JSON Lines files to combine in each GeoParquet file. Defaults to 50. |
50
|
file_ext
|
str
|
File extension of the input files. Defaults to ".json". |
'.json'
|
filename_predix
|
str
|
Prefix for the output GeoParquet files. Defaults to "batch_". |
'batch_'
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the |
{}
|
Source code in leafmap/common.py
14648 14649 14650 14651 14652 14653 14654 14655 14656 14657 14658 14659 14660 14661 14662 14663 14664 14665 14666 14667 14668 14669 14670 14671 14672 14673 14674 14675 14676 14677 14678 14679 14680 14681 14682 14683 14684 14685 14686 14687 14688 14689 14690 14691 14692 14693 14694 14695 14696 14697 14698 14699 14700 14701 14702 14703 14704 14705 14706 14707 14708 14709 14710 14711 14712 14713 14714 14715 14716 14717 14718 14719 14720 14721 14722 14723 14724 14725 14726 14727 14728 14729 14730 14731 14732 14733 14734 14735 14736 14737 14738 14739 14740 14741 14742 14743 14744 14745 14746 14747 14748 14749 14750 14751 14752 14753 14754 14755 14756 14757 14758 14759 14760 14761 14762 14763 14764 14765 14766 14767 14768 14769 14770 14771 14772 14773 14774 14775 14776 14777 14778 14779 14780 14781 14782 14783 14784 14785 14786 14787 14788 14789 14790 14791 14792 | |
geom_type(in_geojson, encoding='utf-8')
¶
Returns the geometry type of a GeoJSON object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_geojson
|
dict
|
A GeoJSON object. |
required |
encoding
|
str
|
The encoding of the GeoJSON object. Defaults to "utf-8". |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
|
The geometry type of the GeoJSON object, such as Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon. For more info, see https://shapely.readthedocs.io/en/stable/manual.html |
Source code in leafmap/common.py
3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 | |
geometry_bounds(geometry, decimals=4)
¶
Returns the bounds of a geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
dict
|
A GeoJSON geometry. |
required |
decimals
|
int
|
The number of decimal places to round the bounds to. Defaults to 4. |
4
|
Returns:
| Type | Description |
|---|---|
|
A list of bounds in the form of [minx, miny, maxx, maxy]. |
Source code in leafmap/common.py
6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 | |
get_3dep_dem(geometry, resolution=30, src_crs=None, output=None, dst_crs='EPSG:5070', to_cog=False, overwrite=False, **kwargs)
¶
Get DEM data at any resolution from 3DEP.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
Polygon | MultiPolygon | tuple
|
It can be a polygon or a bounding box of form (xmin, ymin, xmax, ymax). |
required |
resolution
|
int
|
arget DEM source resolution in meters. Defaults to 30. |
30
|
src_crs
|
str
|
The spatial reference system of the input geometry. Defaults to "EPSG:4326". |
None
|
output
|
str
|
The output GeoTIFF file. Defaults to None. |
None
|
dst_crs
|
str
|
The spatial reference system of the output GeoTIFF file. Defaults to "EPSG:5070". |
'EPSG:5070'
|
to_cog
|
bool
|
Convert to Cloud Optimized GeoTIFF. Defaults to False. |
False
|
overwrite
|
bool
|
Whether to overwrite the output file if it exists. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
|
DEM at the specified resolution in meters and CRS as an xarray.DataArray. |
Source code in leafmap/common.py
11054 11055 11056 11057 11058 11059 11060 11061 11062 11063 11064 11065 11066 11067 11068 11069 11070 11071 11072 11073 11074 11075 11076 11077 11078 11079 11080 11081 11082 11083 11084 11085 11086 11087 11088 11089 11090 11091 11092 11093 11094 11095 11096 11097 11098 11099 11100 11101 11102 11103 11104 11105 11106 11107 11108 11109 11110 11111 11112 11113 11114 11115 | |
get_api_key(name=None, key=None)
¶
Retrieves an API key. If a key is provided, it is returned directly. If a name is provided, the function attempts to retrieve the key from user data (if running in Google Colab) or from environment variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
Optional[str]
|
The name of the key to retrieve. Defaults to None. |
None
|
key
|
Optional[str]
|
The key to return directly. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The retrieved key, or None if no key was found. |
Source code in leafmap/common.py
1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 | |
get_basemap(name)
¶
Gets a basemap tile layer by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the basemap. |
required |
Returns:
| Type | Description |
|---|---|
|
ipylealfet.TileLayer | ipyleaflet.WMSLayer: The basemap layer. |
Source code in leafmap/leafmap.py
6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 | |
get_bounds(geometry, north_up=True, transform=None)
¶
Bounding box of a GeoJSON geometry, GeometryCollection, or FeatureCollection. left, bottom, right, top not xmin, ymin, xmax, ymax If not north_up, y will be switched to guarantee the above. Source code adapted from https://github.com/mapbox/rasterio/blob/master/rasterio/features.py#L361
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
dict
|
A GeoJSON dict. |
required |
north_up
|
bool
|
. Defaults to True. |
True
|
transform
|
[type]
|
. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[float, float, float, float]
|
A list of coordinates representing [left, bottom, right, top]. |
Source code in leafmap/common.py
1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 | |
get_census_dict(reset=False)
¶
Returns a dictionary of Census data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reset
|
bool
|
Reset the dictionary. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
|
A dictionary of Census data. |
Source code in leafmap/common.py
2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 | |
get_center(geometry, north_up=True, transform=None)
¶
Get the centroid of a GeoJSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geometry
|
dict
|
A GeoJSON dict. |
required |
north_up
|
bool
|
. Defaults to True. |
True
|
transform
|
[type]
|
. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
A coordinate pair in the form [lon, lat]. |
Source code in leafmap/common.py
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 | |
get_cog_link_from_stac_item(item_url)
¶
Retrieve the URL of the GeoTIFF asset from a STAC Item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_url
|
str
|
The URL to a STAC Item JSON. |
required |
Returns:
| Type | Description |
|---|---|
str
|
URL of the first .tif asset, or None if not found. |
Source code in leafmap/stac.py
2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 | |
get_direct_url(url)
¶
Get the direct URL for a given URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to get the direct URL for. |
required |
Returns:
| Type | Description |
|---|---|
|
The direct URL. |
Source code in leafmap/common.py
6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 | |
get_ee_tile_url(asset_id, vis_params=None, endpoint=None)
¶
Get the tile URL for an Earth Engine asset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset_id
|
str
|
The Earth Engine asset ID. |
required |
vis_params
|
Optional[Union[str, dict]]
|
The visualization parameters. |
None
|
endpoint
|
Optional[str]
|
The endpoint to use for the tile request. Set to "default" to use the default endpoint. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The tile URL. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the asset ID is not a valid Earth Engine asset ID. |
ValueError
|
If the visualization parameters are not a valid JSON string. |
ValueError
|
If the endpoint is not a valid URL. |
ValueError
|
If the data type is not supported. |
Source code in leafmap/common.py
19746 19747 19748 19749 19750 19751 19752 19753 19754 19755 19756 19757 19758 19759 19760 19761 19762 19763 19764 19765 19766 19767 19768 19769 19770 19771 19772 19773 19774 19775 19776 19777 19778 19779 19780 19781 19782 19783 19784 19785 19786 19787 19788 19789 19790 19791 19792 19793 19794 19795 19796 19797 19798 19799 19800 19801 19802 19803 19804 19805 19806 19807 19808 19809 19810 19811 19812 19813 19814 19815 19816 19817 19818 19819 19820 19821 19822 | |
get_env_var(key)
¶
Retrieves 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 |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The retrieved key, or None if no environment variable was found. |
Source code in leafmap/common.py
19336 19337 19338 19339 19340 19341 19342 19343 19344 19345 19346 19347 19348 19349 19350 19351 19352 19353 19354 19355 19356 19357 19358 | |
get_gdal_drivers()
¶
Get a list of available driver names in the GDAL library.
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of available driver names. |
Source code in leafmap/common.py
14243 14244 14245 14246 14247 14248 14249 14250 14251 14252 14253 14254 14255 14256 14257 14258 14259 | |
get_gdal_file_extension(driver_name)
¶
Get the file extension corresponding to a driver name in the GDAL library.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
driver_name
|
str
|
The name of the driver. |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The file extension corresponding to the driver name, or None if the driver is not found or does not have a specific file extension. |
Source code in leafmap/common.py
14262 14263 14264 14265 14266 14267 14268 14269 14270 14271 14272 14273 14274 14275 14276 14277 14278 14279 14280 14281 14282 14283 14284 14285 14286 14287 14288 14289 14290 | |
get_geometry_coords(row, geom, coord_type, shape_type, mercator=False)
¶
Returns the coordinates ('x' or 'y') of edges of a Polygon exterior.
:param: (GeoPandas Series) row : The row of each of the GeoPandas DataFrame. :param: (str) geom : The column name. :param: (str) coord_type : Whether it's 'x' or 'y' coordinate. :param: (str) shape_type
Source code in leafmap/common.py
7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 | |
get_geometry_type(in_geojson)
¶
Get the geometry type of a GeoJSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_geojson
|
str | dict
|
The path to the GeoJSON file or a GeoJSON dictionary. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The geometry type. Can be one of "Point", "LineString", "Polygon", "MultiPoint", "MultiLineString", "MultiPolygon", "GeometryCollection", or "Unknown". |
Source code in leafmap/common.py
11431 11432 11433 11434 11435 11436 11437 11438 11439 11440 11441 11442 11443 11444 11445 11446 11447 11448 11449 11450 11451 11452 11453 11454 11455 11456 11457 11458 11459 11460 11461 11462 11463 11464 11465 11466 11467 11468 11469 11470 11471 11472 11473 11474 11475 11476 | |
get_google_map(map_type='HYBRID', show=True, api_key=None, backend='ipyleaflet', **kwargs)
¶
Gets Google basemap tile layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
map_type
|
str
|
Can be one of "ROADMAP", "SATELLITE", "HYBRID" or "TERRAIN". Defaults to 'HYBRID'. |
'HYBRID'
|
show
|
bool
|
Whether to add the layer to the map. Defaults to True. |
True
|
api_key
|
str
|
The Google Maps API key. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional arguments to pass to ipyleaflet.TileLayer(). |
{}
|
Source code in leafmap/common.py
11479 11480 11481 11482 11483 11484 11485 11486 11487 11488 11489 11490 11491 11492 11493 11494 11495 11496 11497 11498 11499 11500 11501 11502 11503 11504 11505 11506 11507 11508 11509 11510 11511 11512 11513 11514 11515 11516 11517 11518 11519 11520 11521 11522 11523 11524 11525 11526 11527 11528 11529 11530 11531 11532 11533 11534 11535 11536 11537 11538 11539 11540 11541 11542 11543 11544 11545 11546 11547 11548 11549 11550 11551 11552 11553 11554 11555 11556 11557 11558 11559 11560 11561 | |
get_google_map_tile_providers(language='en-Us', region='US', api_key=None, **kwargs)
¶
Generates a dictionary of Google Map tile providers for different map types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
language
|
str
|
An IETF language tag that specifies the language used to display information on the tiles, such as 'zh-Cn'. Defaults to 'en-Us'. |
'en-Us'
|
region
|
str
|
A Common Locale Data Repository region identifier (two uppercase letters) that represents the physical location of the user. Defaults to 'US'. |
'US'
|
api_key
|
str
|
The API key to use for the Google Maps API. If not provided, it will try to get it from the environment or Colab user data with the key 'GOOGLE_MAPS_API_KEY'. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional parameters to pass to the map generation. For more info, visit https://bit.ly/3UhbZKU |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
A dictionary where the keys are the map types and the values are tile providers. |
Dict[str, Any]
|
('roadmap', 'satellite', 'terrain', 'hybrid') |
Dict[str, Any]
|
and the values are the corresponding GoogleMapsTileProvider objects. |
Source code in leafmap/common.py
19282 19283 19284 19285 19286 19287 19288 19289 19290 19291 19292 19293 19294 19295 19296 19297 19298 19299 19300 19301 19302 19303 19304 19305 19306 19307 19308 19309 19310 19311 19312 19313 19314 19315 19316 | |
get_google_maps_api_key(key='GOOGLE_MAPS_API_KEY')
¶
Retrieves 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. Defaults to 'GOOGLE_MAPS_API_KEY'. |
'GOOGLE_MAPS_API_KEY'
|
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The API key, or None if it could not be found. |
Source code in leafmap/common.py
19319 19320 19321 19322 19323 19324 19325 19326 19327 19328 19329 19330 19331 19332 19333 | |
get_image_colormap(image, index=1)
¶
Retrieve the colormap from an image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
(str, DatasetReader, DataArray)
|
The input image. It can be: - A file path to a raster image (string). - A rasterio dataset. - A rioxarray DataArray. |
required |
index
|
int
|
The band index to retrieve the colormap from (default is 1). |
1
|
Returns:
| Type | Description |
|---|---|
|
A dictionary representing the colormap (value: (R, G, B, A)), or None if no colormap is found. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input image type is unsupported. |
Source code in leafmap/common.py
18425 18426 18427 18428 18429 18430 18431 18432 18433 18434 18435 18436 18437 18438 18439 18440 18441 18442 18443 18444 18445 18446 18447 18448 18449 18450 18451 18452 18453 18454 18455 18456 18457 18458 18459 18460 18461 18462 18463 18464 18465 18466 18467 18468 18469 18470 18471 18472 18473 18474 18475 18476 18477 18478 | |
get_local_tile_layer(source, port='default', debug=False, indexes=None, colormap=None, vmin=None, vmax=None, nodata=None, attribution=None, tile_format='ipyleaflet', layer_name='Local COG', client_args={'cors_all': False}, return_client=False, quiet=False, **kwargs)
¶
Generate an ipyleaflet/folium TileLayer from a local raster dataset or remote Cloud Optimized GeoTIFF (COG). If you are using this function in JupyterHub on a remote server and the raster does not render properly, try running the following two lines before calling this function:
1 2 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
The path to the GeoTIFF file or the URL of the Cloud Optimized GeoTIFF. |
required |
port
|
str
|
The port to use for the server. Defaults to "default". |
'default'
|
debug
|
bool
|
If True, the server will be started in debug mode. Defaults to False. |
False
|
indexes
|
int
|
The band(s) to use. Band indexing starts at 1. Defaults to None. |
None
|
colormap
|
str
|
The name of the colormap from |
None
|
vmin
|
float
|
The minimum value to use when colormapping the colormap when plotting a single band. Defaults to None. |
None
|
vmax
|
float
|
The maximum value to use when colormapping the colormap when plotting a single band. Defaults to None. |
None
|
nodata
|
float
|
The value from the band to use to interpret as not valid data. Defaults to None. |
None
|
attribution
|
str
|
Attribution for the source raster. This defaults to a message about it being a local file.. Defaults to None. |
None
|
tile_format
|
str
|
The tile layer format. Can be either ipyleaflet or folium. Defaults to "ipyleaflet". |
'ipyleaflet'
|
layer_name
|
str
|
The layer name to use. Defaults to None. |
'Local COG'
|
client_args
|
dict
|
Additional arguments to pass to the TileClient. Defaults to {}. |
{'cors_all': False}
|
return_client
|
bool
|
If True, the tile client will be returned. Defaults to False. |
False
|
quiet
|
bool
|
If True, the error messages will be suppressed. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
|
An ipyleaflet.TileLayer or folium.TileLayer. |
Source code in leafmap/common.py
3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 | |
get_local_tile_url(source, port='default', indexes=None, colormap=None, vmin=None, vmax=None, nodata=None, client_args={'cors_all': False}, return_client=False, **kwargs)
¶
Generate an ipyleaflet/folium TileLayer from a local raster dataset or remote Cloud Optimized GeoTIFF (COG). If you are using this function in JupyterHub on a remote server and the raster does not render properly, try running the following two lines before calling this function:
1 2 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
The path to the GeoTIFF file or the URL of the Cloud Optimized GeoTIFF. |
required |
port
|
str
|
The port to use for the server. Defaults to "default". |
'default'
|
indexes
|
int
|
The band(s) to use. Band indexing starts at 1. Defaults to None. |
None
|
colormap
|
str
|
The name of the colormap from |
None
|
vmin
|
float
|
The minimum value to use when colormapping the colormap when plotting a single band. Defaults to None. |
None
|
vmax
|
float
|
The maximum value to use when colormapping the colormap when plotting a single band. Defaults to None. |
None
|
nodata
|
float
|
The value from the band to use to interpret as not valid data. Defaults to None. |
None
|
client_args
|
dict
|
Additional arguments to pass to the TileClient. Defaults to {}. |
{'cors_all': False}
|
return_client
|
bool
|
If True, the tile client will be returned. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
|
An ipyleaflet.TileLayer or folium.TileLayer. |
Source code in leafmap/common.py
3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 | |
get_mapillary_image_url(image_id, resolution='original', access_token=None, **kwargs)
¶
Retrieves the URL of a Mapillary image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_id
|
str
|
The ID of the Mapillary image. |
required |
resolution
|
str
|
The resolution of the image. Can be 256, 1024, 2048, or original. Defaults to "original". |
'original'
|
access_token
|
str
|
The access token for the Mapillary API. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional keyword arguments for the request. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no access token is provided. |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
The URL of the Mapillary image, or None if an error occurs. |
Source code in leafmap/common.py
18310 18311 18312 18313 18314 18315 18316 18317 18318 18319 18320 18321 18322 18323 18324 18325 18326 18327 18328 18329 |