Given a map of a city with a drawing layer containing the footprints of buildings as polygonal areas, and a second drawing layer containing districts in the city as polygonal areas, we use the Join dialog to add a new attribute field to each building giving the district in which it is located.
We consider first the simple case where district boundaries always fall between buildings, so buildings are always only in one district. Next, we deal with the case where buildings can straddle district boundaries, so parts of the same building can be in different districts. In that case we use the Transform pane to quickly build centroids for building footprints, and then we use the centroids to guide the spatial join.
Consider the map shown above, which has two vector drawings as layers. The Buildings drawing shows building footprints as polygonal areas in a small city. The building footprints are colored in shades of blue. The Districts drawing shows two districts in the city, also as polygonal areas. One of the districts is colored a pale violet and the other is colored a pale green
We can see at a glance that the boundary between the East and West districts falls on what is likely a road, so the boundary falls between any building footprints. No building straddles the boundary such that part of the building is in one district and some other part of the building is in the other district.
Opening the table for the Buildings drawing we see that other than the standard mfd_id field and the geometry field it has no attribute fields. Opening the table for the Districts drawing we see that in addition to the identity field and the geometry field, it has an attribute field called Name, of type nvarchar (a text field), that gives the name of each district, either East or West.
We would like to spatially join the Districts drawing with the Buildings drawing, to add a new attribute field to the buildings table that gives the name of the district in which each building is located.
With the focus on the Buildings tab in the open map window, we choose Edit - Join to launch the Join dialog.
In the Join dialog, in the upper right corner we choose the Districts drawing as the joined drawing.
For the join criterion, we choose contained in. We want to match all buildings contained in a district.
We press the Add button to add a new field, taken from the joined drawing, to the Buildings drawing.
The pull down menu lists available fields from the Districts drawing. We choose the Name field.
A new row appears in provisional blue color, for the new field to be added to the Buildings drawing. We double-click into the name for the field on the left side of the dialog (the name to use when creating the field in the Buildings drawing), and we change the default name to District Name. We can use whatever name we like, but it is wise to use a name for an attribute field that reminds us what that field contains.
For the transfer method, we leave copy, the default choice. That simply copies the name of the district in which each building is located into the new District Name field.
Instantly, a new field, District Name, appears in the Buildings Table. Since the new field was joined in from a field of type nvarchar in the joined drawing's table, the new District Name field also uses the data type nvarchar. The new field is populated with the name of the district in which each building is located.
The workflow given above works perfectly in cases where a district boundary does not cut through a building footprint. That is a common situation in city planning, where the boundaries of various city districts are often marked using the center lines of roads. But it is also a common situation that a district boundary may cut through a building footprint, so that part of the same building is in one district while another part of the building is in a different district.
Consider the situation shown above, where we use a new districts vector drawing, called Four Districts, that has four polygonal areas for districts. The boundaries between districts clearly cut through many building footprints.
Opening the attribute table for the Four Districts drawing, we see that each district is named based on which compass quadrant it represents.
If we want to assign one, and only one, district to each building footprint, we need to use some rule to say in which district a building that straddles more than one district is located. If we have the address of each building, one rule used in some cities is to choose the district in which the main entrance of the building is located. If we do not have the location of the main entrance, we must use some other proxy.
For this example, we will use the inner centroid of the building. The inner centroid is the circle center of the building that is adjusted so if centroid computed using a simple algorithm falls outside the building, for example, in the case of a building with a "C" shape, the center automatically is nudged to fall within the building's footprint. We can do that using the Center : inner (area) transform operation.
With the focus on the opened map window, in the Transform pane we choose the Buildings layer. We then choose the Geom field. Double-click the Center template to launch it.
In the Center template we choose inner (area) as the Center option.
For the Result destination, we choose New Field and then we enter Centroids as the name of the new geometry field to create. For the name of the New Drawing that will visualize that new geometry field, we enter Building Centroids. We can choose whatever names we like for the names of the new field and the new drawing, but it is wise to choose names that at a glance remind us of what they contain.
To see a preview of what the template will do, press Preview. We do not have to do a preview before apply a transform template, but a quick preview to see what will happen is often a great way to avoid errors.
A preview layer in blue preview color appears above all other layers in the map, showing the points that will be created. A blue preview caption bar appears at the top of the window, giving the name of the template that is being previewed. We can right-click on the caption bar for a context menu of commands to control the preview.
If we would like to see the preview without other layers, we can double-click the layer tabs of any layers to turn them off. For example, in the illustration above we have double-clicked the Buildings layer to turn it off.
If we like what we see in the preview, we press Transform to apply the transform template.
Immediately, a new geometry field called Centroids appears in the Buildings Table. The new Centroids field contains point geometry that for each building record is located at the inner centroid of that building's footprint.
A new drawing called Building Centroids appears in the Project pane. We drag and drop the new Buildings Centroid drawing into the map.
Styling the points in the Buildings Centroids layer as bright green dots, we can see that each centroid point falls inside the footprint of the building for which it was created. Because points are dimensionless, we can expect that each centroid point will fall within only one district. Even if it seems to fall on a boundary, a centroid will be a few microns to one side or the other of the boundary line.
Note that since we created the centroids points as another geometry field in the same Buildings table as the building footprint areas, each centroid is in the same record as the building area from which it was generated. Doing a spatial join against the centroids is doing a spatial join for the same records as the building footprints, just using a different geometry field.
With the focus on the Buildings Centroids tab in the open map window, we choose Edit - Join to launch the Join dialog.
In the Join dialog, in the upper right corner we choose the Four Districts drawing as the joined drawing. The upper left, target drawing is the Building Centroids drawing, but that is the same table as the Buildings table. We can see the fields for the table in the pane below, including both of the geometry fields, the Geom field and the Centroids field.
For the join criterion, we again choose contained in. We want to match all centroids contained in a district.
Press the Add button to add a new field, taken from the joined drawing, to the Buildings drawing.
A new row appears in provisional blue color, for the new field to be added to the Buildings drawing. We double-click into the name for the field on the left side of the dialog (the name to use when creating the field in the Buildings drawing), and we change the default name to District. We can use whatever name we like, but it is wise to use a name for an attribute field that reminds us what that field contains.
For the transfer method, we leave copy, the default choice. That simply copies the name of the district in which each building is located into the new District field.
Immediately, a new District field appears in the Buildings Table, populated with the name of the district in which each centroid is located.
Taking chances - We may feel certain that districts in cities are drawn so the boundaries between districts never cut through any building, but "real life" may surprise us with a building that has been built with part of the building extending into a different district. In that case, using contained in as a join criterion will fail for that building, because it is not contained in either of the districts it straddles. We could use touching, but then the Join operation would pull in all of the districts that building touches, at least two of them if it straddles a boundary. Using copy as the aggregation / transfer method will simply pick one of them, which might not be the majority district, if just a tiny portion of the building crosses over into a neighboring district. In such cases it is safer to use centroids, since at least in that case we will know that the district picked will more likely be where much of the building is located.
Getting a centroid inside each building footprint - Using Center with the inner (area) option may seem unnecessary, but there are surprisingly many building footprints in real life where plotting a centroid based on an enclosing circle or by center of weight will place the centroid point outside the building footprint.
In the example below we have created centroids for the example Buildings layer using the Center : circle option, which simply plots a centroid point at the center of the minimum enclosing circle.
The Circle Centroids points are shown as magenta points. We can see there are several instances where the magenta centroid falls outside the building footprint, such as the building marked with a magenta arrow in the illustration above. This is a "real life" example, as the building footprints are taken from the OpenStreetMap data set of building footprints for Monaco.
See the Join Videos list of videos showing how to use the Join dialog.
Editing and Combining Data
Editable Results Tables