Example: Smooth Lines with a Transform Dialog Expression

In this example we use an expression written in the Expression tab of the Transform dialog to make lines smoother in a drawing so that longer lines are smoothed more.  We will also use the Edit Query button to show how different queries are created automatically depending on if we want to update a field or to add a new component.

 

eg_xform_smooth01_01.png

 

We being with a drawing showing highways in Mexico as lines.   We zoom in to one of the highways so we can see the many changes in direction of the line.

 

eg_xform_smooth01_02.png

 

We will use an expression to smooth the line, that is to simplify it so that it has fewer changes in direction. One reason we might want to do that could be to create a publication that shows highways in simpler, smoother form for greater legibility.

 

We choose Edit - Transform to open the Transform dialog and then we click on the Expression tab.

 

 

eg_xform_smooth01_03.png

 

In the blank expression pane we enter the following expression:

 

GeomSmooth([Geom],

   GeomLength([Geom], 0)/100)

 

White space is not significant in expressions so we may format what we enter with indents and use of new lines to increase legibility.   The expression takes 1% of the length of the line, as calculated by GeomLength([Geom], 0)/100, and uses that as an argument for the GeomSmooth function that smooths the line.   The result is that we smooth lines to 1% of their lengths.  As a result longer lines will be smoothed more to lose more detail.

 

 

eg_xform_smooth01_04.png

 

As soon as enough of the expression has been entered to be evaluated, Manifold will show a preview of what would result in the drawing window.   The drawing's data is not changed: what is shown is only a preview.  If we Close the dialog without pressing Update Field there will be no change in the data and the drawing window will return to showing the lines unchanged.

 

eg_xform_smooth01_05.png

 

If we look closely we can see that the line has been simplified.    We can increase the effect by dividing by 50 in the expression instead of by 100.   That will smooth lines to 2% of their lengths.

 

 

eg_xform_smooth01_06.png

 

Editing the expression to change the value of 100 to 50 will result in an immediate preview of the results of that altered expression in the drawing window.

 

eg_xform_smooth01_07.png

 

We can see that the line has been simplified, that is "smoothed," even more.

 

eg_xform_smooth01_08.png

 

Comparing the original line with the effects of 1% smoothing (dividing by 100 in the expression) and 2% smoothing (dividing by 50 in the expression) we can more easily see the reduction in detail caused by smoothing.

 

 

 

eg_xform_smooth01_09.png

 

 

We can see what query would be generated to implement this expression and to update the table with the results by pressing the Edit Query button.  

 

eg_xform_smooth01_10.png

 

Doing so opens a Command Window that is populated with an automatically generated SQL query that is the equivalent of the expression we wrote in the Transform dialog.   We can now modify the query or save it for later use.   The query is a simple UPDATE query because it operates on the original data in the original table.

 

The Transform dialog also gives us the option to save changes as a new component instead of updating the original component with changes.  

 

 

eg_xform_smooth01_11.png

 

Switching the action button to Add Component instead of Update Field will change the function to saving results in a new component instead of altering the original component.   That also changes the query that will be generated automatically when we press the Edit Query button.

 

 

eg_xform_smooth01_12.png

 

Pressing the Edit Query button with the action button set to Add Component tells the dialog we want to generate a query which will implement the expression and save the results in a new table with a new drawing to visualize that table.

eg_xform_smooth01_13.png

 

Pressing the Edit Query button launches the Command Window populated with the automatically generated query.   This query is considerably longer than the previous one because instead of being a simple UPDATE query it must create a table and a drawing with all necessary infrastructure, such as the coordinate system to use for the geom, correctly specified, and then insert into the new table the results of the expression.

Notes

Objects that are created as a result of Transform operations will acquire the data content of the fields for that record based on what we choose in the Options button that appears when the Add Component action button is used.  If we replace a line showing a highway with a smoothed version of that line, the alteration when we choose Upgrade Field is to the contents of the geom field.   Other fields for that record, for example, any field that gives the name of the highway, will be copied over based on the Options.

 

See Also

Transform Dialog

 

Command Window

 

Queries

 

Transform Templates

 

Transform Templates - Boolean

 

Transform Templates - Datetime

 

Transform Templates - Geom

 

Transform Templates - Numeric

 

Transform Templates - Text

 

Example: Two Drawings from the Same Table - Take a table with a geom field that is visualized by a drawing.  Add a second geom field to the table and create an rtree index on that field so it can be visualized by a drawing.   Copy the first drawing, paste it and adjust the pasted copy so it uses the second geom field. Demonstrate how to use the Transform dialog to show "live" modifications in the second drawing compared to the first drawing.

 

Example: Copy one Column into Another Column with Transform - How to use the Transform dialog to copy the contents of one column in a table into another column, but only for selected records.  Uses the Products table from the Nwind example data set.  

 

Example: Transform Field Values using an Expression in the Transform Dialog -  How the Expressions tab of the Transform Dialog may be used to change the values of fields.   We include an example of changing the price of selected products and using two different Transform dialogs open at the same time for two different table windows.

 

Example: Construct JSON String using Select and Transform - Use the Select and Transform dialogs to manually construct a JSON string using values from other fields in a table. Shows how we can manipulate text to build desired contents in a field.

 

Example: Edit a Drawing with Transform Dialog Templates -  In this example we open a drawing and edit objects in the drawing using the Transform dialog Template tab.   Includes examples of using the Add Component button and also the Edit Query button.

 

Example: Use a Transform Dialog Expression to Create Buffers in a Drawing - Use the Expression tab of the Transform Dialog to create three different sizes of buffers for different lines in a drawing and then automatically create a query which does the same thing.  Includes examples of using the Add Component button and also the Edit Query button.

 

Example: Clip Areas with a Transform Dialog Expression - Use the Expression tab of the Transform dialog to clip areas in a drawing to fit within horizontal bounds.   Includes examples of using the Add Component button and also the Edit Query button.

 

Example: Transfer Options and Merge Areas - Using the Merge Areas Transform dialog template, an exploration of the difference between using Copy and Sum for transfer options.

 

Example: Transform Templates, Expressions and Queries - We learn to use a function by clicking on a template in the Transform dialog, seeing what it does in a preview, looking at the query Manifold creates and then trying out the function in the Expression tab.