A Python package for interactive geospatial analysis and visualization with Google Earth Engine
—
Extensive collection of utility functions for data format conversion, file operations, geospatial data processing, and general-purpose utilities for working with various data formats and external services.
Convert between various geospatial and tabular data formats including CSV, GeoJSON, Shapefile, and KML.
def csv_to_geojson(
in_csv: str,
out_geojson: str = None,
latitude: str = "latitude",
longitude: str = "longitude",
encoding: str = "utf-8",
**kwargs
) -> Union[Dict, None]:
"""
Convert CSV file with coordinates to GeoJSON.
Args:
in_csv: Input CSV file path
out_geojson: Output GeoJSON file path (optional)
latitude: Column name for latitude values
longitude: Column name for longitude values
encoding: Character encoding for CSV file
**kwargs: Additional conversion parameters
Returns:
GeoJSON dictionary if no output file specified
"""
def csv_to_shp(
in_csv: str,
out_shp: str,
latitude: str = "latitude",
longitude: str = "longitude",
**kwargs
) -> None:
"""
Convert CSV file to shapefile.
Args:
in_csv: Input CSV file path
out_shp: Output shapefile path
latitude: Column name for latitude values
longitude: Column name for longitude values
**kwargs: Additional parameters
"""
def shp_to_geojson(
in_shp: str,
out_geojson: str = None,
**kwargs
) -> Union[Dict, None]:
"""
Convert shapefile to GeoJSON.
Args:
in_shp: Input shapefile path
out_geojson: Output GeoJSON path (optional)
**kwargs: Additional parameters
Returns:
GeoJSON dictionary if no output file specified
"""
def csv_points_to_shp(
in_csv: str,
out_shp: str,
latitude: str = "latitude",
longitude: str = "longitude",
**kwargs
) -> None:
"""
Convert CSV points to shapefile.
Args:
in_csv: Input CSV file path
out_shp: Output shapefile path
latitude: Column name for latitude
longitude: Column name for longitude
**kwargs: Additional parameters
"""Convert between different coordinate systems and geometry representations.
def xy_to_points(
in_csv: str,
out_shp: str,
x_col: str = "x",
y_col: str = "y",
crs: str = "EPSG:4326",
**kwargs
) -> None:
"""
Convert XY coordinates to point shapefile.
Args:
in_csv: Input CSV file path
out_shp: Output shapefile path
x_col: X coordinate column name
y_col: Y coordinate column name
crs: Coordinate reference system
**kwargs: Additional parameters
"""
def bbox_to_extent(bbox: List[float]) -> List[float]:
"""
Convert bounding box to extent format.
Args:
bbox: Bounding box [minx, miny, maxx, maxy]
Returns:
Extent coordinates
"""Download files from various sources including URLs, Google Drive, and cloud storage services.
def download_from_url(
url: str,
out_file_name: str = None,
out_dir: str = ".",
unzip: bool = True,
**kwargs
) -> str:
"""
Download file from URL.
Args:
url: File URL
out_file_name: Output filename (optional)
out_dir: Output directory
unzip: Whether to unzip downloaded file
**kwargs: Additional parameters
Returns:
Path to downloaded file
"""
def download_from_gdrive(
gfile_url: str,
file_name: str,
out_dir: str = ".",
unzip: bool = True,
**kwargs
) -> str:
"""
Download file from Google Drive.
Args:
gfile_url: Google Drive file URL
file_name: Output filename
out_dir: Output directory
unzip: Whether to unzip file
**kwargs: Additional parameters
Returns:
Path to downloaded file
"""
def create_download_link(
filename: str,
title: str = "Click here to download: ",
**kwargs
) -> str:
"""
Create HTML download link for file.
Args:
filename: File path
title: Link display text
**kwargs: Additional parameters
Returns:
HTML download link string
"""Handle image operations, display, and upload to external services.
def open_image_from_url(url: str) -> Any:
"""
Open image from URL.
Args:
url: Image URL
Returns:
Image object
"""
def show_image(
img_path: str,
width: int = None,
height: int = None,
**kwargs
) -> None:
"""
Display image in Jupyter notebook.
Args:
img_path: Path to image file
width: Display width in pixels
height: Display height in pixels
**kwargs: Additional display parameters
"""
def has_transparency(img_path: str) -> bool:
"""
Check if image has transparency channel.
Args:
img_path: Path to image file
Returns:
True if image has transparency
"""
def upload_to_imgur(
in_gif: str,
client_id: str = None,
**kwargs
) -> str:
"""
Upload image/GIF to Imgur.
Args:
in_gif: Path to image/GIF file
client_id: Imgur client ID
**kwargs: Additional parameters
Returns:
Imgur URL
"""Utilities for managing Python packages and dependencies.
def check_install(package: str) -> bool:
"""
Check if package is installed.
Args:
package: Package name
Returns:
True if package is installed
"""
def install_package(package: str, **kwargs) -> None:
"""
Install Python package.
Args:
package: Package name to install
**kwargs: Additional installation parameters
"""
def update_package() -> None:
"""Update geemap package to latest version."""
def check_package(name: str) -> Dict:
"""
Check package information.
Args:
name: Package name
Returns:
Package information dictionary
"""Git repository cloning and management utilities.
def clone_repo(
out_dir: str = ".",
unzip: bool = True,
**kwargs
) -> str:
"""
Clone repository.
Args:
out_dir: Output directory
unzip: Whether to unzip
**kwargs: Additional parameters
Returns:
Path to cloned repository
"""
def install_from_github(
url: str,
**kwargs
) -> None:
"""
Install package from GitHub.
Args:
url: GitHub repository URL
**kwargs: Additional parameters
"""
def check_git_install() -> bool:
"""
Check if Git is installed.
Returns:
True if Git is available
"""
def clone_github_repo(
url: str,
out_dir: str = None,
**kwargs
) -> str:
"""
Clone GitHub repository.
Args:
url: GitHub repository URL
out_dir: Output directory
**kwargs: Additional parameters
Returns:
Path to cloned repository
"""
def open_github() -> None:
"""Open geemap GitHub repository."""
def open_youtube() -> None:
"""Open geemap YouTube channel."""System-level utilities and environment management functions.
def is_tool(name: str) -> bool:
"""
Check if command line tool exists.
Args:
name: Tool name
Returns:
True if tool is available
"""
def system_fonts() -> List[str]:
"""
Get list of system fonts.
Returns:
List of available font names
"""
def show_html(
html_string: str,
width: int = 950,
height: int = 600,
**kwargs
) -> None:
"""
Display HTML content in Jupyter notebook.
Args:
html_string: HTML content string
width: Display width
height: Display height
**kwargs: Additional parameters
"""Tools for converting Earth Engine JavaScript code to Python.
def js_to_python(
in_js_file: str,
out_py_file: str = None,
use_qgis: bool = True,
**kwargs
) -> str:
"""
Convert JavaScript Earth Engine code to Python.
Args:
in_js_file: Input JavaScript file path
out_py_file: Output Python file path
use_qgis: Whether to use QGIS-compatible syntax
**kwargs: Additional conversion parameters
Returns:
Converted Python code string
"""
def js_snippet_to_py(
js_snippet: str,
add_new_cell: bool = False,
import_ee: bool = True,
import_geemap: bool = True,
show_map: bool = True,
**kwargs
) -> str:
"""
Convert JavaScript code snippet to Python.
Args:
js_snippet: JavaScript code snippet
add_new_cell: Add as new Jupyter cell
import_ee: Include Earth Engine import
import_geemap: Include geemap import
show_map: Add map display code
**kwargs: Additional parameters
Returns:
Converted Python code
"""
def create_new_cell(
contents: str = "",
cell_type: str = "code",
**kwargs
) -> None:
"""
Create new Jupyter notebook cell.
Args:
contents: Cell contents
cell_type: Cell type ('code' or 'markdown')
**kwargs: Additional parameters
"""
def js_to_python_dir(
in_dir: str,
out_dir: str = None,
use_qgis: bool = True,
**kwargs
) -> None:
"""
Convert directory of JavaScript files to Python.
Args:
in_dir: Input directory path
out_dir: Output directory path
use_qgis: Use QGIS-compatible syntax
**kwargs: Additional parameters
"""Integration with TiTiler for cloud-optimized geospatial tile serving.
class TitilerEndpoint:
"""TiTiler endpoint configuration."""
def __init__(
self,
endpoint: str,
name: str = "TiTiler",
**kwargs
) -> None:
"""
Initialize TiTiler endpoint.
Args:
endpoint: TiTiler endpoint URL
name: Endpoint name
**kwargs: Additional parameters
"""
def check_titiler_endpoint(titiler_endpoint: str = None) -> bool:
"""
Check TiTiler endpoint availability.
Args:
titiler_endpoint: TiTiler endpoint URL
Returns:
True if endpoint is accessible
"""import geemap
# Convert CSV to GeoJSON
geemap.csv_to_geojson(
'points.csv',
'points.geojson',
latitude='lat',
longitude='lon'
)
# Convert shapefile to GeoJSON
geojson_data = geemap.shp_to_geojson('boundaries.shp')
# Convert CSV to shapefile
geemap.csv_to_shp(
'locations.csv',
'locations.shp',
latitude='y',
longitude='x'
)# Download from URL
file_path = geemap.download_from_url(
'https://example.com/data.zip',
out_dir='./downloads',
unzip=True
)
# Download from Google Drive
geemap.download_from_gdrive(
'https://drive.google.com/file/d/abc123/view',
'dataset.zip',
out_dir='./data'
)# Convert JavaScript file
geemap.js_to_python(
'earth_engine_script.js',
'earth_engine_script.py'
)
# Convert code snippet
js_code = """
var image = ee.Image('LANDSAT/LC08/C01/T1/LC08_044034_20140318');
Map.addLayer(image, {bands: ['B4', 'B3', 'B2']}, 'Landsat');
"""
python_code = geemap.js_snippet_to_py(js_code)
print(python_code)# Check if package is installed
if not geemap.check_install('folium'):
geemap.install_package('folium')
# Update geemap
geemap.update_package()# File path type
FilePath = str
# Coordinate reference system
CRS = str
# Bounding box format [minx, miny, maxx, maxy]
BBox = List[float]
# Package information
PackageInfo = Dict[str, Union[str, bool, List[str]]]
# Download parameters
DownloadParams = Dict[str, Union[str, bool, int]]Install with Tessl CLI
npx tessl i tessl/pypi-geemap