Map Room Home page  
written by Nigel James
 
Contents
 
   
MAPINFO How to...  
No. 15: Extracting object coordinates and saving them in a table  
(References to tables, folders etc., are not applicable outside the Map Room, so if you are located elsewhere, you should substitute your own)  
   

This explains how to extract the coordinates of the objects (centroids) in a table and save them. If you have carried out normal geocoding (see MapInfo How to No. 6 Geocoding your data) or manual geocoding (see MapInfo How to No. 10 Manual geocoding), then coordinates will have been created for the objects in your table, but they will not be displayed. This How to guide explains the procedure for creating columns for the coordinates and adding them to your table.

Note: MapInfo extracts Lon/Lat coordinates by default, even if your table is in a different projection. An additional step is required if your table is not in Lon/Lat (OS National Grid or Non-earth, for example) and this is explained in this guide.

 
   
 
1. Start MapInfo.  
 
2. Open your table. This should be a normal mappable table (i.e: with objects). Close any other tables which are open (this avoids restructuring the wrong table by mistake!)  
 
3. You will be changing the structure of your table, so to be safe, save a backup copy of the table (Open the File menu and click Save Copy As..). Save the copy under a different name.  
   
4. Open the Table menu and click Maintenance, then Table Structure. You will now see the Modify Table Structure dialog. If you cannot modify the structure it is because you are working on an original file and MapInfo will not allow you to change it. Make a copy first and work on the copy instead.  
   
5. You will need two new fields for the coordinates. You can call them Lat and Lon, or X and Y - it's up to you but remember that they must be single words, or multiple words joined with an underscore, e.g: Lat_value, and cannot strat with a number or non-alphabetic chararacter.  
   
6. Create the first field by clicking the Add Field button. Enter the name and set its type to either float or decimal (decimal uses less strorage but you have to specify the number of places, with float it is automatic)  
   
7. Click Add Field again to add the second coordinate field with the same type.  
   
8. Click OK to confirm the changes and save the table - don't be surprised when it disappears!  
   
9. Re-open the table again. When it appears, open the Window menu and click New Browser Window to view the data as well.  
   
10. You will now see two new columns with 0 values. These will be replaced with the coordinate values in the next step.  
   
11. Important: If your table is in a Lon/Lat projection you can skip steps 12 to 14, otherwise proceed as follows:  
   
12. MapInfo will by default return the coordinates in lon/lat, even though your table may be in a different projection (e.g: British National Grid), and the results will be most bizarre if you are using a non-earth projection! The reason is that although your table is in OS National Grid for example, the mapper window will calculate the values in degrees, unless you tell it otherwise, which can be done using a simple MapBasic command (don't worry if you have never used MapBasic - it's very simple and you don't need to understand it!)  
   

13. Open the Options menu and click Show MapBasic Window. This will now appear at the bottom of the screen. Click in the MapBasic window and type:

set coordsys table <yourtablename>


where <yourtablename> is the name of the table. For example, if your table was called "newplaces.tab" then the line would read: set coordsys table newplaces (note: only the table name is used, not the .tab extension).

 
   
14. Press <Enter> to execute the command. Nothing appears to change, but the mapper window is now in the same projection as the table itself. You can now proceed to extract the values.  
   
15. The two values required are the X and Y coordinates of each object, and MapInfo has functions to do this, called CentroidX(obj) and CentroidY(Obj).  
   
16. Make sure that mapper or browser window is the active window (blue title bar), open the Table menu and click Update Column. In the Update Column dialog, the Table to Update should be your table, and the Column to Update should the one which wil have the X coordinate (i.e:longitude, easting etc). The table name in Get Value from Table should the same as inTable to Update.  
   
17. In the Value box type: CentroidX(obj) and click OK. The X coordinate column will now show the X coordinates.  
   
18. Repeat the process, this time selecting the Y coordinate column in Column to Update and in the Value box type: CentroidY(obj) and click OK to fill the Y coordinate column with values.  
   
19. Remember to save your table after extracting the values.  
   
This is a brief and specific guide to this topic, for more general information, see: MapInfo l - an easy guide for new users  
Nigel James
Bodleian Library 2001
 
Bodleian Library Map Room