Example: Add a Spatial Index to a Table

This example shows how to add a spatial index using a geom field in a table.  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.  




We open the Roads Table table and 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.




We click on <new index> to create a new index.




In the controls that open up we first name 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.    We achoose an rtree type of index from the list of available index types.




Having made those choices we press Add.   We now specify which field will be used for the index.




The Field box is loaded with the names of fields we can use.  We choose the Geom field.




We press Add.   tech_angus_sm.png


Tech Tip:  The number one mistake made when creating an index is to forget to press Add in this step and instead just pressing OK.   Until we add the Geom field to the Geom_x index we have just created, the index cannot do anything, because we have not told it which field it should index.  




After double-checking our work we press OK to close the Schema dialog.




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.


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.


See Also



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.