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.


Previews in Manifold save us from errors.  When it is obvious what a proposed operation will do we can correct our workflow before committing any changes.


We start with a drawing of regions in France as areas.




Launch Edit - Transform to open the Transform dialog.




We click on the Convert to Line template.   This drawing uses Geometry as the name of the geom field, an atypical name given that most Manifold users will almost always choose Geom by default.   In this case the name Geometry ws used because some of these screenshots may appear on Manifold web sites and that name is clearer for novices than insider slang like Geom.   Ah, those marketing people... always working all the angles...




The moment we choose the Convert to Line template Manifold will preview what that template would do to the drawing in blue preview color.   The template takes area objects and converts them to lines by drawing a line for the boundary of the area.




We can see what SQL magic is used behind the scenes to accomplish that conversion by pressing the Edit Query button.




That launches the Command Window loaded with the SQL query that is used to do the conversion.   The query is simple: it starts with a housekeeping PRAGMA statement that sets up the progress bar in case of long computations.  The THREADS statement is just the usual automatic parallelization that says to use as many threads as there are CPU cores in the system.  


The guts of the query is a single function, GeomConvertToLine([Geometry]), which takes the [Geometry] field and converts whatever is in it to a line object.   


Manifold is full of such useful functions.   If we are not into reading documentation (for shame!) or browsing functions within lists in the Query Builder, clicking on templates in the Transform dialog to see what they do and then clicking the Edit Query button to see how the SQL works is a great way to learn about functions and how to use them.


Now that we know about the GeomConvertToLine([Geometry]) function we can use it in our own, custom work.   We copy the function from the Command Window (why manually mess with the keyboard when we can copy and paste?) and then back in the Transform dialog we paste it into the Expression tab of the dialog.


The Transform dialog has two tabs: the Template tab provides a list of point-and-click templates while the Expression tab allows us to write our own expressions that are snippets of SQL expressions.    The Expression tab is like a blend of the convenience of a point-and-click infrastructure of the Template tab with the custom power of SQL in the Command Window.




The moment we paste the function into the Expression pane Manifold goes to work to preview it.




Not surprisingly, since we copied and pasted the function from the SQL created for the Convert to Line template, the preview for the function as evaluated in the Expression tab creates exactly the same preview as for the template.


That is fine and cool but more interesting is that now that we know about the function we can play around with writing a more custom expression using the function in the Expression tab.




For example, the drawing of provinces has the French identification number for each region as one of the fields for each record.   We can write an expression that converts to lines only those provinces which have an identification number greater than 30:



WHEN [Number] > 30

  THEN GeomConvertToLine([Geometry])

ELSE [Geometry]



Manifold will immediately evaluate the above to create a preview.




So far, what we have created are just previews.  The actual data has not been modified.   If we like what we see, we can apply the transform by clicking the Update Field button.




The moment we click the Update Field button Manifold will apply the transform to the drawing.    




If we did not want to change the drawing we could have changed the Update Field button to Add Component and then pressed the Add Component button.




That would have created in the Project a copy of the drawing, as modified by the transform, without modifying the original drawing.


See Also

Transform Dialog


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 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: Smooth Lines with a Transform Dialog Expression - Use the Expression tab of the Transform dialog to make lines smoother in a drawing so that longer lines are smoothed more.  Includes examples of using 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.


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.