Example: Transform Templates, Expressions and Queries

We learn to use a function by clicking on a template in the Transform panel, 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 show in blue preview color what a proposed command will do before we issue that command.  Previews can 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.

 

transform_preview_01.png

 

In the Contents pane we choose the Transform panel.

 

transform_preview_02.png

 

We click on the Convert to Line template.   This drawing uses Geom as the name of the geometry field that contains the shapes of objects in the drawing.

 

transform_preview_03.png

 

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.

 

transform_preview_04.png

 

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

 

transform_preview_05.png

 

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 to show progress 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 heart of the query is a single function, GeomConvertToLine([Geom]), which takes the [Geom] field and converts whatever is in it to a line object.   

 

Manifold is full of such useful functions.   In addition to reading documentation and browsing functions within lists in the Query Builder, clicking on templates in the Transform panel 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([Geom]) function we can use it in our own, custom work.   We copy the function from the Command Window (no need to keyboard when we can copy and paste) and then back in the Transform panel we paste it into the Expression tab of the panel.

 

transform_preview_06.png

 

The Transform panel 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.

 

transform_preview_03.png

 

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.

 

transform_preview_07.png

 

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:

 

CASE

WHEN [Number] > 30

  THEN GeomConvertToLine([Geom])

ELSE [Geom]

END

 

Manifold will immediately evaluate the above to create a preview.

 

transform_preview_08.png

 

The preview above shows that all regions which have a Number value greater than 30 will be converted into lines.   Those regions which have a Number value less than or equal to 30 will be copied in unmodified form.

 

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.

 

transform_preview_09.png

 

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

 

transform_preview_10.png

 

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.

 

transform_preview_11.png

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

 

See Also

Style

 

Contents Pane

 

Contents - Transform

 

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

 

Example: Construct JSON String using Select and Transform - Use the Select panel and the Transform panel 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 Templates - In this example we open a drawing and edit objects in the drawing using Transform panel 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 panel 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 panel 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 Expression - Use the Expression tab of the Transform panel 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 panel template, an exploration of the difference between using Copy and Sum for transfer options.