1

I want to modify the network analysis library because th graph builder does something I don't want. When there is an intersection between to lines, it creates a node in it. I want to avoid this behaviour, so I did something like :

Calculate the coordinates of every beginning and end of a line in my .shp file

Create a shp that has every node as a point

Associate the first shp containg the lines the id of the beginning point and end point in new attributes called "from" and "to"

define a new function that will each time I want to calculate the graph. It initialises a new Qgsgrapg(), then I loop over the node shp and use the addVertex() method, when it ends, I loop over my line shp and use the addEdge() method. in the end I return the graph.

My problem is it that this last function consumes a bit of time. I got over something like 300k lines, and I guess there is some python overhead in the loop. (I don't know much about these kind of things, I just assume from what I read)

So I thought that now that I made a working project, I could try to optimize it. I'm trying to understand how this function works :

http://qgis.org/api/classQgsLineVectorLayerDirector.html#af14ff34e31a2860edd156090c0f746ef

I suspect it's the one responsible of my problem. I don't know how it really works, but I guess I should find the lines responsible of the new nodes in intersections, delete them (maybe it would need some code adjustment), find a way to recompile this (There are some small c++ plugin guides in github), and tell my module from where to import the new dll (I guess that compiling this would lead to a .dll, I don't know much about c++, I have enough troubles to write std::string)

Ps: I tried to use the networkx library and it's read_shp() method to see if it's fast enough, I got a memory after 2min of processing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.