Uncategorized

At large scales, rivers are delineated as lines. Typically river network data are in the form of polyline shapefile. To convert polyline network to polygon nework that is consistent is a quite challenging task. In GIS, the buffer approach is not returning the desired results as it returns a rounded buffer around the end polyline points.

For example, using the fixed distance buffer in QGIS with one segment the result is the following:

where each polyline segment creates a buffer polygon that overlaps with other.

The proposed workflow is not ideal but tackles some of the issues, while it returns a continuous representation of the river using polygons.

However the method is quite involved as requires some Matlab coding, and some experience with Houdini. A great advantage of the workflow is that it is non destructive, which means that modifications of the original input shapefile propagated at the end result without additional work.

Starting with Matlab, first we read the polyline shapefile:

MATLAB

1

cvhm_stream=shaperead('gis_data/CVHM_streams');

Each river consists of multiple polyline segments. Therefore we have to group them. Here we use the field NAME to group the rivers.

Group river polylines by name

MATLAB

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

CVHMSTRM(1,1).Name=cvhm_stream(1,1).NAME;

CVHMSTRM(1,1).segments(1,1).X=cvhm_stream(1,1).X;

CVHMSTRM(1,1).segments(1,1).Y=cvhm_stream(1,1).Y;

CVHMSTRM(1,1).segments(1,1).CELLNUM=cvhm_stream(1,1).CELLNUM;

CVHMSTRM(1,1).segments(1,1).row=cvhm_stream(1,1).ROW;

CVHMSTRM(1,1).segments(1,1).col=cvhm_stream(1,1).COLUMN_;

forii=2:size(cvhm_stream,1)

new_river=true;

forjj=1:size(CVHMSTRM,1)

ifstrcmp(CVHMSTRM(jj,1).Name,cvhm_stream(ii,1).NAME)

% add a segment to an existing river

Nseg=size(CVHMSTRM(jj,1).segments,1);

CVHMSTRM(jj,1).segments(Nseg+1,1).X=cvhm_stream(ii,1).X;

CVHMSTRM(jj,1).segments(Nseg+1,1).Y=cvhm_stream(ii,1).Y;

CVHMSTRM(jj,1).segments(Nseg+1,1).CELLNUM=cvhm_stream(ii,1).CELLNUM;

CVHMSTRM(jj,1).segments(Nseg+1,1).row=cvhm_stream(ii,1).ROW;

CVHMSTRM(jj,1).segments(Nseg+1,1).col=cvhm_stream(ii,1).COLUMN_;

new_river=false;

break;

end

end

ifnew_river

Nriv=size(CVHMSTRM,1);

CVHMSTRM(Nriv+1,1).Name=cvhm_stream(ii,1).NAME;

CVHMSTRM(Nriv+1,1).segments(1,1).X=cvhm_stream(ii,1).X;

CVHMSTRM(Nriv+1,1).segments(1,1).Y=cvhm_stream(ii,1).Y;

CVHMSTRM(Nriv+1,1).segments(1,1).CELLNUM=cvhm_stream(ii,1).CELLNUM;

CVHMSTRM(Nriv+1,1).segments(1,1).row=cvhm_stream(ii,1).ROW;

CVHMSTRM(Nriv+1,1).segments(1,1).col=cvhm_stream(ii,1).COLUMN_;

end

end

The grouped rivers are stored into a temporary CVHMSTRM variable. Each polyline segment has shared nodes with other polyline segments, which are supposed to be connected. Here we make a unique list of river nodes.

Graphs are powerful data classes that provide many functionalities. An example is the ability to plot them.

Plot a graph

MATLAB

1

2

3

4

5

ii=8;

p=CVHMSTRM(ii,1).G.plot;

p.XData=CVHMSTRM(ii,1).ND(:,1);

p.YData=CVHMSTRM(ii,1).ND(:,2);

p.NodeLabel=[1:size(CVHMSTRM(ii,1).ND,1)];

With the river graphs at our disposal we are able to identify the main rivers and separate them from the tributaries. The following lengthy code does two things. First Identifies the longest paths which are supposed to be the main rivers and the remaining paths connected to the longest one. Secondly calculates normal vectors for each river node. For the nodes that are connected to only one segment, the normal is equal to the segment normal. For the nodes that are connected to two segments the normal is the average of the two segment normals. Normals will be used later to create the river polygons.

Finally for each river a width and flow rate is added. While the width is a required information for the method the flow rate could be omitted. However when I export the river polygons I would like to have the flow rate associated with each polygon. The code to add width depends on the application and is not shown here.

