09-26-2016 08:54 AM - edited 09-26-2016 09:08 AM
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.
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:
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:
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
Solved! Go to Solution.
09-27-2016 10:20 PM
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?
09-28-2016 06:03 AM
10-04-2016 12:32 PM
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,
10-29-2019 05:50 PM
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?
10-31-2019 06:07 AM
"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! :-)
10-31-2019 05:10 PM
Moving this question to a separate thread since it does not late tot eh original thread.