Hexagon Geospatial
MENU

Spatial Modeler Tutorials

Learn more about our products, find answers, get the latest updates, and connect with other Hexagon Geospatial product users, or get support from our professional service team.
Showing results for 
Search instead for 
Do you mean 

Set Matrix Center Snippet

by cassie.tamblyn on ‎12-09-2015 11:52 AM - edited on ‎04-14-2016 02:53 AM by Community Manager (1,187 Views)

Download model

Description:

This model demonstrates how to change the center value in a matrix. The model is a snippet and is intended to be used as part of a workflow (placed into a larger model) and, as such, does not have input/output port operators.

 

Provide the 'New Value' port of the 'Set Center Value' submodel with the desired value, enter a filename for the output matrix that will have this new center value, and you're done. The snippet will take whatever input matrix has been selected for Custom Matrix Input, will change the center value to New Value and write the resulting new matrix to Matrix File Output. The Inputs and Outputs can be removed to hook the snippet up into a larger model workflow.

 

You can see this snippet being used in a larger Model in the Article entitled "Blended Filters". There it is used to initialise another matrix that is the same size as the main matrix selected by the user, but which contains all zeros apart from the center value, which is set to one (via the New Value port shown below).

 

SetMatrixCenter-v15_1_1.gmdx
SetMatrixCenter-v15_1_1.PNG
Set Center Value submodel
SetMatrixCenter-v15_1_1-submodel.PNG
Set Matrix Element submodel
SetMatrixCenter-v15_1_1-sub-submodel.PNG

 

Input parameters:

Set Center Value.New Value: the desired center value (Scalar, Table, Matrix, Raster)

Matrix Output.Filename: name of the output matrix

 

Comments
by
on ‎08-07-2016 07:41 PM

Slick and works great!

 

There's a couple tricks in the 'Set Matrix Element' submodel that may not be obvious to noobs like myself so don't mind if l point them out.

 

(1) If a matrix was reshaped as a vector of N elements, then RowNum*Cols+ColNum yields an index for a particular matrix element. 

 

(2) The InitialValue port on the 'Dynamic Matrix Input (Series)' operator assumes a zerod initial matrix. If that's not the case, then updates will fail. Users can modify the model to include an additional port to set InitialValue to the value to be replaced.

 

The puzzling part is how the index to the Nth item (a scalar) is compared/equated to the output of the 'Dynamic Matrix Input (Series)' operator (a Matrix). So that it can compare values of the same data-type, I suspect the engine simply pulls the InitialValue scalar from the input side of the 'Dynamic Matrix Input (Series)' operator. 

 

Who'd have guessed?

Courses