In the map shown below, I have manually created the dummy lines (in green).
Using python, and without using PostGIS or sextante, I would like to automate the creation of these dummy links between a point and a line layer, based on the following criteria:
- Depending on the polygon size, I should be able to add an
X
amount of dummy links between the centroid (point) and its nearest projection(s) onto the roadway layer. - The script so that the largest polygons get the most amount of dummy links and the smallest get the least amount.
- The script should connect the newly created dummy link to nearest highway based on a classifications scheme, i.e. connect to "busier" highways first
- If a polygon does not have any roads/links in it, the script should allow the centroid of that polygon to connect to roads outside of its boundaries within
Y
units of distance - The dummy links must be connected to the roadway layer in such a way that this roadway layer could be potentially used for routing including the dummy links.
- Therefore, the dummy link layer must have the same attributes as the road layer
- Create a new layer with all the new dummy links
Question:
Is this possible using Qgis and Python alone? any pointers as to where to start or can you help in providing a pseudocode to assist me to solve this problem?
Best Answer
I'd add my answer as a comment, but since I can't comment (no reputation enough), I'll add as an answer. It seems that you are trying to add centroid connectors to feed into a traffic assignment algorithm. Right? I should say that doing it automatically is not considered best practice in this industry, but it you are going to do it, I'd like to suggest you to make it proportional to the amount of network comprised within the polygon (roadway stock) and the displacement of this network as well.
I'll also mix some of the transportation modelling jargon with the GIS jargon...
First of all, are you considering splitting links or just connecting the new centroid connectors (dummy links) to the existing extremities of the links? Since I don't know what is the case, I'll assume that you want to connect them to the existing extremities. And it DOES make a huge difference in the algorithm if anybody is wondering.
Now is where I think there are two major questions you need to think about: 1st - How to weigh the criteria closest links versus busiest links 2nd - How to spread the connectors through the TAZ so you don't have them all clustered together?
I'll not answer thse questions, so when it comes to the part of the algorithm to actually add centroids, I'll add a single one.
The algorithm I am suggesting is:
Loop through the centroids adding the connectors to a new layer
Now let's put some codes to these steps (I hope the variables names are self explanatory):
Steps 1 & 2:
Let's assume there is TAZ field in both the centroids layer and the TAZ (polygon) layer. Something like this:
Step 3:
Step 4:
#This code is very slow, but will suffice #You should look into using spatial index, but this is what I could write by heart...
Step 5:
Well... It ended up being an answer longer than I had anticipated, but it should get you started... And just as a warning, I did NOT test this code, so it is likely to have typos and other mistakes...