MapInfo Pro

 View Only

MapInfo Monday: How can I control the Drawing Order of a Layer

  • 1.  MapInfo Monday: How can I control the Drawing Order of a Layer

    Employee
    Posted 08-22-2022 04:35
    Happy #MapInfoMonday!

    In this post, I will give you some examples of how you can control the drawing order​ of records in a layer.

    Typically, you do not have any control over what order objects in a layer are rendered. This is controlled by the spatial index. When MapInfo Pro  When MapInfo Pro is about to render a layer to be displayed in a map window, it will request the objects to render by querying the spatial index. The spatial index makes it faster to determine which objects are within the extent of the map and therefore need to be rendered. The spatial index is built from the MBR (Minimum Bounding Rectangles) of the objects in the table and stored in the form of an R-tree spatial index.

    This means that there currently is no way to control the order in which objects are rendered to the screen for a layer. This is handled by the spatial index.

    But there are some workarounds that we will inspect next. Let's start with one example where controlling the draw order can be beneficial.

    A fast-food chain is trying to understand the catchment area of their shops in Bucharest. They already have a layer with all their restaurants.

    To understand the catchment area for the restaurants, they decide to create drivetime zones around all the restaurants. They create a 5-minute and a 10-minute drivetime zone around each store.

    But by just looking at the resulting map, they realize that something is off. For some of the stores, they can't see the 5-minute drivetime zones drawn with a lighter orange color. This is the typical problem you can run into with the drawing order for a layer containing many overlapping polygons.

    Use a Sorted Query as a Layer

    One workaround is to use a query where you sort the records in the opposite order as you would like them to be rendered. In the example above, we want the larger 10-minute drivetime zones to be drawn first and the smaller 5-minute zones to be rendered last and so appear on top of the larger zones. In order to do so, we need to order the query so that the 10-minute drivetime zones are at the top of the query result.

    There are multiple ways to create a sorted query. You can build a SQL Select statement using the SQL Select dialog or the SQL Window. Or you can simply order the table from the Browser window. We will use the later method.

    From a browser window containing the drivetime zones, right-click on the column you want to order by. In our example, we right-click on the column "Value" and select Sort Descending to get in sorted with the larger values at the top.

    From the Table tab, select Add to Map in the Sort and Filter group. This will bring up the dialog Create Query that allows you to convert the sorted and/or filtered content of a browser window into a named query and add this to a new or existing map window.

    I give my query a name - use underscores instead of spaces and dashes, check the option Add this query as a layer to and select the existing map to add the layer to.

    Below you can see the resulting map where the smaller zones now are rendered on top of the larger zones.

    Use Layer Filter

    Another option that will work fine in some situations is to use a Layer Filter to control which records from a layer are rendered. This will mean that will need to add your layer multiple times as the order is controlled by these layers. If you have too many groups in order to control the draw order, it gets too complicated. Layer Filter was added to MapInfo Pro v2021.

    In this example, we just need two layers that work quite well.

    Add the table with the drivetime zones again to the map so that you have this layer twice.

    Double-click on the first of these two layers and in the Layer Properties dialog go to the Filter tab and click the Expression button under Layer Filter.

    In this example, I set the Layer Filter Expression for the top layer to value = 5 and for the bottom layer to value = 10. In this way, the top layer will only render the 5-minute drivetime zones and the bottom layer will render the larger 10-minute drivetime zones.

    The resulting map is similar to the one above where we used the sorted query. In the Layer List, I renamed these two layers to have a more friendly layer name.

    There are some additional benefits to this method. As I now have a layer for each group of drivetime zones, I can now control the visibility of the drivetime zones independently and show only the small zones or only the larger zones. And I have all the other benefits of separated layers such as global layer styles and different label settings too.

    Before I end this article, I want to show you the difference between the two maps; one where the spatial index controls the draw order and the other where I take control over the draw order through one of the examples above.

    Do you often have a situation where your layer contains objects that overlap?


    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------