Example: Add a Spatial Index to a Table

This example shows how to add a spatial index to a geometry field in a table.  We use a field of type geom, the native Manifold geometry data type.  As is traditional in Manifold, we have named the geometry field Geom so in the schema and other places where field names appear we can immediately know it as a geometry field that contains type geom.

 

A typical use of an index is to provide a spatial index on a geom field in a table, so the geom data can be visualized in a drawing.  

 

In most cases, Manifold will do that for us automatically.     We can create a drawing from a table and Manifold will automatically create a spatial index on the geom field we choose to use, so we do not normally need to do this manually as shown in this example.   It is still a useful thing to know to better understand how geometry from tables is used in drawings, or for creating spatial indexes within tables when we will use the data programmatically.  

 

The data set we use consists of a table called Roads Table that contains geom data for lines stored in a Geom field.  Each line represents a road.   The table includes some attribute fields.  

 

eg_add_spatialx01_01.png

 

We open the Roads Table table.  With the focus on the Roads Table window we choose Edit-Schema.  The dialog opens with a display of the schema of the Roads Table table.

 

eg_add_spatialx01_02.png

 

btn_schema_add.png Press the Add command button.

 

eg_add_spatialx01_03.png

 

Choose Index in the drop down menu.

 

eg_add_spatialx01_04.png

 

In the Index dialog we provide a name for the new index.   We will name it Geom_x using the recommended Manifold style of naming indexes after the field they index with a _x appended.   From the drop down list of available index types, we choose spatial index for geometry (rtree).

 

The dialog automatically reconfigures to add the index type selected.

 

eg_add_spatialx01_05.png

 

The Geometry box is loaded with the names of geometry fields we can use.  In this table, there is only one geometry field, called Geom, so that is the field which appears by default in the Geometry box.   We press OK.

 

eg_add_spatialx01_06.png

 

The new spatial index appears in the schema in provisional, bluish color, indicating it has not yet been added to the table.   To add the new spatial index to the table and close the dialog, we press Save Changes.

 

eg_add_spatialx01_07.png

 

There is no visible change in the table, since the spatial index is not used in the table.    However, we can now create a drawing based on the table, using the Geom field for geometry and the Geom_x spatial index.

 

eg_add_spatialx01_08.png

 

Now that we have a spatial index on the Geom field we can now open up the Roads drawing that displays data taken from the Geom field.  This particular data set shows roads created during the Roman empire.

Notes

The Roman roads network which appears in this topic was downloaded from the Harvard University Digital Atlas of Roman and Medieval Civilizations (DARMC) data availability web page, cited as DARMC Scholarly Data Series 2013-5: M McCormick et al. 2013 - Roman Road Network (version 2008).   The data set provides a digitized form of roads shown in the Barrington Atlas.  

 

eg_add_spatialx01_09.png

 

Seen above is a section of the Appian Way, one of the most important Roman roads leading out from Rome.

See Also

Tables

 

Adding an Index to a Table

 

Example: Add a UUID-based Index to a Table - Create a new computed field that is filled with UUID values on creation and then create an index on that field.   This technique creates an indexed field that has guaranteed unique values for all records and thus the indexed field and record values may be used in other projects.

 

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.