Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7822659
Try exporting vectorLayer to qgis
arjxn-py Jan 24, 2025
3223bec
add index
arjxn-py Jan 24, 2025
bc02e2f
Needed for testing
arjxn-py Jan 24, 2025
4a3ea1b
add layer_id[4] to layertree
arjxn-py Jan 24, 2025
53942b1
Update python/jupytergis_qgis/jupytergis_qgis/tests/test_qgis.py
arjxn-py Jan 24, 2025
9156be4
vector layer exports
arjxn-py Jan 27, 2025
c82b2c3
update test
arjxn-py Jan 27, 2025
9065b71
remove eq.json from test
arjxn-py Jan 27, 2025
d31f9a7
add example for geojson from url
arjxn-py Jan 27, 2025
039cee9
try fixing tests
arjxn-py Jan 27, 2025
0f77936
stroke color for polygon
arjxn-py Jan 27, 2025
84b1baa
Merge branch 'main' into vectorlayer-qgis
arjxn-py Jan 27, 2025
c42ef0a
Make graduated symbology work
arjxn-py Jan 27, 2025
f82583f
Make categorised symbology work
arjxn-py Jan 27, 2025
ddd9019
GUI working
arjxn-py Jan 27, 2025
71b77a5
examples for testing
arjxn-py Jan 27, 2025
9e1435d
use types from jgis, use pixel as units
arjxn-py Jan 28, 2025
b39f5cf
circles work nicely
arjxn-py Jan 28, 2025
16a25e8
All ranges in graduated symbology
arjxn-py Jan 28, 2025
166de01
make categorised work for fill
arjxn-py Jan 28, 2025
ace1f14
Working for lines too
arjxn-py Jan 28, 2025
e30c650
Merge branch 'main' into vectorlayer-qgis
arjxn-py Jan 28, 2025
0165491
some cleanup
arjxn-py Jan 28, 2025
01dbe41
Apply suggestions from code review
arjxn-py Jan 29, 2025
bb7673e
Condense export logic into methods
arjxn-py Jan 29, 2025
43d1696
fix to fill
arjxn-py Jan 29, 2025
15e43c0
fix to line
arjxn-py Jan 29, 2025
4d01d67
Apply suggestions from code review
arjxn-py Jan 29, 2025
8e6174c
Avoid setting opacity, stroke_color again
arjxn-py Jan 29, 2025
6d77c9b
In fill too
arjxn-py Jan 29, 2025
cfe5f5d
Merge branch 'main' into vectorlayer-qgis
arjxn-py Jan 30, 2025
88baa76
circle stroke color
arjxn-py Jan 30, 2025
06a87b1
correct path
arjxn-py Jan 30, 2025
e0b22c2
try fixing tests
arjxn-py Jan 30, 2025
a0c4e7c
Give some consideration to circle-radius
arjxn-py Jan 30, 2025
5349ece
try lean test for now
arjxn-py Jan 30, 2025
39cbbca
Simplify test more for now
arjxn-py Jan 30, 2025
40e179d
Update python/jupytergis_qgis/jupytergis_qgis/qgis_loader.py
arjxn-py Jan 30, 2025
a612da3
non intentional typecasting
arjxn-py Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions examples/world.jGIS
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"layerTree": [
"ef427395-3dad-411d-ae4b-d56190cb2e68"
],
"layers": {
"ef427395-3dad-411d-ae4b-d56190cb2e68": {
"name": "Custom GeoJSON Layer",
"parameters": {
"color": {
"fill-color": "#4ea4d0",
"stroke-color": "#ff0000",
"stroke-line-cap": "round",
"stroke-line-join": "round",
"stroke-width": 1.25
},
"opacity": 1.0,
"source": "5c228c74-5167-4437-a38b-f9302be9b80f",
"symbologyState": {
"renderType": "Single Symbol"
},
"type": "line"
},
"type": "VectorLayer",
"visible": true
}
},
"metadata": {},
"options": {
"bearing": 0.0,
"extent": [
-5350224.080333857,
-8168086.573252421,
13275562.199623892,
12116960.46690232
],
"latitude": 17.459989741135686,
"longitude": 35.59726182186651,
"pitch": 0.0,
"projection": "EPSG:3857",
"zoom": 2.7438377054069027
},
"sources": {
"5c228c74-5167-4437-a38b-f9302be9b80f": {
"name": "Custom GeoJSON Layer Source",
"parameters": {
"path": "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/ne_110m_admin_0_countries.geojson"
},
"type": "GeoJSONSource"
}
}
}
67 changes: 67 additions & 0 deletions python/jupytergis_qgis/jupytergis_qgis/qgis_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
QgsSingleBandPseudoColorRenderer,
QgsVectorLayer,
QgsVectorTileLayer,
QgsWkbTypes,
QgsSingleSymbolRenderer,
)

