Example: Two Drawings from the Same Table

Drawings show geometry that is stored in a geometry field in a table.  We can have more than one drawing that shows the same geometry field, for example, if we would like to create more than one drawing using a different Style to show that same geometry.  Each additional drawing created from the same geometry field takes no additional space, because the common geometry used by all such drawings is just stored once in the same table.  

 

Tables in some databases can have only one geometry field in a table.  GPKG, for example, allows only one geometry field in a table.  PostgreSQL with the PostGIS extension can host more than one geometry field in a table, as can Manifold.   This example uses a table in a Manifold project to show how a table can have multiple geometry fields in the table, with each record having more than one geometry value.

 

For the simple case of creating two drawings from the same table, both of which drawings use the same geom field, please see the Example: Multiple Drawings from the Same Table topic.

 

For another example like this one, where a table has two geometry fields and different drawings are created using those two different geom fields, see the Example: Add a Second Computed Geom Field to a Table  topic.  See also the example, in the Creating Geometry with Computed Fields section of the Example: Add a Computed Field to a Table  topic.

 

This example has three objectives:

 

 

In this example we take a table with a geometry field that is visualized by a drawing.  Geometry fields are of type geom by default in Manifold, so this documentation often refers to a geometry field as simply a geom.   It is Manifold convention to name the main geometry field Geom with a capital G.  That name, which could be any legal name for a field, is the same as the name of the data type used to help us keep track of which field does what.  We could use a different name, such as George or Ringo, but using the name Geom for the geometry field makes it instantly obvious which field in a table is the geometry field.

 

In this example, we add a second geom field, which we will call Tgeom, to the table and create an rtree index on that field so it can be visualized by a drawing.   We copy the first drawing, paste it and adjust the pasted copy so it uses the second geom field.   We demonstrate how to use the Transform pane to show "live" modifications in the second drawing compared to the first drawing.

Tables and the Transform Pane

The Transform pane operates on whatever open component has the focus when the Transform pane is launched.  For example, if we open a table window and then choose the Transform pane, the pane will operate on that table.  The Transform templates available will be those which make sense for that table and for the specific field within the table chosen as the target field.  Whatever previews in blue preview color the pane does will be done within that table, showing the result that would happen to the target field.

 

Such previews will not be passed on and displayed in other components.  For example, a preview in a table for a transform template will not also create a preview in a drawing window that visualizes data from a geom field in the table.   That is because the preview is just a preview, not a change in the actual table data.  Other components, like drawings, which display the actual data in the table will continue to display the actual data.   If we want other components to change we must change the actual data which they display.

 

We could always open the drawing and click on a template in the Transform pane to see a preview in the drawing; however, sometimes we are working within the drawing's table and not in the drawing.    We would like to see what a transform will do to a drawing even though we are working in the table.  We might want to  experiment with data in a table but at the same time we might also want to see what changes such experimentation causes in other components, such as drawings, which depend upon data in the table.   That is easy to do.

 

If we want to experiment with changes to a geom field without actually changing the geom field, we simply create an additional geom field that can function as a copy of the geom field or as a temporary scratch pad to hold changed versions of the geom field.  We can then create a drawing that uses the additional geom field.  We can then make changes to the copied geom field to see what happens.

 

In this example we use a name of Tgeom (a mnemonic for "Temporary Geom")  for that temporary scratch pad field.   We can then create a second drawing, which in this example we name Tgeom Drawing, shows whatever is in Tgeom.    We can then use Tgeom as the target field for Transform templates, using Geom as the source field and we can press Transform to actually change the data within Tgeom so that any components, like Tgeom Drawing, which utilize that field can update as well.

 

Geom never gets modified: it is just the source field from which data is copied or which is used to feed the Transform template that puts data into our temporary scratch pad field, Tgeom.   That allows us to try out as many templates as we like to see what effect they have on Tgeom in the preview in the table, and then, by pressing Transform to update Tgeom to see what effect they have on the Tgeom Drawing.

 

At any time when we are done experimenting we can fill Tgeom full of NULL values again or simply delete that field as well as the temporary, Tgeom Drawing that showed its contents and the table will be back to the way it was originally, with Geom completely unmodified.

Drawings and the Transform Pane

The Transform pane applies to whatever window has the focus.  When a window that has the focus has a drawing layer, we can choose that drawing layer in the Transform pane and the pane will operate on that drawing.   Fields that are available in the pane will be fields in the drawing's table.  

 