Last we write the river information into files for reading into Houdini. Note that the coordinate values are divided by a large constant 100000. This is because software like Houdini, blender etc do not handle very well large coordinate values.

Next we are going to build a small graph to achieve the desired result.

Right after python code we have to remove duplicated nodes using the Fuse node. Then we use the Point-Old node to set the normals:

I have also added a Null node that does nothing other than improving visibility and organizing the graph.

If we turn on the display points and display normals options we can see the river polyline, the points and the point normals.

Next we lay down 2 Attribute VOP nodes. These nodes offset the main river by the width amount along the normal direction. In practice I created the positive offset and then duplicated to modify the negative offset.

By double clicking the attribute VOP (dive inside the node) we can modify the geometries at a different level. In addition we can see that the available nodes now are very different.

First we lay down a Get Attribute node to read the width information. For the Get Attribute to work we have to set float as Signature, First Input as Input method, Point as Attribute Class and type width for Attribute. As shown above the ptnum have to be connected to i1. In addition we lay down a constant float equal to 2 and a divide node to calculate the half width.

There is also a normalize node that is connected with the N value of the geometry. This is normalizing the normals of the nodes. The following figure shows the continuation of the Attribute VOP graph

The outcome of half width is further divided by the same large constant we use when writing the houdini files, which is then multiplied by the point normalized normals and added to point Position values. Finally the result of add operation is connected to P geometry output node which shifts the nodes by half width amount. The negative offset node is identical with the exception that between the divide1 and multiply1 we have added a negate node.

Next outside the Attribute VOP node we merge the two offset nodes and then add a skin node. The following figures show the result of the merge and the result of the skin node. For the skin to work properly we have to set some rules about which lines to connect. Set Quadrilaterals for connectivity. For Skin pick Skip every Nth primitive, and for N value use the expression
detail("../python2/","Nseg",0) which sets as N value the number of stream segments. Note that in the initial python code we set a global attribute Nseg.

We can see in areas where the river has sharp bends some weird artifacts may be produced. These will be taken care later. However note how the river width changes smoothly between segments of different width.

Somehow the Skin operator does not transfer the Qrate attribute to the polygons and sets all Qrates to 0. A simple attribute VOP takes care of that. A get and a set attribute node does exactly that.

Then the fuse node with a certain tolerance resolve the artifacts displayed above

Finally we use a python node to write the polygons into a file to export them into a suitable format using the following python code.

Houdini is not the typical software used for scientific visualizations but the possibilities that Houdini offers are truly amazing.

However the first step to use Houdini is to instruct it how to read data. In this guide I’ll describe the steps to read an element mesh. I assume that the mesh data file is in some custom format.

One option is to convert the custom file into a typical file format like wavefront .obj and then read via a file node.

The option I’ll describe here is to use a python node that reads a custom mesh file. The format of the file is as follows

1

2

3

4

5

6

7

8

9

10

11

12

13

14

np nel

X_1 Y_1 Z_1

X_2 Y_2 Z_2

.

.

.

X_np Y_np Z_np

ID1_1 ID2_1 ID3_1 ID4_1

ID1_2 ID2_2 ID3_20

ID1_3 ID2_3 ID3_3 ID4_3

.

.

.

ID1_nel ID2_nel ID3_nel ID4_nel

where
np is the number of mesh nodes and
nel the number of mesh elements. The next np lines are the coordinates of the nodes followed by the node ids that the elements are made of. Note that the file reads either triangular or quadrilateral elements. The triangular elements are indicated by setting 0 as the fourth id of the node element.

By default Houdini interface is split into 3 main windows. Place the cursor anywhere inside the network view window(bottom right), press tab, start typing the word geometry, press enter to confirm and left click to place a geometry node.

Inside the geo1 node, with the cursor still located anywhere inside the network view, press tab, type python and press enter to confirm and left click to place the python node. The window above the network view is where the properties of the selected node are shown. For the python node there is just an almost empty area where one can write python code. I’ll add one more property which is a gui element to select the mesh file.

Find the gear button at the top right corner of the property window. Click once and choose Edit Parameter Interface…

At the left panel select the type file and click the arrow between the 2 panels (the one that points to the right) to add a new parameter.

Highlight the newly created property and rename the Name and label as shown in the figure below

Make sure you spell the Name exactly the same way

Next Apply and Accept to close the window and a new property will appear!

You can now click on the icon after the dropdown menu symbol to chose the mesh file.

Finally paste the following code inside the python Code area and you should be able to read a 2D mesh.