Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InfoWorks - addition of nodes into existing links #14

Open
Franklin-A opened this issue Mar 18, 2021 · 2 comments
Open

InfoWorks - addition of nodes into existing links #14

Franklin-A opened this issue Mar 18, 2021 · 2 comments

Comments

@Franklin-A
Copy link

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
Copy link
Contributor

lbutler commented Mar 19, 2021

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:

  • Loop through the bends that make up the line object
  • Measure the distance between the current vertex and the next vertex
  • Keep looping through vertexes until you have overshot the required distance
  • Calculate the angle from the last vertex to the previous one and use some trigonometry to go back the overshot distance
  • You now have the XY of the position along the line you required

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

  • Create new nodes at x distance with the along function
  • Use the lineSliceAlong function to calculate the pipe geometry between each of the new nodes
  • Create a new link object between each node with each of the geometry above
  • Copy the attributes from the original link to each of the slices and delete the original

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
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants