Skip to main content

Explore geodata interactively.

Project description

geo-explorer

Explore geodata interactively with a file browser.

Opprettet av: ort ort@ssb.no


To install, use either:

poetry add geo-explorer

Or:

pip install geo-explorer

GeoExplorer

It's best to run the app in the terminal.

Create a simple python file and run it:

from geo_explorer import GeoExplorer
from gcsfs import GCSFileSystem

DELT_KART = "ssb-areal-data-delt-kart-prod"
YEAR = 2025

GeoExplorer(
    start_dir=f"{DELT_KART}/analyse_data/klargjorte-data/{YEAR}",
    favorites=[
        f"{DELT_KART}/analyse_data/klargjorte-data/{YEAR}",
        f"{DELT_KART}/visualisering_data/klargjorte-data/{YEAR}/parquet",
    ],
    center=(59.91740845, 10.71394444),
    zoom=13,
    file_system=GCSFileSystem(),
    port=3000,
).run()
poetry run python my_file.py
# or
python my_file.py

Export as code

The export button can be used to "save" your map. Copy the printed code and paste it into a new file. Running this file will give you an app with the same bounds, data, coloring and attribute table.

Starting the app with data already loaded, filtered and colored

Use the 'data' argument to add data to the map at startup. 'data' can be:

  • a list of file paths
  • a dict with GeoDataFrames as values and labels as keys
  • a dict with file paths as keys and filter function (or None) as value (note that the filter function must be formated as a string!)

Set 'column' to color the geometries.

Optionally specify the colors with the 'color_dict' argument (with column values as dict keys and color codes (hex) or named colors (https://matplotlib.org/stable/gallery/color/named_colors.html) as dict values).

Here is an example of a GeoExplorer app where data is loaded, filtered and colored:

import sgis as sg

# Create a custom GeoDataFrame to add to the map
jernbanetorget = sg.to_gdf([10.7535581, 59.9110967], crs=4326).to_crs(25833)
jernbanetorget.geometry = jernbanetorget.buffer(500)
jernbanetorget["what"] = "Jernbanetorget buffered 500 meters"

GeoExplorer(
    start_dir=f"{DELT_KART}/analyse_data/klargjorte-data/{YEAR}",
    favorites=[
        f"{DELT_KART}/analyse_data/klargjorte-data/{YEAR}",
        f"{DELT_KART}/visualisering_data/klargjorte-data/{YEAR}/parquet",
    ],
    data={
        "jernbanetorget_500m": jernbanetorget,
        f"{DELT_KART}/analyse_data/klargjorte-data/{YEAR}/ENTUR_Holdeplasser_punkt_p{YEAR}_v1.parquet": "kjoeretoey != 'fly'",
    },
    column="kjoeretoey",
    color_dict={
        "jernbane": "darkgreen",
        "buss": "red",
        "trikk": "deepskyblue",
        "tbane": "yellow",
        "baat": "navy",
    },
    center=(59.91740845, 10.71394444),
    zoom=13,
    file_system=GCSFileSystem(),
    port=3000,
).run()

filter functions

Filtering data can be done in the GeoExplorer init, as shown above, or in the app.

Filter functions can be:

  • polars expression or an iterable of such, e.g.: (pl.col("FYLKE") != "50", pl.col("FYLKE") != "03")
  • lambda functions accepted by pandas.loc, e.g. lambda x: x["kjoeretoey"] != "fly"
  • queries accepted by pandas.query, e.g. kjoeretoey != "fly"

Note that the filter functions must be wrapped in quotation marks ("") if used in the GeoExplorer init.

For large datasets, the polars approach might be noticeably faster, both because polars is faster and because the data is stored as polars.DataFrames and converted to pandas and back if the polars filtering fails.

Local files

For local files, use the LocalFileSystem class, which simply implements glob and ls methods based on the standard library (os and glob).

from geo_explorer import GeoExplorer
from geo_explorer import LocalFileSystem

GeoExplorer(
    start_dir="ssb-areal-data-delt-kart-prod/analyse_data/klargjorte-data/2025",
    file_system=GCSFileSystem(),
).run()

Other file systems can be used, as long as it acts like fsspec's AbstractFileSystem and implement the methods ls and glob. The methods should take the argument 'detail', which, if set to True, will return a dict for each listed path with the keys "updated" (timestamp), "size" (bytes), "name" (full path) and "type" ("directory" or "file").

Developer information

Git LFS

The data in the testdata directory is stored with Git LFS. Make sure git-lfs is installed and that you have run the command git lfs install at least once. You only need to run this once per user account.

Dependencies

Poetry is used for dependency management. Install poetry and run the command below from the root directory to install the dependencies.

poetry install -E test --no-root

Tests

Use the following command from the root directory to run the tests:

poetry run pytest  # from root directory

For VS Code there are extensions for opening a python script as Jupyter Notebook, for example: Jupytext for Notebooks.

Code quality

Run 'ruff' on all files with safe fixes:

poetry run ruff check --fix .

Formatting

Format the code with black and isort by running the following command from the root directory:

poetry run black .
poetry run isort .

Pre-commit hooks

We are using pre-commit hooks to make sure the code is correctly formatted and consistent before committing. Use the following command from the root directory in the repo to install the pre-commit hooks:

poetry run pre-commit install

It then checks the changed files before committing. You can run the pre-commit checks on all files by using this command:

poetry run pre-commit run --all-files

Documentation

To generate the API-documentation locally, run the following command from the root directory:

poetry run sphinx-build -W docs docs/_build

Then open the file docs/_build/index.html.

To check and run the docstrings examples, run this command:

poetry run xdoctest --command=all ./src/sgis

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the MIT license, SSB sgis is free and open source software.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Credits

This project was generated from Statistics Norway's SSB PyPI Template.

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

geo_explorer-0.7.4.tar.gz (54.2 kB view details)

Uploaded Source

Built Distribution

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

geo_explorer-0.7.4-py3-none-any.whl (53.5 kB view details)

Uploaded Python 3

File details

Details for the file geo_explorer-0.7.4.tar.gz.

File metadata

  • Download URL: geo_explorer-0.7.4.tar.gz
  • Upload date:
  • Size: 54.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for geo_explorer-0.7.4.tar.gz
Algorithm Hash digest
SHA256 ae55288432f0e18da5a1f19b7799d1bc983eb01f57d13e2feba0645d4a5ae7ba
MD5 a90f78bb90b9e42c21621ad34b7f78c0
BLAKE2b-256 3a132cfc8a1383af9fffb080b7a8bbffd2195c7322786f99759131efb13ab669

See more details on using hashes here.

Provenance

The following attestation bundles were made for geo_explorer-0.7.4.tar.gz:

Publisher: release.yml on statisticsnorway/geo-explorer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file geo_explorer-0.7.4-py3-none-any.whl.

File metadata

  • Download URL: geo_explorer-0.7.4-py3-none-any.whl
  • Upload date:
  • Size: 53.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for geo_explorer-0.7.4-py3-none-any.whl
Algorithm Hash digest
SHA256 af728be9eb20fdd34c5c9caa5b44568eb10302c77f5ba269ca87072eacffc89c
MD5 73a734989ad13bb1e1d148223e2b4402
BLAKE2b-256 14e4068d8de07707d462b47e28888d14cc93f9570dff4812fd133d421fd42670

See more details on using hashes here.

Provenance

The following attestation bundles were made for geo_explorer-0.7.4-py3-none-any.whl:

Publisher: release.yml on statisticsnorway/geo-explorer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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