Tuesday, April 17, 2007

Using FME to report lines lengths per grid

I recently received a request from a reader asking me to give some more detail about how I accomplished the grid/valve KML report in "FME as a Spatial Intelligence tool for Smallworld". He wanted to do a slightly different report that summarized length of lines per grid.

Instead of explaining how I did that original report, I tried to see for myself if what he was asking was in itself an easy query in FME. I created a similar report using FME Workbench. You can see the FMW file here.

In less than an hour I was able to take as input Smallworld area and line features, and then compute the total length of all lines for a given area and then create both a CSV and KML report. CSV is a good and simple tabular report format. KML provides a nice visual representation that anyone using Google Earth can use to see your query results.

If you have FME Workbench, you can open the report_pipe_lengths_by_grid.fmw file and view the comments I put in there describing how the data/transformer flows work. If you do not have FME, you can download a fully functional trial version from http://www.safe.com.

The basic steps included:
  • read area and line feature sets from Smallworld into FME Workbench
  • use the LineOnAreaOverlayer transformer to split the line features at the area boundaries
  • use the LengthCalculator transformer to calculate the length of each line feature inside a given area boundary
  • use the Aggregator transformer to sum up the length of all lines per area feature
  • use the FeatureMerger transformer to assign the aggregate line length to each area feature
  • write results out to a KML file (click here for image of result)
  • write results out to a CSV file (click here for file)
The steps were fairly easy and demonstrate again the power of the FME tool for reporting and data manipulation applications.

[Shameless commercial plug: if you would like to explore how you could use FME to get meaningful reports out of your data, please contact me at the e-mail addresses listed on the "Contact Information" in the side bar of this blog]

Tuesday, April 10, 2007

getting a list of all users currently connected to Smallworld

I learned a new aspect of Windows command-line scripting the other day that I thought might be worth sharing here.

The requirement was to get a list of all users connected to a particular swmfs server and notify them that the server was about to go down.

I discovered that the FOR command is just what the doctor ordered for this task. The basic form is as follows...

FOR /F "skip=5 delims=@" %%i IN ('swmfs_list -full \\%COMPUTERNAME%\sw400\product\data message.ds') DO net send %%i Smallworld server going down in 2 minutes.


Where...

  • FOR /F ... IN ...
    • Command key words that tell the system that you want to iteratively process the results of some file or command
  • ('swmfs_list -full \\%COMPUTERNAME%\sw400\product\data message.ds')
    • the command that will have each line processed individually for some information. This particular command provides a list of all the user@computername that are connected to message.ds in the specified folder on %COMPUTERNAME%
  • %%i
    • the internal variable representing each line of the file/command
  • "skip=5 delims=@"
    • instructions to the command to skip the first 5 lines of swmfs_list and then also split the processed lines by the @ character.
  • DO
    • a command key word that indicates that what follows next is the command to be processed on each line of iterator
  • net send %%i Smallworld server going down in 2 minutes.
    • the NET SEND command is used to send the message "Smallworld server going down in 2 minutes" to the user specified in variable %%i. Remember that the variable %%i represents the first element of each line after it has been split by the @ character.

Special note about the variables. If you are running this script from within a BAT file, you need to reference the variable with two percent signs: eg., %%i. If you want to test this functionality at the command line, you need to reference the variable with only one percent sign: eg., %i.

I hope you find this useful.

getting a list of all users currently connected to Smallworld

I learned a new aspect of Windows command-line scripting the other day that I thought might be worth sharing here.

The requirement was to get a list of all users connected to a particular swmfs server and notify them that the server was about to go down.

I discovered that the FOR command is just what the doctor ordered for this task. The basic form is as follows...

FOR /F "skip=5 delims=@" %%i IN ('swmfs_list -full \\%COMPUTERNAME%\sw400\product\data message.ds') DO net send %%i Smallworld server going down in 2 minutes.


Where...

  • FOR /F ... IN ...
    • Command key words that tell the system that you want to iteratively process the results of some file or command
  • ('swmfs_list -full \\%COMPUTERNAME%\sw400\product\data message.ds')
    • the command that will have each line processed individually for some information. This particular command provides a list of all the user@computername that are connected to message.ds in the specified folder on %COMPUTERNAME%
  • %%i
    • the internal variable representing each line of the file/command
  • "skip=5 delims=@"
    • instructions to the command to skip the first 5 lines of swmfs_list and then also split the processed lines by the @ character.
  • DO
    • a command key word that indicates that what follows next is the command to be processed on each line of iterator
  • net send %%i Smallworld server going down in 2 minutes.
    • the NET SEND command is used to send the message "Smallworld server going down in 2 minutes" to the user specified in variable %%i. Remember that the variable %%i represents the first element of each line after it has been split by the @ character.
I hope you find this useful.

Tuesday, April 3, 2007

CST 4.1 allows single-quote strings

CST version 4.1 now allows single-quote strings.

Here's an example. Let's say you wanted to put in the short-hand notation for inch in a string. So you might try...


MagikSF> length << "5""
$
**** Error (parser_error): on line 1
length << "5""
^
Missing end of statement


The Magik compiler gets confused by your use of the double-quote character as a string delimiter and an inch unit.

To get around that in Magik, you would have to do something like...


MagikSF> length << write_string(5,%")
$
"5""


But as of version 4.1 you can use single quotes for strings...


MagikSF> length << '5"'
$
"5""


And if you wanted to do something similar with the short hand for feet units, you could do...


MagikSF> length << "5'"
$
"5'"



Incidentally...

MagikSF> '5' = "5"
$
True