﻿ Example: Drawings use Geom Fields in Tables

# Example: Drawings use Geom Fields in Tables

In this example we take a tour of the relationship between drawings and tables.  We look at how a drawing takes geometry data from a table and how it knows which coordinate system to use.  The very first part repeats some information from the Drawings topic to give us a running start.

Consider a drawing, called Provinces, that shows provinces (regions) in France as areas.

If we right-click on the Provinces drawing in the Project pane and choose Properties we can see the properties for the drawing.

The properties tell us that the Provinces drawing takes its data from a table called Provinces Table and that within that table it uses a geom field called Geom.

Opening the Provinces table we can see that it does indeed include a field called Geom of type geom.   That field contains geom values that encode area objects.

If we right-click on the Provinces Table table in the Project pane and choose Properties we can see the properties for the table.

The FieldCoordSystem.Geom property contains a value starting with a curly left bracket { which is a JSON specification for the coordinate system to be used with the contents of the Geom field.

We can diagram the above relationships as follows:

The drawing's properties tell it which table to use and which field within that table contains the geom information for the drawing.    The table's properties specify which coordinate system to use for each geom type field that is in the table.

Tech Tip:  There is nothing magic about using the name Geom for the field which contains geom types.   The field could just as easily be called Harry or Geometric Data for Objects or any other legal field name.   Naming the field Geom is just a habit for most Manifold users and it is the default name used by Manifold when it creates such fields.   Using that name by default is convenient since everybody automatically knows what it is when they see it.   It certainly is less confusing than naming the field Harry.

To show how that works, we open Provinces Table and then choose Edit - Schema.  We add a field of type geom that we call Jeff.   We then add a spatial index called Jeff_x based on Jeff using the procedure given in the Example: Add a Spatial Index to a Table topic.

Next, using the Transform Dialog we copy the contents of the Geom field into the Jeff field using the procedure given in the Example: Copy one Column into Another Column with Transform topic.

We now have a Provinces Table with two geom fields, one named Geom and the other named Jeff.    We now will add a property to the table's properties that will advertise what coordinate system should be used for the geom values in the Jeff field.

We right-click onto the Provinces Table in the Project pane and choose Properties. In the properties dialog we click on the yellow star button to add a new property that we call FieldCoordSystem.Jeff.

We double-click into the value cell for FieldCoordSystem.Geom and Copy the contents, which specify the coordinate system to use.  We then double-click into the value cell for FieldCoordSystem.Jeff and Paste the coordinate system.  Press Enter to close the edit and then OK to update the table's properties.

The result is that we have added a new property to the table which gives the coordinate system to be used for the geom field named Jeff

Now all we have to do is create a drawing that will use Jeff instead of Geom.    Doing that is easy.   We click on the Provinces drawing in the Project pane, press Ctrl-C to Copy it and then we press Ctrl-V to Paste a copy of the drawing, which will be called Provinces 2 by default.

We right-click the Provinces 2 drawing in the Project pane and choose Properties. In the properties dialog we change the name of the FieldGeom property from Geom to Jeff.   Press OK.   The drawing Provinces 2 will now take its geometry information from the Jeff field in the Provinces Table.

If we open the Provinces 2 drawing and Zoom to Fit we see it is exactly the same as the Provinces drawing.  That makes sense, since we created the Jeff geometry values by copying the Geom geometry values that the Provinces drawing uses.

In the above we show how two different drawings can be created using two different geom fields in the same table, similar to the Example: Two Drawings from the Same Table topic.   In the above the different geom fields are just copies of each other so the content of the drawings is the same.   But, those geom fields could contain different values so the drawings which use the different geom fields could be different as well.

Suppose we decide to use Provinces 2 to change something in the table.  Remember, the Provinces 2 drawing takes its geometry data from the Jeff field.  We select the Centre region in France by ctrl-clicking it.

Next, we push the delete key.  Good-bye, Centre!   We may think that because the Provinces 2 drawing takes its geom data from the Jeff field all we have done is deleted the geom in the Jeff field for the Centre record in the table while leaving the other geom value in the Geom field for that record unmodified.  But that is a mistake.

If we take a look at the Provinces drawing, which takes its geometry information from the Geom field, we see that Centre has disappeared in that drawing as well.  How did that happen?

Pressing the Delete key with an object selected is a command to delete that object, which means deleting the record for that object.  That is a very different thing than editing the value for one cell in the record to set that value to NULL.   When we selected the Centre object and then deleted the Centre object from the Provinces 2 drawing we deleted the entire record for Centre.

If we want to remove the Centre geometry data  from the Provinces 2 drawing while leaving the Centre geometry data in the Provinces drawing, that is easy to do:  we simply set the value of the Jeff field to NULL for the Centre record.   We will demonstrate how to do that.

Since it is good idea to make backups when working with data we do not want to accidentally lose, we begin by making a copy of the Provinces Table and naming the copy Provinces Table with Nulls.  We could work with the Provinces Table directly, of course, but in most real life situations with tables that are not large we will simply make a copy by doing a quick Ctrl-C and Ctrl-V in the Project pane.  We would also save the project under a backup name before making any radical changes.

We will select the Centre record in the illustrations below to make the record more visible.  There is no need to actually select the record to edit it, but for the purpose of illustrations having a red selection background makes it easier to see.

Changing the value of a cell to NULL in a Manifold table is a two step process:  First, put the cell into edited mode and then second, change it to NULL.

We first double-click into the record to open it for editing and we make any change or no change at all.   Some Manifold users get into the habit of entering a few text characters.   Those are harmless whether or not we abandon the edit because we cannot commit an edit with text characters into a geom field.

See the Example: Editing Records in a Table topic.

We have edited the cell to enter the text nothing.  Next, we right-click onto the cell and choose Set to NULL. We then press Ctrl-Enter to commit the edit.

The result is that the geom value in the Jeff field for the Centre record is set to NULL.

We now adjust the Provinces 2 drawing and the Provinces drawing to use the new table.

We open the properties dialog for the Provinces 2 drawing and we change the table to use to Provinces Table with Nulls.  Press OK.

We open the properties dialog for the Provinces drawing and we change the table to use to Provinces Table with Nulls.  Press OK.

Looking at the two drawings side by side we see that Centre has disappeared from Provinces 2 but is still in place in Provinces.   When a geom has a NULL value the drawing shows nothing as there is no object to show for that record.

We can remove another region by changing to NULL the value for that region's record in the Jeff field.

For example, we change the value of the Jeff field to NULL for the Champagne-Ardenne record.

Instantly, in the Provinces 2 drawing the Champagne-Ardenne area object disappears while remaining unchanged, as expected, in the Provinces drawing.

We can diagram how the two drawings use the same table in the diagram below:

The properties of each drawing and the table tell the drawings what to do:

• Each drawing's properties tell it what data to display.   The Table property tells the drawing what table to use.  The FieldGeom property tells the drawing what field inside that table is to be used as a geom field.  The Provinces 2 drawing's  FieldGeom property tells it to use the Jeff field.  The Provinces drawing's  FieldGeom property tells it to use the Geom field.
• The table's properties say what coordinate system to use for each geom field.    The Provinces 2 drawing uses the Geom field so it looks into the table's FieldCoordSystem.Geom property to know what coordinate system to use for that geom data.  The Provinces 2 drawing uses the Jeff field so it looks into the table's FieldCoordSystem.Jeff property to know what coordinate system to use for that geom data.

In most cases drawings we use will take data from a table that has only one geom field.  But in some cases it might make sense to have more than one geom field in a table.   For example, a table that has geom fields showing regions of France as areas might have a second geom field that contains a point showing the location of the capital city of that region.

### Restoring Centre and Champagne-Ardenne

Suppose we would like to restore Centre and Champagne-Ardenne geometry to the Jeff field.   How can we do that given there is no undo?   We can copy the geom data from the Geom field, where it remains unchanged.

We begin by ctrl-clicking the Center record and the Champagne-Ardenne record to select them.

Next, we choose Edit - Transform to launch the Transform dialog.  We will use the copy transform.

We choose Jeff as the Target field, Copy as the template to use and Geom as the source, Value field.  We check the Restrict to selection box.   Press Update Field and the values in the Geom field will be copied into the Jeff field for the selected records.

We can see in the table the values have been copied.

The Provinces 2 drawing is immediately updated with Centre and the Champagne-Ardenne region restored.

## Notes

Multiple records - Some of the illustrations of tables show more than one record for various regions.   Why is that?  GIS data will often use multiple records for each area that makes up a particular region.   For example, the region of Bretagne (known in England as Brittany) includes many islands, each of which is a separate area object in this data.

Provinces vs. Regions - The illustrations in this topic use data from the US government, which show the regions of France as they were before 1 January 2016, when the regions in France were reduced from 22 to 13.  Centre is the same it was with just a change of name.

The drawing is called Provinces and not Regions because it was clipped out of a larger data set showing provincial boundaries for the entire world.  Around the world sub-national divisions such as US states or French regions are called many different things, but the word provinces seems to have become a reasonably generic word that militaries and others engaged in mapping often use.   State is rarely used because in many cultures it is a synonym for country and thus does not capture the notion of the administrative sub-units of a given country.

Centre vs. Centre-Val de Loire  - The region referred to as Centre in this topic was called Centre until 2015, when the new name of Centre-Val de Loire took effect, perhaps in an effort to boost tourism to the genuinely wonderful valley of the Loire river, home to what is perhaps the largest concentration of classic chateaux anywhere in the world.  To this day everyone still calls the region Centre.

Getting Started

User Interface Basics

Tables

Selection

Drawings

Coordinates

Coordinate Systems

Transform Dialog

Example: Editing Records in a Table - How to edit the contents of an existing record using mouse and keyboard.

Example: Draw Lines, Areas and Points - Simple example of using basic mouse moves to add points, lines and areas to a drawing.

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