Over the coming weeks, I'll write a #series of articles about the #SQL improvements we have made in MapInfo Pro v2019. This will, of course, look at the Select statement but I'll also dive into the other improvements.
It's not all about the SQL syntax improvements, in this article, we'll dive into the new Select By Location feature.
The new Select By Location feature
Some, or maybe even many, users might struggle a bit building a spatial join using the SQL Window and the classic SQL Select dialog. It can be difficult to get it right, especially if you also are new to writing SQL in general.
That why we created a dedicated dialog to help you build your spatial joins. With this dialog, you don't need to worry about the SQL syntax, the dialog will create this for you. The dialog will also guide you to pick the right spatial operator, that is the way to compare the two tables spatially.
You can find
Select By Location in the new
SQL dropdown on the
TABLE,
MAP and
SPATIAL tabs. The shortcut key for the feature is Ctrl+Shift+X. If you use it a lot, you can also add it to your Map Mini Toolbar.

When you activate Select By Location, this dialog will be shown
As you start selecting tables from the two dropdown lists, the Relation dropdown will also change to match the most common object types in the two tables. It will preselect the best match depending on the object types in the two tables and the data bounds of the objects in the tables. This will help you select the best spatial relation and help you avoid selecting a relation where you want the points in one table to contain the polygons in another table.

You can always change the spatial relation if you want a different one. The dialog will not prevent you from selecting the specific spatial relation that you want to use. But it will preselect the spatial relation that it thinks would work best.
Within a distance
The dialog will also give you access to a spatial relation that hasn't been supported in earlier versions of MapInfo Pro: Within a Distance. This will make it possible for you to find relations between objects that don't touch each other but just are nearby.
When you use the Within a Distance spatial relation, you will need to specify the distance used, the distance unit and also the Distance Calculation Method that can be Spherical or Cartesian. Spherical is used for Lat/Long data and Cartesian is used for projected data, which is data based on for example a UTM coordinate system.

Notice that this is only possible in MapInfo Pro v2019. Earlier you could only build a join based on a spatial operator or the equal sign. And you would have to use existing columns or the object on both sides of the comparison.
Using a Selection
If you have selected one or multiple records before accessing the Select By Location dialog, the Compared to objects in dropdown will be prefilled with the selection. The dialog assumes that you want to use the selected objects to find objects in another table.
All you have to do now is to select the table you want to "compare" to the selected objects and the spatial relation.

Notice that this is only possible in MapInfo Pro v2019. In earlier versions of MapInfo Pro, it wasn't possible to join a temporary table to another table.
Viewing the result
When you click on the OK button MapInfo Pro will build the SQL Select statement and run it. The result will get selected into the current Selection and highlighted on the map.
If you have the MapBasic window open, you can also see the SQL Select statement here. You can modify the statement and rerun the statement directly from the MapBasic window. In the example above do notice that the join is based on a temporary query, Query1.
You can, however, also access the query in the new SQL Window. You can find the Select statement in the Scripts dropdown at the top of the window. The statement will be named using the two tables and the spatial relation used. You can select it from the dropdown, and then edit and rerun it from the SQL Window.
Joins based on the same base table is not possible
You need to have two base tables open for the Select By Location control to get enabled. It will not allow you to build a join on the same table or queries based on the same base table. This might change in the future. If you think it would be really valuable to be able to do this, let us know, for example via a comment to this post.
If you try to build a join based on the same table or queries of the same table, the dialog will ask you to build a different join.
I hope you can see the value of this new feature. Do let us know how you are using it and also give us some feedback if there are things you think could work even better.
Stay tuned for the next article on the SQL improvements in MapInfo Pro v2019!
------------------------------
Peter Horsbøll Møller
Distinguished Engineer
Pitney Bowes Software & Data
------------------------------