When a Transform pane is opened in the context of a drawing any previews the Transform pane causes will be shown in the drawing.   We can exploit that effect to see what a particular template does to objects in the drawing using the preview without any need to press the Transform button.

 

Important: The Transform pane can show previews for its work in a drawing if there is at least one object in the drawing.   Drawings cannot host previews if they are empty, that is, where there are no records in the associated table or where the values for all records in the geom field the drawing uses are NULL values.  That is true even if the preview would involve filling the NULL values with non-NULL geom values.

Example Data

Our project has an Objects table and an Objects Drawing.

 

 

We open the Objects Drawing.

 

 

We zoom to fit, and then zoom out one click on our wheel mouse so that all objects are visible.  The objects appear using default, gray Style for drawings, since we have not styled the drawing to use different colors or symbology.

 

 

We can take a look at the Info pane to see what projection the drawing uses.  We see it is the default Pseudo-Mercator projection, and we remember that for use later when we create another geometry field in the table.

 

We open the table. 

 

 

The table has the usual mfd_id identity field that is used for an index, and a geometry field called Geom containing values of data type geom.  There are three areas, two lines and two points in the table.

 

We will add a second geometry field called Tgeom, and populate that field with a copy of data from the Geom field.  We also will create a drawing to visualize the data in the Tgeom field.    There are two ways to accomplish those tasks:

 

 

We show both procedures, starting first with the easy way.

Add a Second Geometry Field, Populate it, Create Drawing (Easy Way)

 

With the focus either on the drawing window or on the table window, in the Transform pane we choose the Geom field, and then we double-click the Copy template to launch it in the Transform pane.

 

 

In the Copy template we choose geometry as the Use option, and we choose New Field for the Result destination, entering the name Tgeom as the name for the new field.  We enter Tgeom Drawing as the name of the new drawing that will display that new field.

 

Press Transform.

 

 

A new Tgeom field appears in the Objects table, filled with copies of the geometry values in the Geom field.

 

 

A new Tgeom drawing appears in the Project pane.   We can double-click it open.

 

 

We have Styled the drawing to use shades of green, to visually differentiate it from the Objects Drawing.

 

The Tgeom Drawing is an exact duplicate of the Objects Drawing, which is expected since the objects within it are exact duplicates of the objects in the Geom field that the Objects Drawing shows.

Add a Second Geometry Field, Populate it, Create Drawing (Step by step)

Now that we have seen the fast and easy workflow, let us duplicate what we just did step by step.   We will add a geometry field using the Edit - Schema dialog, we will create a drawing that visualizes that geometry field, we then we will populate the new geometry field using the Transform pane,

Add a Geometry Field

To add another field we choose Edit - Schema to open the schema for the table.

 

 

Press the Add command button and choose Field in the drop down menu.

 

 

In the Field dialog, enter Tgeom as the name of the new field and geom as the type.  Press OK.

 

 

The new Tgeom field appears in provisional, bluish color in the Schema dialog, the provisional color indicating the field has not yet been added to the table's schema.   We press Save Changes to commit the changes, creating the new field in the table, and exiting the Schema dialog.

 

 

A new geometry field called Tgeom appears in the table.  So far it is filled with NULL values.    

 

We could populate that new field with copies of geometry from the Geom field and then create a drawing based on the new field, or we could first create the new drawing and then populate the new field.  We will create a new drawing first.

Create a Second Drawing using the New Field

We will now create a second drawing to use the new Tgeom field.

 

 

In the Project pane we right-click on the Objects table and then in the context menu we choose Create - New Drawing.

 

 

In the New Drawing dialog we Name the new drawing Tgeom Drawing.   The dialog is already loaded with the Objects table and the geometry fields in the table.  In the Geometry box we choose Tgeom.

 

 

When we created the Tgeom field in the Schema dialog, we could have also created a spatial index on that field.  However, it is easier to leave the default Create spatial index box checked, so the New Drawing dialog will automatically create that spatial index for us.   

 

By default, a new drawing is created assuming the geometry field is in the default Pseudo-Mercator projection.  We will use that, since the existing Geom field also uses Pseudo-Mercator, as we saw in the Components pane illustration near the beginning of this topic.

 

We press Create Drawing.

 

 

The new drawing appears in the Project.  To open it we can double-click on the Tgeom Drawing.

 

 

When we open the Tgeom Drawing it shows nothing, because the drawing has been created from a geometry field, Tgeom, within the Objects table that is full of NULL values.

Populate the Tgeom Field

We will now populate the Tgeom field using the Transform pane to put values into the Tgeom field based on existing values in the Geom field.   

 

