Skip to content

Commit

Permalink
Enable xarray dataset in add_raster_legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Aug 31, 2023
1 parent 25734c2 commit cb696ae
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
31 changes: 31 additions & 0 deletions leafmap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10125,3 +10125,34 @@ def get_google_map(
raise ValueError("backend must be either 'ipyleaflet' or 'folium'")

return layer


def install_package(package):
"""Install a Python package.
Args:
package (str | list): The package name or a GitHub URL or a list of package names or GitHub URLs.
"""
import subprocess

if isinstance(package, str):
packages = [package]

for package in packages:
if package.startswith("https://github.com"):

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High

The string
https://github.com
may be at an arbitrary position in the sanitized URL.
package = f"git+{package}"

# Execute pip install command and show output in real-time
command = f"pip install {package}"
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)

# Print output in real-time
while True:
output = process.stdout.readline()
if output == b"" and process.poll() is not None:
break
if output:
print(output.decode("utf-8").strip())

# Wait for process to complete
process.wait()
12 changes: 8 additions & 4 deletions leafmap/leafmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2134,9 +2134,10 @@ def add_raster_legacy(

warnings.simplefilter("ignore")

if not os.path.exists(image):
print("The image file does not exist.")
return
if isinstance(image, str):
if not os.path.exists(image):
print("The image file does not exist.")
return

if colormap is None:
colormap = plt.cm.inferno
Expand All @@ -2147,7 +2148,10 @@ def add_raster_legacy(
if isinstance(colormap, str):
colormap = plt.cm.get_cmap(name=colormap)

da = rioxarray.open_rasterio(image, masked=True)
if isinstance(image, str):
da = rioxarray.open_rasterio(image, masked=True)
else:
da = image

# print(da.rio.nodata)

Expand Down

0 comments on commit cb696ae

Please sign in to comment.