mgaudin / Hy2roresO

QGIS Plugin that compute some stream hierarchisation system (Strahler, Horton, Shreve)
Other
5 stars 2 forks source link

Plantage avec MultiLineStringZ #1

Open sig-pnrnm opened 4 years ago

sig-pnrnm commented 4 years ago

Je viens de découvrir ce plugin, qui répondrait à un besoin que j'avais identifié depuis longtemps (bravo 👍 ) J'ai voulu le lancer sur ma couche issue de la Bd-Carthage (2014). Malheureusement, j'obtiens ce message d'erreur :

Une erreur est survenue lors de l'éxécution du code Python: 

TypeError: MultiLineStringZ geometry cannot be converted to a polyline. Only single line or curve types are permitted. 
Traceback (most recent call last):
  File "C:/Users/Sylvain/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\Hy2roresO-master\hydroreso.py", line 191, in run
    self.run_process()
  File "C:/Users/Sylvain/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\Hy2roresO-master\hydroreso.py", line 246, in run_process
    edges, nodes = create_edges_nodes(features, name_column, alt_init_column, alt_final_column)
  File "C:/Users/Sylvain/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\Hy2roresO-master\hydroreso.py", line 538, in create_edges_nodes
    node1_geom = geom.asPolyline()[0]
TypeError: MultiLineStringZ geometry cannot be converted to a polyline. Only single line or curve types are permitted.

Version de Python : 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] 
Version de QGIS : 3.6.2-Noosa Noosa, 656500e0c4 

Chemin Python :
C:/PROGRA~1/QGIS3~1.6/apps/qgis/./python
C:/Users/Sylvain/AppData/Roaming/QGIS/QGIS3\profiles\default/python
C:/Users/Sylvain/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins
C:/PROGRA~1/QGIS3~1.6/apps/qgis/./python/plugins
C:\Program Files\QGIS 3.6\bin\python37.zip
C:\PROGRA~1\QGIS3~1.6\apps\Python37\DLLs
C:\PROGRA~1\QGIS3~1.6\apps\Python37\lib
C:\Program Files\QGIS 3.6\bin
C:\PROGRA~1\QGIS3~1.6\apps\Python37
C:\PROGRA~1\QGIS3~1.6\apps\Python37\lib\site-packages
C:\PROGRA~1\QGIS3~1.6\apps\Python37\lib\site-packages\win32
C:\PROGRA~1\QGIS3~1.6\apps\Python37\lib\site-packages\win32\lib
C:\PROGRA~1\QGIS3~1.6\apps\Python37\lib\site-packages\Pythonwin
C:/Users/Sylvain/AppData/Roaming/QGIS/QGIS3\profiles\default/python
C:\Users\Sylvain\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\cadastre\forms
C:/Users/Sylvain/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\SwapVectorDirection

Je vais tenter en enregistrant ma couche en polylignes simples, mais je le signale au cas où vous travailliez encore à son amélioration.

A+

Sylvain

sig-pnrnm commented 4 years ago

Bon, après avoir converti le SHP en polylignes, j'ai un nouveau message d'erreur :

Une erreur est survenue lors de l'éxécution du code Python: 

IndexError: list index out of range 
Traceback (most recent call last):
  File "C:/Users/Sylvain/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\Hy2roresO-master\hydroreso.py", line 191, in run
    self.run_process()
  File "C:/Users/Sylvain/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\Hy2roresO-master\hydroreso.py", line 303, in run_process
    process_network(edges, sources_edges, orders_to_compute, edges.copy(), {}, {}, {})
  File "C:/Users/Sylvain/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\Hy2roresO-master\hydroreso.py", line 1787, in process_network
    compute_stroke_outgoing_island(dict_strokes, dict_forks, edge.island.id_stroke, outgoing_edges_island)
  File "C:/Users/Sylvain/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\Hy2roresO-master\hydroreso.py", line 1546, in compute_stroke_outgoing_island
    outgoing_edges_island[0].id_stroke = island_id_stroke
IndexError: list index out of range

Version de Python : 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] 
Version de QGIS : 3.6.2-Noosa Noosa, 656500e0c4 

