Spatial Modeler Discussions

Gain, exchange, and share knowledge, or discuss topics with other Hexagon Geospatial Product pioneers and experts to get the most out of Hexagon Geospatial products.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
Technical Evangelist
Posts: 961
Registered: ‎10-01-2015
Accepted Solution

HOWTO: Use the Regular Expression Search operator in Spatial Modeler

[ Edited ]

We had a request for more information on the Regular Expression Search operator and how it should be used, which I thought might be useful to post for other users as well. 

 

RegEx.PNG

 

You would generally use the Regular Expression Search operator to validate string inputs; i.e., to be sure that a string provided as an input to the model has the expected form.

 

So an example might be as follows...

 

Suppose I have multiple NITF files in a directory and I use the MultiFilenameInput operator to list them.  For my particular data, I might get a list something like this:

 

\\beta\teamspace\args\batchtestdata\inputdata\05jul19181951-p1bs-chip4.ntf,

\\beta\teamspace\args\batchtestdata\inputdata\05jun11150241-m1bs-005519673030_01_p001_chip.ntf,

\\beta\teamspace\args\batchtestdata\inputdata\06apr20183623-m2as_r02c2-052668476010_01_p001.ntf,

\\beta\teamspace\args\batchtestdata\inputdata\06apr20183623-m2as_r11c1-052668476010_01_p001.ntf,

\\beta\teamspace\args\batchtestdata\inputdata\07nov25173946-p1bs-005711045010_01_p001.ntf,

\\beta\teamspace\args\batchtestdata\inputdata\09aug24151221-p1bs_r1c1-052215201010_01_p001-chip.ntf

 

where *-m1*.ntf and *-m2*.ntf are multispectral and *-p1*.ntf are panchromatic.  Maybe the directory also contains other .ntf files with differently-structured filenames that I want to ignore.

 

Inside an iterator where I’m processing each file, I can choose the path of execution based on matching the filename without actually opening the file:

 

 RegEx_Model.png

 

The full model using this iterator is attached.  Using a Report operator to dump the output (list) to the session log, you will see entries like this:

 

23/09/16 18:38:21 SessionMgr(404): \\beta\teamspace\args\batchtestdata\inputdata\05jul19181951-p1bs-chip4.ntf is panchromatic,

23/09/16 18:38:21 SessionMgr(404): \\beta\teamspace\args\batchtestdata\inputdata\05jun11150241-m1bs-005519673030_01_p001_chip.ntf is multispectral,

23/09/16 18:38:21 SessionMgr(404): \\beta\teamspace\args\batchtestdata\inputdata\06apr20183623-m2as_r01c1-052668476010_01_p001.ntf is multispectral,

23/09/16 18:38:21 SessionMgr(404): \\beta\teamspace\args\batchtestdata\inputdata\06apr20183623-m2as_r02c1-052668476010_01_p001.ntf is multispectral,

23/09/16 18:38:21 SessionMgr(404): \\beta\teamspace\args\batchtestdata\inputdata\07nov25173946-p1bs-005711045010_01_p001.ntf is panchromatic,

23/09/16 18:38:21 SessionMgr(404): \\beta\teamspace\args\batchtestdata\inputdata\09aug24151221-p1bs_r1c1-052215201010_01_p001-chip.ntf is panchromatic,

23/09/16 18:38:21 SessionMgr(404): \\beta\teamspace\args\batchtestdata\inputdata\15-16.ntf is something I don't care about,

 

Obviously this is a “toy” example, but it’s one of the kinds of things that regular expression matching and searching are useful for.

 

Writing regular expressions can be tricky, but there are a number of tutorials on the web.  After working through the tutorials, a cheat sheet like this one will be helpful: http://cpprocks.com/files/c++11-regex-cheatsheet.pdf

 

 

Ian Anderson
Chief Product Owner, Desktop Remote Sensing
Hexagon Geospatial
Highlighted
Frequent Contributor
Posts: 106
Registered: ‎06-03-2016

Re: HOWTO: Use the Regular Expression Search operator in Spatial Modeler

Hi Ian, 

 

I use that op to strip the data-type information that ToString wraps values with. Is there an easy way to suppress that markup?

 

Also, a RegEx-Replace operator: roadmap or roadkill? How about a regular Replace?

 

Regards

 

Highlighted
Frequent Contributor
Posts: 106
Registered: ‎06-03-2016

Re: HOWTO: Use the Regular Expression Search operator in Spatial Modeler

Forgot to ask, will the RegEx op be enhanced to allow global matches and return a list, support capture groups, and other standard RegEx features?

Regards
Highlighted
Technical Evangelist
Posts: 961
Registered: ‎10-01-2015

Re: HOWTO: Use the Regular Expression Search operator in Spatial Modeler

Hi Noel,

 

Yes, we've considered expanding the scope of the Regular Expression operator, but I can't provide a timeline at this point.

 

The To String operator does what's described on the box - whatever is provided on the port is converted to a string. So if that has "decoration", that's what ends up in the string. Depending on what you're trying to convert there may be other ways to approach it,

 

Cheers

Ian Anderson
Chief Product Owner, Desktop Remote Sensing
Hexagon Geospatial
Highlighted
New Contributor
Posts: 2
Registered: ‎09-05-2019

Re: HOWTO: Use the Regular Expression Search operator in Spatial Modeler

What's the best way to take raster statistics from many different images and combine them into one table/txt file?

Currently, I can do it fine except for the output. 

 

Also, what's the best way to Dice an image in Spatial Modeler?

 

Thanks,

Justin

Highlighted
Technical Evangelist
Posts: 961
Registered: ‎10-01-2015

Re: HOWTO: Use the Regular Expression Search operator in Spatial Modeler

"Also, what's the best way to Dice an image in Spatial Modeler?"

 

Best way is definitely to upgrade to ERDAS IMAGINE 2020 and use the Create Dice Boundaries operator! :-)

 

Cheers

 

 

Ian Anderson
Chief Product Owner, Desktop Remote Sensing
Hexagon Geospatial
Highlighted
Technical Evangelist
Posts: 961
Registered: ‎10-01-2015

Re: HOWTO: Use the Regular Expression Search operator in Spatial Modeler