Spatial Join Example: Copy Terrain Heights to Points

Spatial joins between  images and drawings use spatial relationships between the locations of pixels in the source, joined image and the geometry of objects in the target, original drawing to join data into the original drawing.    The Edit - Join dialog provides spatial joins between images and drawings that are layers in maps.    This allows transferring values from images, such as terrain elevation rasters, to objects in drawing layers, packaged within an easy to use dialog.  Spatial joins between images and drawings work between layers in the same map.  Layers can be in different data sources.

 

Add fields using a spatial join:

 

  1. With the focus on a drawing layer in an open map window, choose Edit - Join.

  2. In the upper right box choose the joined image in the map from which fields will be joined.

  3. In the second row of boxes, choose the geometry and tile fields to use and the spatial method, such as contains or contained in.

  4. Click the Add button to choose a field in the joined images's table that will provide data for a new field in the original table.

  5. Double-click a cell to edit the field name (new fields) or to choose a different source field (joined table) or to choose a different transfer method.

  6. Press Join.

Example

An image to drawing spatial join:  Given a raster terrain image that shows terrain elevations, and a drawing of points, we transfer the heights in the terrain elevation raster at the location of each point into a new Height attribute for each point in the drawing.  We will use a map similar to that used in the Example: Transfer DEM Terrain Heights to Areas in a Drawing  topic.  This example is directly analogous to that example,  but instead of using ESRI-style overlays we do the same thing more easily using the Join dialog.

 

See the video version of this example in the Join Dialog Part 3 - Raster to Vector Joins video.  

 

 

Our map includes an image layer called Terrain that shows terrain elevations in a single channel image.   It also includes a drawing layer called Points that shows the location of various points.

 

 

The Points table has no attributes for the points.  We will add a Height field that gives the height of each point, taken from the underlying Terrain elevation.

 

With the focus on the Points layer in the opened map window, we choose Edit - Join from the main menu.

 

 

We choose Terrain as the joined image.  The only option we have for a method is contains.  For each object in the Points drawing, the join finds all pixels that object contains.  In the case of a point object that will be only one pixel, but in the case of area objects an area might contain many pixels.

 

We press the Add button to add a new field.

 

 

The only choice we have of a source "field" in the joined image is Channel 0, the only data channel in the image and the channel that contains height values for each pixel.   There is no Fields choice because there is only one "field," Channel 0, in the raster.   

 

If the image had more than one channel, all of the channels would appear in the pull down menu, as well as the Fields choice.

 

 

Adding the field, we double-click into the name to change Channel 0  to Height.   By default, the copy method is sample, meaning taking the first value found in any pixels the object contains.   That is equivalent to copy for point objects, since a point "contains" only one pixel in the terrain.

 

 

Press Join.

 

 

A new Height field is added to the Points Table.  The new Height field is filled with the value of the height for that location in the terrain, taken from the Channel 0 value of the image for that pixel.

Notes

Terminology - The original table also may be called the target table, and the table providing data also may be called the source table.

 

Quick reference - With the Join dialog open, press F1 to open a quick reference guide in a browser window.

 

Guessing the key field - When we launch the dialog with an original field and when we choose a joined field, the dialog will try to guess what fields we might want to use as key fields and will load those first by default.  If it guesses wrong, we can choose the field we want.   For the original table, the dialog tries to use a field (other than mfd_id) that has a BTREE / BTREENULL index, with a data type preference for numbers, then text, then everything else, and a name preference for field names with id in them, such as ... id or ..._id, then ...id and then everything else. For the joined table, the dialog uses similar logic, but first tries to use a field with the same name as in the original table.

 

Added fields are static - Added fields are static, that is, if data in the joined table changes the fields in the original table that received data in the Join operation from the joined table will not automatically be updated.  We can easily update the table any time we want using a saved update query.  

 

Spatial joins are automatically parallel - Joining data between drawings uses parallel GeomOverlay function variants.  Joins from images to drawings are parallelized through a nested SELECT using THREADS.

 

Videos

See the Join Videos list of videos showing how to use the Join dialog.

See Also

Maps

 

Tables

 

Queries

 

Drawings

 

Images

 

Editing and Combining Data

 

Join

 

Join Videos

 

Join Examples

 

Command Window

 

JOIN Statements

 

Editable Results Tables