Chemin Python :
C:/PROGRA~1/QGIS3~1.6/apps/qgis/./python
C:/Users/Sylvain/AppData/Roaming/QGIS/QGIS3\profiles\default/python
C:/Users/Sylvain/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins
C:/PROGRA~1/QGIS3~1.6/apps/qgis/./python/plugins
C:\Program Files\QGIS 3.6\bin\python37.zip
C:\PROGRA~1\QGIS3~1.6\apps\Python37\DLLs
C:\PROGRA~1\QGIS3~1.6\apps\Python37\lib
C:\Program Files\QGIS 3.6\bin
C:\PROGRA~1\QGIS3~1.6\apps\Python37
C:\PROGRA~1\QGIS3~1.6\apps\Python37\lib\site-packages
C:\PROGRA~1\QGIS3~1.6\apps\Python37\lib\site-packages\win32
C:\PROGRA~1\QGIS3~1.6\apps\Python37\lib\site-packages\win32\lib
C:\PROGRA~1\QGIS3~1.6\apps\Python37\lib\site-packages\Pythonwin
C:/Users/Sylvain/AppData/Roaming/QGIS/QGIS3\profiles\default/python
C:\Users\Sylvain\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\cadastre\forms
C:/Users/Sylvain/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\SwapVectorDirection

Là, je ne vois pas ce qui peut poser problème...

Si jamais vous avez une piste ?

johngreenspace commented 3 years ago

My french is not the best but I think I am having the same problems as Sylvain. I first had the 'MultiLineStringZ' error but I think I solved this by exporting the data layer from an shape file to a different format and forcing it to use a simple LineString. I don't think shape files will work as inputs as they appear to be MultiLineString geometry and there's nothing you can do to change this (I tried).

But now when I run the software I hit a different error - "list index out of range":

2020-11-11T23:07:33 WARNING Traceback (most recent call last): File "C:/Users/john/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\Hy2roresO-master\hydroreso.py", line 191, in run self.run_process() File "C:/Users/john/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\Hy2roresO-master\hydroreso.py", line 246, in run_process edges, nodes = create_edges_nodes(features, name_column, alt_init_column, alt_final_column) File "C:/Users/john/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\Hy2roresO-master\hydroreso.py", line 538, in create_edges_nodes node1_geom = geom.asPolyline()[0] IndexError: list index out of range

I have tried lots of options of different file formats and making the vector stream network very simple but keep getting this error. I am using QGIS 3.14. It looks like maybe this software is not being supported any longer? That's a shame as it does exactly what I want! I really don't want to have to work with rasters, DTMs etc. Thanks for any help. John

mgaudin commented 3 years ago

Bonjour,

Merci de l'intérêt que vous portez à notre plugin !

En effet, un "bug" connu de notre plugin est qu'il ne fonctionne pas avec des shapefiles contenant des géométries MultiLineStringZM. Notre implémentation a été conçue pour qu'il fonctionne pour les géométries LineString.

Pour le détail plus technique : nous avons utilisé une méthode appelée asPolyline qui renvoie le contenu de la géométrie sous forme de polyligne si le wkbType est WKBLineString, sinon une liste vide sinon. Ainsi, avec un MultiLineStringZM, la méthode renvoit systématiquement une liste vide pour le contenu de la géométrie. C'est un problème connu que nous devrions ajouter à notre documentation en ligne.

Le moyen le plus simple que nous pouvons vous conseiller est de convertir le MultiLineStringZM en LineString. Il existe une façon simple et native dans QGIS de le faire dans Vecteur > Outils de géométrie > De morceaux multiples à morceaux uniques. Vous pouvez ensuite enregistrer la sortie sous la forme d'un nouveau shapefile.

Si vous souhaitez continuer à travailler avec des géométries MultiLineStringZM, quelques modifications dans le code source sont nécessaires.

--

Hello,

Thank you for your interest in our plugin!

The plugin is not working because the geometries in your shapefile are MultiLineStringZM, whereas we made our implemention to make it work for LineString geometries. In particular, we used a method called asPolyline that returns contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list. So with a MultiLineStringZM, it would never work as it would always return an empty list for the content of the geometry. This is a known issue that we should add to our documentation online.

The easiest way we could advise you is to convert the MultiLineStringZM into LineString. There is a simple and native way in QGIS to do that in Vector > Geometry tools > Multipart to single parts. You can then save the output as a new shapefile.

If you'd like to keep working with MultiLineStringZM, a few modifications in the source code are needed.

ArcheoWA commented 2 years ago

Hi I am also having this issue. I have tried multipart to single part, v.clean, geometry checker and merge and it still remains unresolved. I have been able to get the tool to work on the data before changes were made to the network but they were required to link up parts. I have a feeling the errors relate to me editing the joins in my network but I have checked my network using the Water Net Analyzer Plugin tools 1 Water Network Constructor and 2 Flow path upsteam so I know my network connects and should be a singular network.

I have tested this on QGIS 3.16, 3.22 and 3.26.1 and it happens on every one.