Jannik-Schilling / generate_swmm_inp

a QGIS plugin for the import and export of SWMM input files (conversion of geodata, e.g. shapefiles or geopackage into SWMM models and vice versa)
GNU General Public License v2.0
35 stars 10 forks source link

generating subcatchments file ... list index out of range #60

Closed sjib closed 1 year ago

sjib commented 1 year ago

While running 3_ImportInpFile im am getting the following error with my data:

`QGIS-Version: 3.28.4-Firenze QGIS-Codeversion: fd0fb72ab3 Qt-Version: 5.15.3 Python-Version: 3.9.5 GDAL-Version: 3.6.2 GEOS-Version: 3.11.1-CAPI-1.17.1 PROJ-Version: Rel. 9.1.1, December 1st, 2022 PDAL-Version: 2.4.3 (git-version: f8d673) Algorithmus gestartet um: 2023-05-02T17:39:37 Algorithmus 3_ImportInpFile startet… Eingabeparameter: { 'DATA_CRS' : QgsCoordinateReferenceSystem('EPSG:2056'), 'GEODATA_DRIVER' : 0, 'INP_FILE' : 'C:\Daten\test.inp', 'PREFIX' : '', 'SAVE_FOLDER' : 'C:\Daten' }

reading inp ... got unicode error with utf-8 , trying different encoding opening the file with encoding: windows-1250 generating options file ... generating inflows file ... generating curves file ... generating quality file ... generating raingages file ... generating junctions file ... generating storages file ... generating outfalls file ... extracting vertices ... generating conduits file ... generating pumps file ... generating weirs file ... extracting poligons ... generating subcatchments file ... Traceback (most recent call last): File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\teksi_standard/python/plugins\generate_swmm_inp\generate_swmm_import_inp_file.py", line 1381, in processAlgorithm polyg_geoms = [get_polygon_from_verts(x) for x in all_subcatchments['Name']] File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\teksi_standard/python/plugins\generate_swmm_inp\generate_swmm_import_inp_file.py", line 1381, in polyg_geoms = [get_polygon_from_verts(x) for x in all_subcatchments['Name']] File "C:\Users/Stefan/AppData/Roaming/QGIS/QGIS3\profiles\teksi_standard/python/plugins\generate_swmm_inp\generate_swmm_import_inp_file.py", line 1339, in get_polygon_from_verts polyg_geom = QgsGeometry.fromPointXY(verts_points[0]).buffer(5, 5) IndexError: list index out of range

Execution failed after 0.68 Sekunden

Lade Ergebnis Layer Algorithmus '3_ImportInpFile' beendet`

Any ideas why this fails?

Jannik-Schilling commented 1 year ago

Most likely, because one (or more) subcatchments has no Polygon and not even a Point.

See: https://github.com/Jannik-Schilling/generate_swmm_inp/issues/59#issuecomment-1525951707

I´m working on a general fix for such cases (e.g. d5dba58), because this can happen to any feature in SWMM.

Jannik-Schilling commented 1 year ago

You can test the current developement version, which already contains some solutions: https://github.com/Jannik-Schilling/generate_swmm_inp/tree/dev_v_0_29

sjib commented 1 year ago

Great thanks. As you mentioned in https://github.com/Jannik-Schilling/generate_swmm_inp/issues/59#issuecomment-1525951707 polygons are not or at least were not necessary for SWMM in the catchment so it would be helpful if the 3_ImportInpFile Process would still work even if there are no polygons for catchment and just write a layer without geometry in that case. My old SWMM projects all have no polygons for catchments. Or just use the coordinate of the node they are attached to as default geometry (-> so the layer would have a geometry that could be worked on if the polygon info for catchment is available later).

Jannik-Schilling commented 1 year ago

Or just use the coordinate of the node they are attached to as default geometry

In SWMM, many polygons can be attached to one node. Following this solution the polygons would be exactly overlapping and only the polygon on top would be visible.

~The current approach sets an empty geometry if the geometry is not available. The user can add a geometry later on, using the tool "add part" from the advanced digitizing toolbar.~ Edit: this doesn´t work with some file formats e.g. gpkg

Jannik-Schilling commented 1 year ago

549710a

Jannik-Schilling commented 1 year ago

Following this solution the polygons would be exactly overlapping and only the polygon on top would be visible.

Ok.. that´s not the main problem. There could also be nodes SWMM without coordinates. In order to work properly in any case, the import tool will replace all missing geometries (as well as combinations of missing geometries) by default geometries (around coordinates "(0,0)" .

sjib commented 1 year ago

In order to work properly in any case, the import tool will replace all missing geometries (as well as combinations of missing geometries) by default geometries (around coordinates "(0,0)" .

QGIS version: 3.28.4-Firenze QGIS code revision: fd0fb72ab3 Qt version: 5.15.3 Python version: 3.9.5 GDAL version: 3.6.2 GEOS version: 3.11.1-CAPI-1.17.1 PROJ version: Rel. 9.1.1, December 1st, 2022 PDAL version: 2.4.3 (git-version: f8d673) Algorithm started at: 2023-05-08T11:17:48 Algorithm '3_ImportInpFile' starting… Input parameters: { 'DATA_CRS' : QgsCoordinateReferenceSystem('EPSG:2056'), 'GEODATA_DRIVER' : 1, 'INP_FILE' : 'C:\Daten\test.inp', 'PREFIX' : '', 'SAVE_FOLDER' : 'C:\Daten }

reading inp ... got unicode error with utf-8 , trying different encoding opening the file with encoding: windows-1250 generating options file ... generating inflows file ... generating curves file ... generating quality file ... generating raingages file ... generating junctions file ... generating storages file ... generating outfalls file ... extracting vertices ... generating conduits file ... generating pumps file ... generating weirs file ... extracting polygons ... generating subcatchments file ... Warning: in section "SUBCATCHMENTS" one (or more) geometries are missing in the input file. Affected feature(s): 1, SubCatch2, 3, 4, 5, 6, SubCatch7, SubCatch8, SubCatch9, 10, 11, 12, SubCatch13, 14, 15, SubCatch16, 17, 18, 19, 20, 21, SubCatch22, 23, 24, 25, 26, 27, 28, SubCatch29, 30, 31, 32, SubCatch33, 34, SubCatch35, 36, 37, SubCatch38, 39, 40, 41, 42, 43, SubCatch44, SubCatch45, 46, 47, 48, 49, SubCatch50, SubCatch51. Default geometries will be used instead. The features can be found around (0,0) all data was saved in C:\Daten Execution completed in 1.12 seconds Results: {}

Loading resulting layers Algorithm '3_ImportInpFile' finished

Great - now it works!

sjib commented 1 year ago
Or just use the coordinate of the node they are attached to as default geometry

In SWMM, many polygons can be attached to one node. Following this solution the polygons would be exactly overlapping and only the polygon on top would be visible.

Also if you have all polygons around (0,0) you can't distinguish them really and they are overlapping

Jannik-Schilling commented 1 year ago

yep, I know. I´m not perfectly happy with the current solution but it covers all the exceptions that I found, so far. Alternatively I could add a shift for every feature. But this might lead to errors with some coordinate reference systems.

Jannik-Schilling commented 1 year ago

so far I'll mark this issue as solved