Repository: geojupyter/jupytergis (language: python)

Issue:
Add back ShapeFile Support
Should fix #140 & #117 

https://github.com/user-attachments/assets/48b9cb16-f7e8-40eb-8792-48c3b00b10c5




Discussion / hints:
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/arjxn-py/jupytergis/fix-shapefile?urlpath=lab) :point_left: Launch a Binder on branch _arjxn-py/jupytergis/fix-shapefile_
Hi @brichet, thanks for the review :)

> can we add tests on it to prevent it from being broken

Sure, I'll be happy to add those, haven't added one to JGIS before so I'd once have to give a look to other tests and PR how they do it.

> looks like changing the color only affect the border of the shapes. Would it be easy to propagate it to the background also ?

Yeah, I notice that too. I'll be happy to look into that as well. On a side note I'll also see if the same is happening for GeoJSON layer too as in the case of ShapeFile too, it is first being converted to GeoJson and then being overlayed on the map. But at the moment i'm quite unsure about the complexity of the same hence if it's easy I'll be sure to fix it directly but in case I couldn't manage to I'll be happy to open an issue for the same to keep track. 
> But at the moment i'm quite unsure about the complexity of the same hence if it's easy I'll be sure to fix it directly but in case I couldn't manage to I'll be happy to open an issue for the same to keep track.

I was looking at it and you're right, the issue is the same for the GeoJSON layer. 
It has to be fixed for the `VectorLayer`, I think probably at https://github.com/geojupyter/jupytergis/blob/7cf2425b6e05015f438aa8a4f6346c446addb474/packages/base/src/mainview/mainView.tsx#L555
> > But at the moment i'm quite unsure about the complexity of the same hence if it's easy I'll be sure to fix it directly but in case I couldn't manage to I'll be happy to open an issue for the same to keep track.
> 
> I was looking at it and you're right, the issue is the same for the GeoJSON layer. It has to be fixed for the `VectorLayer`, I think probably at
> 
> https://github.com/geojupyter/jupytergis/blob/7cf2425b6e05015f438aa8a4f6346c446addb474/packages/base/src/mainview/mainView.tsx#L555

Thanks for looking into it already 🚀, this is helpful. I'll be happy to make a quick try on it to see if it can be fixed easily.

Fix patch:
diff --git a/examples/shapefile.jGIS b/examples/shapefile.jGIS
new file mode 100644
index 00000000..82f23925
--- /dev/null
+++ b/examples/shapefile.jGIS
@@ -0,0 +1,102 @@
+{
+  "layerTree": [
+    "54e0ea1f-32fd-4ff2-90fb-ad449a38f902",
+    "9ccab8f8-a170-4977-92b1-ab5f42175c48",
+    "61ef4256-0d6b-4810-93a7-cf29b9e3ae00"
+  ],
+  "layers": {
+    "54e0ea1f-32fd-4ff2-90fb-ad449a38f902": {
+      "name": "OpenStreetMap.Mapnik Layer",
+      "parameters": {
+        "source": "780c4234-ba6d-4da2-9731-739f6c4d8033"
+      },
+      "type": "RasterLayer",
+      "visible": true
+    },
+    "61ef4256-0d6b-4810-93a7-cf29b9e3ae00": {
+      "filters": {
+        "appliedFilters": [],
+        "logicalOp": "all"
+      },
+      "name": "Custom Shapefile Layer",
+      "parameters": {
+        "color": {
+          "fill-color": "#ff0000",
+          "stroke-color": "#ff0000",
+          "stroke-line-cap": "round",
+          "stroke-line-join": "round",
+          "stroke-width": 1.25
+        },
+        "opacity": 1.0,
+        "source": "df86531e-086d-48fa-bfec-98477ec554a4",
+        "type": "line"
+      },
+      "type": "VectorLayer",
+      "visible": true
+    },
+    "9ccab8f8-a170-4977-92b1-ab5f42175c48": {
+      "name": "Custom Shapefile Layer",
+      "parameters": {
+        "opacity": 1.0,
+        "source": "284311a5-01a0-4333-a120-19c23a37e064",
+        "type": "line"
+      },
+      "type": "VectorLayer",
+      "visible": true
+    }
+  },
+  "options": {
+    "bearing": 0.0,
+    "extent": [
+      -8262247.857073612,
+      4961071.288111334,
+      -8221407.547578438,
+      5002025.042910661
+    ],
+    "latitude": 40.79089967838061,
+    "longitude": -74.03759794079146,
+    "pitch": 0.0,
+    "projection": "EPSG:3857",
+    "zoom": 11.430346702791901
+  },
+  "sources": {
+    "284311a5-01a0-4333-a120-19c23a37e064": {
+      "name": "Custom Shapefile Source",
+      "parameters": {
+        "additionalFiles": {},
+        "attribution": "",
+        "encoding": "UTF-8",
+        "path": "https://www2.census.gov/geo/tiger/GENZ2015/shp/cb_2015_us_county_500k.zip",
+        "projection": "WGS84"
+      },
+      "type": "ShapefileSource"
+    },
+    "780c4234-ba6d-4da2-9731-739f6c4d8033": {
+      "name": "OpenStreetMap.Mapnik",
+      "parameters": {
+        "attribution": "(C) OpenStreetMap contributors",
+        "maxZoom": 19.0,
+        "minZoom": 0.0,
+        "provider": "OpenStreetMap",
+        "url": "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
+        "urlParameters": {}
+      },
+      "type": "RasterSource"
+    },
+    "df86531e-086d-48fa-bfec-98477ec554a4": {
+      "name": "Custom Shapefile Source",
+      "parameters": {
+        "additionalFiles": {},
+        "attribution": "",
+        "encoding": "UTF-8",
+        "path": "https://docs.geoserver.org/stable/en/user/_downloads/30e405b790e068c43354367cb08e71bc/nyc_roads.zip",
+        "projection": "WGS84"
+      },
+      "type": "ShapefileSource"
+    }
+  },
+  "terrain": {
+    "exaggeration": 0.0,
+    "source": ""
+  }
+}
\ No newline at end of file