# Prevent any Qt application and event loop to spawn when
Expand Down Expand Up @@ -400,6 +402,12 @@ def build_uri(parameters: dict[str, str], source_type: str) -> str | None:
layer_config["url"] = url
layer_config["type"] = "xyz"

if source_type == "GeoJSONSource":
path = parameters.get("path", None)
if path is None:
return
return path

if source_type == "RasterSource":
layer_config["crs"] = "EPSG:3857"

Expand Down Expand Up @@ -477,6 +485,65 @@ def build_uri(parameters: dict[str, str], source_type: str) -> str | None:

renderer.setStyles(parsed_styles)

if layer_type == "VectorLayer" and source_type == "GeoJSONSource":
source_parameters = source.get("parameters", {})
uri = build_uri(source_parameters, "GeoJSONSource")
if not uri:
logs["warnings"].append(
f"Layer {layer_id} not exported: invalid GeoJSON source."
)
return

map_layer = QgsVectorLayer(uri, layer_name, "ogr")
if not map_layer.isValid():
logs["warnings"].append(
f"Layer {layer_id} not exported: failed to load GeoJSON source."
)
return

geometry_type = map_layer.geometryType()
layer_params = layer.get("parameters", {})
print(f"Geometry Type: {geometry_type}", layer_params)

if geometry_type == QgsWkbTypes.PointGeometry:
symbol = QgsMarkerSymbol()
color_params = layer_params.get("color", {})
color = QColor(color_params.get("circle-stroke-color"))
opacity = int(layer_params.get("opacity"))
print(f"Point Color: {color.name()}, Opacity: {opacity}")
symbol.setColor(color)
symbol.setOpacity(opacity)
renderer = QgsSingleSymbolRenderer(symbol)

elif geometry_type == QgsWkbTypes.LineGeometry:
symbol = QgsLineSymbol()
color_params = layer_params.get("color", {})
color = QColor(color_params.get("stroke-color"))
opacity = int(layer_params.get("opacity"))
print(f"Line Color: {color.name()}, Opacity: {opacity}")
symbol.setColor(color)
symbol.setOpacity(opacity)
renderer = QgsSingleSymbolRenderer(symbol)

elif geometry_type == QgsWkbTypes.PolygonGeometry:
symbol = QgsFillSymbol()
color_params = layer_params.get("color", {})
opacity = layer_params.get("opacity", 1.0)
symbol.setOpacity(opacity)

fill_color = QColor(color_params.get("fill-color"))
symbol.setColor(fill_color)

stroke_color = QColor(color_params.get("stroke-color"))
stroke_width = color_params.get("stroke-width", 1)

symbol_layer = symbol.symbolLayer(0)
symbol_layer.setStrokeColor(stroke_color)
symbol_layer.setStrokeWidth(stroke_width)
renderer = QgsSingleSymbolRenderer(symbol)

map_layer.setRenderer(renderer)

if layer_type == "WebGlLayer" and source_type == "GeoTiffSource":
source_parameters = source.get("parameters", {})
# TODO: Support sources with multiple URLs
Expand Down
30 changes: 28 additions & 2 deletions python/jupytergis_qgis/jupytergis_qgis/tests/test_qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def test_qgis_saver():
if os.path.exists(filename):
os.remove(filename)

layer_ids = [str(uuid4()), str(uuid4()), str(uuid4()), str(uuid4())]
source_ids = [str(uuid4()), str(uuid4()), str(uuid4()), str(uuid4())]
layer_ids = [str(uuid4()), str(uuid4()), str(uuid4()), str(uuid4()), str(uuid4())]
source_ids = [str(uuid4()), str(uuid4()), str(uuid4()), str(uuid4()), str(uuid4())]
jgis = {
"options": {
"bearing": 0.0,
Expand Down Expand Up @@ -185,6 +185,24 @@ def test_qgis_saver():
"type": "RasterLayer",
"visible": False,
},
layer_ids[4]: {
"name": "Custom GeoJSON Layer",
"parameters": {
"color": {
"fill-color": "#4ea4d0",
"stroke-color": "#ff0000",
"stroke-line-cap": "round",
"stroke-line-join": "round",
"stroke-width": 1.25,
},
"opacity": 1.0,
"source": source_ids[4],
"symbologyState": {"renderType": "Single Symbol"},
"type": "fill",
},
"type": "VectorLayer",
"visible": True,
},
},
"layerTree": [
layer_ids[0],
Expand All @@ -196,6 +214,7 @@ def test_qgis_saver():
],
"name": "group0",
},
layer_ids[4],
],
"sources": {
source_ids[0]: {
Expand Down Expand Up @@ -234,6 +253,13 @@ def test_qgis_saver():
"minZoom": 0,
},
},
source_ids[4]: {
"name": "Custom GeoJSON Layer Source",
"parameters": {
"path": "https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/ne_110m_admin_0_countries.geojson"
},
"type": "GeoJSONSource",
},
},
"metadata": {},
}
Expand Down
Loading