modelcreate / infoworks-ruby-scripts

A collection of useful Ruby scripts for InfoWorks
MIT License
29 stars 11 forks source link

InfoWorks - addition of nodes into existing links #14

Open Franklin-A opened 3 years ago

Franklin-A commented 3 years ago

Hi Luke

I'm wondering if you can help out with functionality and syntax with regard to inserting nodal items in links.

I'm essentially wanting to automatically create and snap nodes into a selected link. For example, create a node at a distance of 100m from the selected link's start node, then another in another 100m, etc etc until there is no further room. Then snap the newly created nodes into the selected link (i.e. by splitting the link).

I know how to create nodal items at given co-ords but I can't figure out how to return the co-ords of points which are a specified distance along a link. Plus I don't know how to snap the unconnected nodes into a link.

Can this actually be achieved using InfoWorks PRO WS interface (rather than Exchange) - if so have you got any pointers as to how I can go about it? I'm struggling to find anything in the available documentation that comes close to this functionality.

Cheers Andy

lbutler commented 3 years ago

Hi Andy,

Maybe you are already aware of this but in Synergi Water you can do exactly what you describe from the user interface but this feature is missing in InfoWorks, I can see how building a Ruby script to achieve this could be very useful.

The good news is this can definitely be done in Ruby however you would need to do all the spatial calculations on figuring out where a node lays on a line at a set distance yourself.

If you want to see how the spatial algorithm for what you're asking is done you can look at the along function in the Turf.js library, open index.ts in the repo below: https://github.com/Turfjs/turf/tree/master/packages/turf-along

The code is pretty short but in summary:

Now, this is good for creating nodes but you wanted to split the lines at these points so potentially you could use the function 'lineSliceAlong' which does a similar method to the above but collects the vertexes along the way and returns a line object. https://github.com/Turfjs/turf/tree/master/packages/turf-line-slice-along

So bring this all together, you would do the following

The above examples are in Javascript so they would need to be converted to the equivalent in Ruby, however, some more good news is I've already done all of the above though I haven't uploaded it all at the moment, you can see some examples of my use of the library here: https://github.com/modelcreate/infoworks-ruby-scripts/blob/master/scripts/demand_allocation/lib/customer_allocation/spatial.rb

For my use case, I was converting nodes to links and then expanding to a short length, but the same principles could be used for your needs.

Feel free to start looking into the above but I can upload what I have and I'm sure you could adapt it or maybe I could create a separate library to do what you need.

Franklin-A commented 3 years ago

Hi Luke

Many thanks for getting back to me so soon on this - that's very much appreciated. I wasn't aware that Synergi had this functionality - it's now been two decades since I last used it!

I have other means of achieving this fairly quickly but I was wanting to make the procedure 'instant' and without having to leave the InfoWorks environment.

From what you describe it won't be the easiest script to write - but I quite like a challenge so I'll attempt to give it a go - but I strongly suspect I will be begging for help before long! I'm not a programmer and I'm relatively new to Ruby but I do have a reasonable background in coding for other software so I'll see if I can translate my skills. I'm not in any rush to achieve this so I'll have a dabble in due course.

In the meantime, any uploads would be welcomed!