Test patch:
diff --git a/ui-tests/tests/gis-files/shapefile-test.jGIS b/ui-tests/tests/gis-files/shapefile-test.jGIS
new file mode 100644
index 00000000..018eef6c
--- /dev/null
+++ b/ui-tests/tests/gis-files/shapefile-test.jGIS
@@ -0,0 +1,98 @@
+{
+  "sources": {
+    "773e2245-d11b-42d5-a4ac-2f50293d11c7": {
+      "type": "RasterSource",
+      "name": "OpenStreetMap.Mapnik",
+      "parameters": {
+        "url": "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
+        "minZoom": 0,
+        "maxZoom": 19,
+        "attribution": "(C) OpenStreetMap contributors",
+        "provider": "OpenStreetMap",
+        "urlParameters": {}
+      }
+    },
+    "1c374c77-ab13-4583-a225-8a2f1d8d55b8": {
+      "type": "ShapefileSource",
+      "name": "Custom Shapefile Source",
+      "parameters": {
+        "attribution": "",
+        "projection": "WGS84",
+        "encoding": "UTF-8",
+        "additionalFiles": {},
+        "path": "https://www2.census.gov/geo/tiger/GENZ2015/shp/cb_2015_us_county_500k.zip"
+      }
+    },
+    "52aebf1f-713f-413c-a77e-b1cc096ddb86": {
+      "type": "ShapefileSource",
+      "name": "Custom Shapefile Source",
+      "parameters": {
+        "attribution": "",
+        "projection": "WGS84",
+        "encoding": "UTF-8",
+        "additionalFiles": {},
+        "path": "https://docs.geoserver.org/stable/en/user/_downloads/30e405b790e068c43354367cb08e71bc/nyc_roads.zip"
+      }
+    }
+  },
+  "layers": {
+    "56629dbf-c321-4953-9c54-cc9321af53ba": {
+      "type": "RasterLayer",
+      "parameters": {
+        "source": "773e2245-d11b-42d5-a4ac-2f50293d11c7"
+      },
+      "visible": true,
+      "name": "OpenStreetMap.Mapnik Layer"
+    },
+    "19c17b24-704f-4557-bc8e-4c98df293a7a": {
+      "type": "VectorLayer",
+      "parameters": {
+        "type": "line",
+        "opacity": 1,
+        "source": "1c374c77-ab13-4583-a225-8a2f1d8d55b8"
+      },
+      "visible": true,
+      "name": "Custom Shapefile Layer"
+    },
+    "f9dad6ae-eca9-4667-8538-d628c91cfdd3": {
+      "type": "VectorLayer",
+      "parameters": {
+        "type": "line",
+        "opacity": 1,
+        "source": "52aebf1f-713f-413c-a77e-b1cc096ddb86",
+        "color": {
+          "fill-color": "#ff0000",
+          "stroke-color": "#ff0000",
+          "stroke-width": 1.25,
+          "stroke-line-join": "round",
+          "stroke-line-cap": "round"
+        }
+      },
+      "visible": true,
+      "name": "Custom Shapefile Layer"
+    }
+  },
+  "layerTree": [
+    "56629dbf-c321-4953-9c54-cc9321af53ba",
+    "19c17b24-704f-4557-bc8e-4c98df293a7a",
+    "f9dad6ae-eca9-4667-8538-d628c91cfdd3"
+  ],
+  "options": {
+    "latitude": 45.89950745475744,
+    "longitude": -81.95989943738823,
+    "zoom": 2.527260252685426,
+    "bearing": 0,
+    "pitch": 0,
+    "projection": "EPSG:3857",
+    "extent": [
+      -18872442.044319667,
+      -4038758.305284189,
+      624973.5026437324,
+      15567277.941105189
+    ]
+  },
+  "terrain": {
+    "source": "",
+    "exaggeration": 0
+  }
+}
\ No newline at end of file
diff --git a/ui-tests/tests/ui.spec.ts b/ui-tests/tests/ui.spec.ts
index 534d5d04..2953e825 100644
--- a/ui-tests/tests/ui.spec.ts
+++ b/ui-tests/tests/ui.spec.ts
@@ -4,7 +4,7 @@ import path from 'path';
 test.use({ autoGoto: false });
 
 test.describe('UI Test', () => {
-  const fileList = ['test.jGIS', 'buildings.qgz'];
+  const fileList = ['test.jGIS', 'buildings.qgz', 'shapefile-test.jGIS'];
 
   test.describe('File operations', () => {
     test.beforeAll(async ({ request }) => {