Example: Use a Transform Dialog Expression to Create Buffers in a Drawing

In this example we use the Expression tab of the Transform Dialog to create three different sizes of buffers for different lines in a drawing.  We then automatically create a query which does the same thing.

eg_xform_draw01_01.png

 

We will start with a drawing that shows the locations of Roman roads in Europe and around the Mediterranean as lines.

 

If we open the table for the drawing we see that there is a CLASS field that describes whether the road is a major or minor road.

 

eg_xform_draw01_02.png

 

Clicking Ctrl-End jumps us to the end of the table.   We can see that the values in the CLASS field include the text values Major Road and Minor Road

 

eg_xform_draw01_03.png

 

We will click on the drawing window and then zoom into a region in France where we know that some roads are major roads and some roads are minor roads.    Our task is to create buffer zones, that is, area objects, around the major and the minor roads but to create a substantially larger buffer around the major roads instead of around the minor roads.

 

The point of such a task in archaeological research might be to define target regions for remote sensing searches, perhaps using ground-penetrating radar, with the notion that it may be worthwhile to search larger regions adjacent to major roads where there might be a greater likelihood of finding structures or other remains than with minor roads.

 

eg_xform_draw01_04.png

With the focus on the drawing window we choose Edit - Transform to launch the Transform dialog, and then we click on the Expression tab.

 

eg_xform_draw01_05.png

 

The Expression tab allows us to write an SQL expression that will be immediately evaluated, on the fly, as we write it with the results being previewed in the drawing window.  The results shown are only a preview until we click the Update Field button.

 

eg_xform_draw01_06.png

 

We plan on using the GeomBuffer function.  To find it, we start entering the name of the function into the filter box.   As we enter Geom the list of functions shown gets reduced to only those which match what we have entered so far in the filter box.

 

eg_xform_draw01_07.png

 

As we get to GeomB the list is reduced even further.

 

eg_xform_draw01_08.png

 

By the time we enter GeomBu that leaves only one function.  We double-click on the GeomBuffer function to add it into the Expression window without having to manually keyboard the name of the function.

 

eg_xform_draw01_09.png

 

The Transform dialog's pane has all the fields associated with the drawing's table so we can save some more keyboarding by highlighting the <geom> argument in the function template and then double-clicking the Geom field where the geom data for the drawing's lines are stored.  

 

eg_xform_draw01_10.png

 

That automatically enters the name of the field.   We then change the <tolerance> argument to a value of 0 (meaning automatic tolerance) and proceed to manually enter the rest of the expression we will use.

 

eg_xform_draw01_11.png

 

In this case we will use the following expression:

 

GeomBuffer([Geom], CASE [CLASS]

 WHEN 'Major Road' THEN 1000

 WHEN 'Minor Road' THEN 5

 ELSE 0.05 END, 0)

 

The value of the <distance> argument for the buffer is set by CASE depending on the value of the CLASS field.  We will use a distance of 1000 when the value of CLASS is 'Major Road', a value of 5 when the value of CLASS is 'Minor Road' and a value of 0.05  when the value of CLASS is anything else.  

 

The moment we enter the above expression, or when enough of it is entered to be understandable as an expression, Manifold starts evaluating it and starts previewing the result in the drawing window.  

 

eg_xform_draw01_12.png

In the illustration above we can see that larger buffer areas have been created around major roads.  The minor roads also have buffers created around them, but the difference between buffers which are at a distance of 1000 from the line and those which are 5 from a line gives the impression in a zoomed out view there are no buffers on the minor roads.

 

We can see that effect by changing the values in the CASE to be used for buffer distances for major roads and for minor roads to 100 and 20.

 

eg_xform_draw01_11a.png

 

Right away as we change the values Manifold will change the preview of the result in the drawing.     If we zoom far in to where such smaller buffer distances are visible we see that the buffer areas on the major roads really are bigger than the buffer areas drawn around the lines for the minor roads.

 

eg_xform_draw01_12a.png

No matter what we write in the Expression pane the results we see in the drawing are only a preview.  As we change the expression the preview dynamically changes.

 

eg_xform_draw01_13.png

 

For example, we can make the buffers on the major roads very much larger than those on the minor roads.

 

eg_xform_draw01_14.png

 

Or, if we like we can make the buffers on the minor roads very much larger than the buffers on the major roads.

 

eg_xform_draw01_15.png

 

Right away, as we change the expression the preview of the result in the drawing window will change.

eg_xform_draw01_16.png

 

At any time we can commit changes to the drawing by pressing the Update Field button.  Or, if we prefer we can write the new objects to a new component, that is, just the buffer areas, which are created by the expression.

 

To do so we change the Update Field action in the pull-down menu to Add Component.

 

 

eg_xform_draw01_16a.png

We can then click on Add Component.

 

 

eg_xform_draw01_16b.png

Two new components, a new table and a drawing for that table, will be created in the Project pane.

 

eg_xform_draw01_16c.png

 

We can double-click open the Roads Table Geom Drawing and zoom into the same region we examined more closely above to see that the buffers which are created by the expression have been saved into the new table that was created by the Add Component button.

 

eg_xform_draw01_16d.png

 

Note that using the Add Component button does not change anything in the original data.   It simply writes the new objects which are created by the expression into a new table and then creates a new drawing to visualize that table's geometry.

 

Automatically Creating a Query

 

At any time we can see the SQL that the Expression tab uses to work its magic.  We first reset the action button back to Update Field.

 

eg_xform_draw01_17.png

 

If we click the Edit Query button a Command Window will open up that is loaded with the query that the Expression tab is executing.

 

eg_xform_draw01_18.png

We can use this capability to save the query for later use, to edit the query in a more sophisticated way than is convenient in the Expression tab or simply to learn more about how SQL can be used.  In the query above the PRAGMA sets up the progress bar, which given the speed of queries is unlikely to appear at all unless the data set is very large.  The THREADS statement parallelizes the query, telling the query engine to use as many threads as there are CPU cores available.

 

Notes

Objects that are created as a result of Transform operations will whenever possible inherit the data content of the fields for that record.   If we create buffers on lines the alteration when we choose Upgrade Field is to the contents of the geom field.   Other fields for that record remain unchanged.

 

See Also

Transform Dialog

 

Transform Options

 

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: 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.

 

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.