With the focus on the opened Objects table, in the Transform pane we choose the Geom field and then we double-click the Copy template to launch it in the Transform pane.

 

 

In the Transform pane, from the pull down menu in the Use box we choose geometry.  From the pull down menu in the Result box we choose the Tgeom field.

 

Press Transform.

 

 

The geometry values for each record in the Geom field will be copied into the Tgeom field.

 

To see the objects in the Tgeom Drawing we Ctrl-click on the drawing's layer tab, which is a command to Zoom to Fit the contents of that layer.  We could also press the Zoom to Fit button on the main toolbar.  

 

 

We then use the mouse wheel to click out one zoom level to provide a bit of empty margin, to ensure any points on the periphery of the drawing are better in view.  The view is identical to what we see in the Objects Drawing because the objects now in the Tgeom field that the Tgeom Drawing window shows were copied from the Geom field that the Objects Drawing window shows.

 

 

We have Styled the drawing to use shades of green, to visually differentiate it from the Objects Drawing.

 

As we can see, the fast and easy process, doing everything in a single use of the Transform pane, is a lot easier than the step by step, manual procedure.

Changing Objects in the Tgeom Field

We can use the Transform pane to change objects in the Tgeom field, using different templates to take data from the Geom field, transform it, and save the results into the Tgeom field.   The Tgeom Drawing automatically will show whatever we put into the Tgeom field.

 

We can put the focus on the Objects table, the Objects Drawing, or the Tgeom Drawing when using the Transform pane.   All three components share the same table, the Objects table, so all of the fields in that table are available to the Transform pane when the focus is on any of those three components.

 

 

With the focus on the Objects table, in the Transform pane we choose the Geom field and then we double-click on the Buffer template to launch it in the Transform pane.

 

 

In the Buffer template, we enter 5 for the Distance.  Given the Unit setting of Meter, that is a choice of 5 meters.   In the pull down menu for the Result box, we choose the Tgeom field as the result destination.  

 

Press Transform.

 

 

The Tgeom column is immediately updated with geometry for buffer areas.   Note that geometry which used to represent lines and points now is area geometry.

 

 

We can see the results in an immediate comparison if we position undocked windows for the Objects Drawing and the Tgeom Drawing next to each other.

 

The Transform pane is still set to the Buffer template with the parameters previously used.  We can alter the Distance parameter to see what that does.

 

 

We increase the Distance to 15 and then press Transform.

 

The settings in the Transform pane shown above create buffers of 15 meters based on the geometry of objects in the Geom field, and put the results into the Tgeom field.

 

 

The greater Distance means the borders of the buffer areas are created farther away from the edges of the objects from which they are created.

 

 In the Transform pane we press the up button to move up one level, so we can switch templates.

 

With the focus still on the Objects table, and the Geom field still chosen, we double-click the Convert template to launch it in the Transform pane.

 

 

In the Convert template, in the pull down menu for the Convert to option, we choose point.  In the pull down menu for the Result box, we choose the Tgeom field as the result destination.  

 

Press Transform.

 

The template creates points at the locations of coordinates which define objects in the Geom field, and saves those point geometries into the Tgeom field.

 

 

Since we take geometry from the Geom field, and we save the transformed geometry into the Tgeom field, the Geom field is not modified.   Only the Tgeom field is modified.

 

 In the Transform pane we press the up button to move up one level, so we can switch templates.

 

With the focus still on the Objects table, and the Geom field still chosen, we double-click the Enclose template to launch it in the Transform pane.  Note how the template list in the top level of the Transform pane has grown with shortcuts at the top of the list to most recently used transform operations.

 

 

In the Enclose template, in the pull down menu for the Enclose in option, we choose rectangle.  In the pull down menu for the Result box, we choose the Tgeom field as the result destination.  

 

Press Transform.

 

The template creates rectangular areas that are the minimum enclosing, vertically oriented rectangles for objects in the Geom field, and then saves those rectangular area geometries  into the Tgeom field.

 

 

The result places into the Tgeom field area objects which are the enclosing rectangles for line and area objects in the source Geom field, that is, the minimal sized rectangular areas that fully enclose the source objects.  Points are replaced with a pseudo-area that has all four coordinates at the same location, and which are indicated by small square symbols in the drawing.

 

At any time, we can switch the focus to the Objects Drawing and continue to use the Transform pane to operate on fields in the Objects table.

 

 

With the focus on the Objects Drawing, in the Transform pane we choose the Geom field.   That is the same Geom field we have been using in the Objects table, since that is the table for the Objects Drawing.   We double-click on the Enclose template.   

 

