How to load local shapefile into a JupyterGIS project? #312
-
Note This is almost certainly an out of scope request, as this is not something that is JupyterGIS specific, but a question about interacting with open data through JupyterGIS. So feel free to close as out of scope without any explanation. It would be nice to add an example to the docs that shows how to explore open data sets, which might exist as shapefiles that aren't already in the QGIS format (this is the probably out of scope part). Specific example that I haveThe National Ecological Observatory Network (NEON) publishes all the ecological data it produces, including spatial data as shapefiles. As an example to learn how to play around with open data and JupyterGIS I first wanted to open the 2024 scientific domain shapefile First I created an environment with
resulting manifest:[project]
authors = ["Matthew Feickert <matthew.feickert@cern.ch>"]
channels = ["conda-forge"]
description = "Add a short description here"
name = "neon_gis_data"
platforms = ["linux-64"]
version = "0.1.0"
[tasks.download]
description = "Download NEON domains from https://www.neonscience.org/data-samples/data/spatial-data-maps"
# c.f. https://www.neonscience.org/data-samples/data/spatial-data-maps
cmd = """
mkdir -p data && \
cd data && \
curl -sLO https://www.neonscience.org/sites/default/files/NEONDomains_2024.zip && \
curl -sLO https://github.com/geojupyter/jupytergis/raw/refs/heads/main/examples/buildings.qgz
"""
[dependencies]
jupytergis = ">=0.2.0,<0.3"
qgis = ">=3.40.2,<4"
curl = ">=8.11.1,<9" or with
so now with either tool we're in an activated environment. I then downloaded the zipped shapefile
and for comparison we'll also grab the very nicely provided example
However, the NEON shapefile isn't already a QGIS format and so it needs to be converted. I don't know the Commands/actions to do so:
If I then launch Jupyter Lab (after going one directory up)
and create a new notebook named # Cell 1
from jupytergis_lab import GISDocument
from pathlib import Path
# Cell 2
example_path = Path.cwd() / "data" / "neon_domains_2024.qgz"
doc = GISDocument(str(example_path))
doc the notebook executes without error but it just shows a blank canvas with an interactive distance scale in the bottom left If I change to using the example_path = Path.cwd() / "data" / "buildings.qgz" then things work as expected, both in the notebook and using the JupyterLab Extension. That's great of course, as Motivation for showing open data examplesMy assumption is that I have messed up the conversion from the shapefile to QGIS. This is a "me problem" and outside the However, I think it would be generally useful to show interactions with open data examples (that of course have some long term support so that the examples don't break all the time) as my uninformed assumption is that most open data shapefiles are not (yet) in QGIS format. So providing at least one example, or linking to external documentation, on how to interact with non-QGIS files could be helpful. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
Currently, we don't support opening a local shapefile as a layer, but we will! GeoJSON is supported at the moment, though, so I'd recommend converting your shapefile to geojson and then opening it: ogr2ogr -f GeoJSON output.json input.shp (Yes, the positional args are out of order, I don't know why 🤕 I think you can pass in the zip file directly instead of uncompressing it first, give it a shot :) You can also do this entirely in QGIS. GeoJSON is the only local vector file format that JupyterGIS currently supports. The reason the method you attempted wasn't working is because Finally, I really like this website ;) http://switchfromshapefile.org/ QuantStack folks, did I miss anything important? |
Beta Was this translation helpful? Give feedback.
Currently, we don't support opening a local shapefile as a layer, but we will! GeoJSON is supported at the moment, though, so I'd recommend converting your shapefile to geojson and then opening it:
(Yes, the positional args are out of order, I don't know why 🤕
I think you can pass in the zip file directly instead of uncompressing it first, give it a shot :)
You can also do this entirely in QGIS.
GeoJSON is the only local vector file format that JupyterGIS currently supports.
The reason the method you attempted wasn't working is because
.qgz
or.qgs
files are QGIS project files, not data files, equivalent to JupyterGIS'.jgis
files. QGIS project fil…