ait-energy / qgis-edge-bundling

GNU General Public License v2.0
63 stars 14 forks source link

Provide better warning when input is not in OD format (straight lines with only start and end node) #7

Open spatialsparks opened 6 years ago

spatialsparks commented 6 years ago

Hi Anita

I am trying to get the scripts to work, but currently without success. I have tried with and without clustering, but always get errors:

Example of the set options: screenshot 2017-12-12 08 48 10

Error in Log: screenshot 2017-12-12 08 48 14

Might you have an idea of how to get to the bottom of this?

QGIS version: 2.18 Python version: 2.7.5

CRS of data: EPSG 4326 number of lines: 301

Best regards

brylie commented 6 years ago

One thing that got me was the 'initial step size' being waaaay to large by default. It assumes a CRS in meters, whereas the data may be in a geographic CRS (EPSG 4326 above). Setting the initial step size to 0.0001 may be desirable in your dialogue.

brylie commented 6 years ago

Another thought, does your data cross the prime meridian?

spatialsparks commented 6 years ago

Hi! Will try with a smaller stepsize ASAP. I have now backtracked the error up untill the line:

dot = edges_as_vect[i].normalized() * edges_as_vect[j].normalized()

in bundle_edged.py

And no: the data is only in Switzerland around 47°N/7°E +- 3°

spatialsparks commented 6 years ago

Ok, so Im still getting the error with 0.0001 stepsize: screenshot 2017-12-12 09 42 14

Could it be a version missmatch of sklearn and scipy or something similar?

brylie commented 6 years ago

Ah OK cool. I just went to a mobility as a service conference, called iCoMaaS, where the Swiss public transport system was held in high regard! :-)

brylie commented 6 years ago

Would you mind, privately, sharing a sample of your data? I will try to reproduce locally.

anitagraser commented 6 years ago

Have you tried reprojecting your data to a metric CRS? Also, is there any output in the Python error log? (Log can be opened by clicking on the speech bubble icon in the bottom right corner of the QGIS window.)

brylie commented 6 years ago

@anitagraser from where does the edges_as_vect list inherit the normalized() method?

https://github.com/dts-ait/qgis-edge-bundling/blob/6af5d4e0f5536e2302b807f36d8e38e4f48de560/bundle_edges.py#L83-L102

spatialsparks commented 6 years ago

Hehe! Indeed, the public transportation services are great! :) I now also tryed reprojecting data to EPSG 2056 (swiss coordinate system, metric units) with the same results. Here is the output from the error log:

2017-12-12T09:52:54 1   Cannot find variable: staticmethod
2017-12-12T09:52:54 2   Uncaught error while executing algorithm
            Traceback (most recent call last):
              File "C:/OSGEO4~1/apps/qgis/./python/plugins\processing\core\GeoAlgorithm.py", line 203, in execute
                self.processAlgorithm(progress)
              File "C:/OSGEO4~1/apps/qgis/./python/plugins\processing\script\ScriptAlgorithm.py", line 378, in processAlgorithm
                exec((script), ns)
              File "<string>", line 328, in <module>
              File "<string>", line 173, in force_directed_eb
              File "<string>", line 106, in compute_compatibilty_matrix
            Exception: unknown

I have set manual prints in the python file and it seems to be running through up untill the line mentioned.

spatialsparks commented 6 years ago

Ps. could you give me your mail so I can send you a sample of the data? (Or how does this work on github private sharing? Should I invite you to my private repo?) Pps. Hi Anita, came across this plugin through your colloquium talk at the UZH a few weeks back, great talk btw! :)

brylie commented 6 years ago

My work email is brylie.oxley@maas.global

spatialsparks commented 6 years ago

Thx, already invited you both to a private repo 👍

spatialsparks commented 6 years ago

Another Ps: I also tryed a complete reinstall of QGIS and python and everything before posting here, this shouldnt be an issue

brylie commented 6 years ago

I also tryed a complete reinstall of QGIS and python

That's epic troubleshooting :-)

spatialsparks commented 6 years ago

I got a bit further: Now it seems to be running (initialising 10%) and then crashing. What I did was:

Select all features in attribute table: screenshot 2017-12-12 10 23 08

Then ran the v.clean tool in the GRASS GIS toolbox (didnt work without selecting all features): screenshot 2017-12-12 10 23 53