Note that the template list in the Transform pane shows the same recently-used shortcuts at the top of the list, since after all we are working with the same fields in the same table.

 

 

In the Enclose template, in the pull down menu for the Enclose in option, we choose rectangle with rotation.  In the pull down menu for the Result box, we choose the Tgeom field as the result destination.  

 

Press Transform.

 

The template creates rectangular areas that are the minimum enclosing, freely rotated rectangles for objects in the Geom field, and then saves those rectangular area geometries  into the Tgeom field.  It is like the rectangle operation we used earlier, but allowing the rectangles to be rotated to enable smaller rectangles to fit over objects.

 

 

The result places into the Tgeom field area objects which are the freely rotated, enclosing rectangles for line and area objects in the source Geom field, that is, the minimal sized rectangular areas that fully enclose the source objects with the rectangle rotated to any orientation.   Unlike the rectangle operation, points are replaced with NULL geometries (which do not display in a drawing).

 

At any time, we can switch the focus to the Tgeom Drawing and continue to use the Transform pane to operate on fields in the Objects table.

 

 

With the focus on the Tgeom Drawing, in the Transform pane we choose the Geom field.  Note that even though the Tgeom Drawing shows geometry from the Tgeom field, we can still choose a different field as the source field for Transform pane operations.   The Geom field we choose is the same Geom field we have been using in the Objects table, since that is the table for the Tgeom Drawing as well as for the Objects Drawing.   We double-click on the Reshape template.   

 

Note that the template list in the Transform pane shows the same recently-used shortcuts at the top of the list, since after all we are working with the same fields in the same table.

 

 

In the Reshape template, in the pull down menu for the Operation option, we choose flip horizontal.  In the pull down menu for the Result box, we choose the Tgeom field as the result destination.  

 

Press Transform.

 

The template flips objects in the Geom field horizontally around the centroid of each geom and saves the resulting geometry into the Tgeom field.

 

 

The resulting objects are a mirror image of the original objects.

 

The Transform pane is still loaded with the Reshape template, so we can choose a different Operation to see what that does.

 

 

In the Reshape template, in the pull down menu for the Operation option, we choose scale.  We enter .5 for both X scale and Y scale.   We leave Tgeom as the choice for the Result destination.

 

Press Transform.

 

The template takes objects from the Geom field, reduces their size by 50% in both X and Y directions, and saves the result into the Tgeom field.   

 

 

The result in the drawing is that objects are now half the size they were while remaining centered at the same locations.  Points, of course, are unaffected.

 

Notes

Cheating a bit with Style - The illustrations in this topic make slight adjustments to default Style for drawings.  Instead of using 1 point width for area borders, line widths and stroke width for point symbols, we use .75 point widths.  That provides a thinner, cleaner look for the small illustrations used.

See Also

Transform

 

Transform Pane

 

Transform Reference

 

Example: Drawings use Geom Fields in Tables  - An essential discussion on how drawings are created from geom fields in tables, including how the drawing knows which coordinate system to use.

 

Example: Multiple Drawings from the Same Table - Illustrates how easy it is to create multiple drawings that use the same table and same geometry by copying and pasting an existing drawing.  Each new drawing takes no additional storage space in the project, but can be formatted differently.   

 

Example: Add a Computed Field to a Table - In this example we add a computed field to a table, illustrating how the computed field automatically changes when changes are made in the fields it uses for computation.   We also show how computed fields can use geometry, automatically updating centroids when areas are changed.  Last, we show how geometry can be created using computed fields, to create effective radius circles for antennas based on the power of the antenna..

 

Example: Add a Second Computed Geom Field to a Table  - We can create tables with more than one geom field in the table and then we can create drawings which use those additional geom fields.   This topic shows how to create a second geom that is a computed field based on the first geom.  The topic also shows some "real world" methods, such as how to remember the use of a geometry function to do what we want, and how to restore a geom that has been moved.    We close with some illustrations of how multiple geoms might be used, and how selection from any drawing or labels based on the same record selects the corresponding objects or labels in all other components based on that record.

 

Example: Create a Drawing from a Geocoded Table - A geocoded table has records with a latitude and longitude for each record.   This example starts with a table containing a list of cities with a latitude and longitude field for the location of each city.   We create a geom from the latitude and longitude fields using a template in the Transform pane and then we create a drawing that shows the cities as points.  This example shows all the infrastructure steps involved.

 

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: Construct JSON String using Select and Transform - Use the Select pane and the Transform pane 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 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.