Example: Smooth Lines with a Transform Expression

In this example we use an expression written in the Expression tab of the Transform pane 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.




We being with a map with one layer, a drawing showing highways in Mexico as lines.  We have used the Layers pane to specify a calm beige color for the background.  We zoom in to one of the highways so we can see the many changes in direction of the line.




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 launch the Transform pane.




In the blank expression pane we enter the following expression:



   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.




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 do not press Update Field there will be no change in the data and the drawing window will return to showing the lines unchanged.




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.  



   GeomLength([Geom], 0)/50)


That will smooth lines to 2% of their lengths.




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.




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






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.







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.  




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 pane.  We can now modify the query or save it for later use by choosing Edit - Save as Query.    


The query text is:


PRAGMA ('progress.percentnext' = '100');


  SELECT [mfd_id],



   GeomLength([Geom], 0)/50) AS [n_Geom]

  FROM [Mexico Roads]

  THREADS SystemCpuCount()

) SET [Geom] = [n_Geom];



The PRAGMA statement controls the progress bar display, which is not likely to be seen with such small data and thus instantaneous function, and the THREADS statement is a housekeeping statement saying to use all CPU cores in parallel.   Without the housekeeping statements the query is a simple UPDATE query because it operates on the original data in the original table:  



  SELECT [mfd_id],



   GeomLength([Geom], 0)/50) AS [n_Geom]

  FROM [Mexico Roads]

) SET [Geom] = [n_Geom];


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




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.




Pressing the Edit Query button with the action button set to Add Component tells the pane 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.



Pressing the Edit Query button launches the Command Window populated with the automatically generated query:  


CREATE TABLE [Mexico Roads Table Transform] (

  [mfd_id] INT64,

  [Geom] GEOM,

  INDEX [mfd_id_x] BTREE ([mfd_id]),

  INDEX [Geom_x] RTREE ([Geom]),

  PROPERTY 'FieldCoordSystem.Geom' '{ "Base": "World Geodetic 1984 (WGS84)", "Eccentricity": 0.08181919084262149, "LocalScaleX": 0.0001, "LocalScaleY": 0.0001, "MajorAxis": 6378137, "Name": "Latitude \/ Longitude", "System": "Latitude \/ Longitude", "Unit": "Degree" }'


CREATE DRAWING [Mexico Roads Table Transform Drawing] (

  PROPERTY 'Table' '[Mexico Roads Table Transform]',

  PROPERTY 'FieldGeom' 'Geom'


PRAGMA ('progress.percentnext' = '100');

INSERT INTO [Mexico Roads Table Transform] (






   GeomLength([Geom], 0)/50)

FROM [Mexico Roads]

THREADS SystemCpuCount();


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.


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 Pane


Command Window




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 pane 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 pane 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 Pane - How the Expressions tab of the Transform pane may be used to change the values of fields.  


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


Example: Use a Transform Expression to Create Buffers in a Drawing - Use the Expression tab of the Transform pane 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 Expression - Use the Expression tab of the Transform pane 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 pane  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 pane , seeing what it does in a preview, looking at the query Manifold creates and then trying out the function in the Expression tab.