Skip to main content

a Python library that provides a high-level, leafmap-like API for working with PyQGIS

Project description

qgis-map

image

A Python library that provides a high-level, leafmap-like API for working with PyQGIS

Features

  • High-level API: Simple, intuitive methods inspired by leafmap
  • Basemap support: Easy access to OpenStreetMap, Esri, Google, CartoDB, and more
  • Vector layers: Add shapefiles, GeoJSON, GeoPackage, and other vector formats
  • Raster layers: Add GeoTIFFs, COGs, and apply color ramps
  • Time slider: Create interactive time-based visualizations with dockable panels
  • Dockable panels: Create custom interactive panels in QGIS

Installation

pip install qgis-map

Quick Start

Use qgis-map within the QGIS Python console or in a PyQGIS script:

from qgis_map import Map

# Create a map with a basemap
m = Map(basemap="OpenStreetMap")

# Add vector data
m.add_vector("path/to/data.geojson", layer_name="My Data", zoom_to_layer=True)

# Add raster data with a color ramp
m.add_raster("path/to/dem.tif", colormap="terrain", layer_name="Elevation")

Usage Examples

Adding Basemaps

from qgis_map import Map, get_basemap_names

# See all available basemaps
print(get_basemap_names())

# Create map with a basemap
m = Map(basemap="CartoDB.DarkMatter")

# Add additional basemaps
m.add_basemap("Esri.WorldImagery", layer_name="Satellite")
m.add_basemap("HYBRID")  # Google Hybrid

# Add custom XYZ tiles
m.add_basemap(
    "https://custom.tiles.server/{z}/{x}/{y}.png",
    layer_name="Custom Tiles"
)

Adding Vector Layers

from qgis_map import Map

m = Map()

# Add a shapefile
m.add_vector("countries.shp", layer_name="Countries")

# Add GeoJSON with styling
m.add_vector(
    "cities.geojson",
    layer_name="Cities",
    style={
        "color": "#3388ff",
        "stroke_color": "#000000",
        "stroke_width": 1
    },
    zoom_to_layer=True
)

# Add a GeoDataFrame
import geopandas as gpd
gdf = gpd.read_file("data.gpkg")
m.add_gdf(gdf, layer_name="My GeoDataFrame")

Adding Raster Layers

from qgis_map import Map

m = Map()

# Add a GeoTIFF
m.add_raster("elevation.tif", layer_name="DEM")

# Add with color ramp
m.add_raster(
    "temperature.tif",
    colormap="RdYlBu",
    vmin=-10,
    vmax=40,
    layer_name="Temperature"
)

# Add a Cloud Optimized GeoTIFF (COG)
m.add_cog(
    "https://example.com/data.tif",
    layer_name="Remote COG",
    zoom_to_layer=True
)

# Add a WMS layer
m.add_wms(
    url="https://ows.mundialis.de/services/service",
    layers="TOPO-OSM-WMS",
    layer_name="Topo WMS"
)

Time Slider

from qgis_map import Map

m = Map()

# Create a time slider to switch between layers
layers = {
    "2020": "data/ndvi_2020.tif",
    "2021": "data/ndvi_2021.tif",
    "2022": "data/ndvi_2022.tif",
    "2023": "data/ndvi_2023.tif",
}
m.add_time_slider(layers=layers, time_interval=2)

Utility Methods

from qgis_map import Map

m = Map()
m.add_basemap("OpenStreetMap")
m.add_vector("data.geojson", layer_name="My Layer")

# Get layer names
print(m.get_layer_names())

# Zoom to a layer
m.zoom_to_layer("My Layer")

# Zoom to bounds
m.zoom_to_bounds((-122.5, 37.5, -121.5, 38.5))

# Set center and zoom
m.set_center(lat=37.7749, lon=-122.4194, zoom=12)

# Remove a layer
m.remove_layer("My Layer")

# Clear all layers (keep basemap)
m.clear_layers(keep_basemap=True)

# Export to image
m.to_image("output.png", width=1920, height=1080)

Creating Custom Dock Widgets

from qgis_map import Map
from PyQt5.QtWidgets import QLabel, QVBoxLayout, QWidget

m = Map()

# Create a custom widget
widget = QWidget()
layout = QVBoxLayout()
layout.addWidget(QLabel("Custom Panel Content"))
widget.setLayout(layout)

# Add as dockable panel
dock = m.create_dock_widget("My Panel", widget, position="right")

Available Basemaps

  • OpenStreetMap: OpenStreetMap, OSM
  • CartoDB: CartoDB.Positron, CartoDB.DarkMatter, CartoDB.Voyager
  • Stadia/Stamen: Stadia.StamenToner, Stadia.StamenTerrain, Stadia.StamenWatercolor
  • Esri: Esri.WorldStreetMap, Esri.WorldImagery, Esri.WorldTopoMap, Esri.WorldTerrain, Esri.NatGeoWorldMap, Esri.OceanBasemap
  • Google: ROADMAP, SATELLITE, TERRAIN, HYBRID
  • Other: OpenTopoMap

API Reference

See the full API documentation for detailed information about all available methods.

Credits

This package was inspired by leafmap and is built on PyQGIS.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qgis_map-0.1.0.tar.gz (29.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qgis_map-0.1.0-py2.py3-none-any.whl (17.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file qgis_map-0.1.0.tar.gz.

File metadata

  • Download URL: qgis_map-0.1.0.tar.gz
  • Upload date:
  • Size: 29.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for qgis_map-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f7e4057cbf0226e222e76c2b675373e2dde5bcce8455c090d33455d074fbcb5c
MD5 52a4da5a12b79a0c0594f4370f1c5b8a
BLAKE2b-256 ada75af646a6502a1a04fec5f704d815af24f5f51c964e0ecffef33d7a6a2ce4

See more details on using hashes here.

File details

Details for the file qgis_map-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: qgis_map-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for qgis_map-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 df09df2ec7c0b6eb062ec62b50f85510692e068c9634bb88ba7ec8696d8bbd1b
MD5 4052c7ae8f2dcbda46d660e4bfeb2de4
BLAKE2b-256 8cee242ba03cb6a2cc033601942f94dc37242b020a1cef2219e47ddb28552a14

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page