The error now is: 'NoneType' object has no attribute 'distance' See log for more details

Error log:

2017-12-12T10:26:03 1   Exception: IllegalArgumentException: point array must contain 0 or >1 elements

2017-12-12T10:26:03 1   Exception: IllegalArgumentException: point array must contain 0 or >1 elements

So I guess the problem is in my data somewhere...

anitagraser commented 6 years ago

Looks like it could be zero-length lines again: https://github.com/dts-ait/qgis-edge-bundling/issues/3

brylie commented 6 years ago

@anitagraser good point.

@JoranBeaufort could you try producing a derivative by filtering out zero length origin-destination lines? E.g.

  1. calculate the line lengths
  2. select all lines with length > 0
  3. export as shape file (and re-import)

Then, try re-running the edge bundling on the new layer.

spatialsparks commented 6 years ago

on it

brylie commented 6 years ago

Cool beans. I added links for quick reference.

spatialsparks commented 6 years ago

So I just did this, for comprehension, here the steps: Get line lengths (I saved them as ints, but float would be better): screenshot 2017-12-12 10 37 21

Then using the select by expression with "length" = 0 selected all lengths = 0 (obviously) and deleted them. Then exported as a new SHP with EPSG:2056 (metric). Tryed the bundle tool and still get the error:

2017-12-12T10:41:32 1   Cannot find variable: staticmethod
2017-12-12T10:41:32 2   Uncaught error while executing algorithm
            Traceback (most recent call last):
              File "C:/OSGEO4~1/apps/qgis/./python/plugins\processing\core\GeoAlgorithm.py", line 203, in execute
                self.processAlgorithm(progress)
              File "C:/OSGEO4~1/apps/qgis/./python/plugins\processing\script\ScriptAlgorithm.py", line 378, in processAlgorithm
                exec((script), ns)
              File "<string>", line 315, in <module>
              File "<string>", line 164, in force_directed_eb
              File "<string>", line 103, in compute_compatibilty_matrix
            Exception: unknown

I might be missing something very obvious, but I cant seem to grasp what ATM...

brylie commented 6 years ago

Length should be greater than zero.

brylie commented 6 years ago

Zero length lines may underly the issue.

spatialsparks commented 6 years ago

Oops, I deleted the 0 length lines, sry, wrote it wrong above... Edited now.

spatialsparks commented 6 years ago

Did you try with my data? Does it work on your PC?

spatialsparks commented 6 years ago

Maybe issue #9 has something to do with it?

spatialsparks commented 6 years ago

Another idea: could it be that lines can only be straight lines from A -> B and lines with a via (A -> B -> C) break the script?

anitagraser commented 6 years ago

Yes, that's possible.

spatialsparks commented 6 years ago

Ok, have now created trajectories of lines with single line segments and its been processing for the past 1.5 hours, ill update you with what happens :)

Edit: Coming up on 2.5 hours now. QGIS has become unresponsive, seems to be processing still.

spatialsparks commented 6 years ago

Ok, soOk, so it finally worked by using lines which are not of length 0 and lines with only 2 nodes (origin - destination). I could not cluster them using the optimal clustering algorithm (see issue #9 ) but the "manual" clustering worked. But I could not use the clusters in the bundle_lines tool.

To summarise, what I needed was:

I will report if I find out more... 👍

anitagraser commented 6 years ago

(Just as a note: Some examples in the paper were made with other CRS than EPSG:4326. The challenge is to chose the right parameters for a specific CRS and dataset.)

anitagraser commented 6 years ago

Here are the results I get after simplifying all lines to direct OD connections: https://www.dropbox.com/sh/fkrf7b7xm9e9dgy/AABjJKHSUwkx4EDjS3EihTd8a?dl=0

spatialsparks commented 6 years ago

Ill have a look first thing tomorrow morning, thanks so much! 👍

spatialsparks commented 6 years ago

Looks good, thanks! So the main problem was that the data needs to be linelength > 0 AND lines only with 2 nodes: origin, destination. Added small description to the readme, feel free to merge. Ps. would feel obliged if you could remove the dropbox link to the data again :) Best regards!

anitagraser commented 6 years ago

would feel obliged if you could remove the dropbox link to the data again

Done.

spatialsparks commented 6 years ago

Thanks alot! 👍