SQL and MapInfo macro language
 

Below are the results of the queries and thematic mapping process to plot the changes in population of school-age children.  The following scripts detail precisely the "structured query language" (SQL) commands that were necessary to create the combined thematic map, indicating areas where the population of children are increasing and decreasing.

The left column details the "pseudo-code" in terms of what is required.  The right column reproduces the exact MapInfo commands from the MapBasic window.  Our instructor advised that, for lengthy operations, we "cut-and-paste" the MapBasic window text to save as a MapBasic (.MBX) program.  While an alternative is to save the queries as "query files" or even save the workspace, saving the scripts as text files for MapBasic allows one to recycle useful query routines.  In other words, the scripts below can be edited for other data by simply changing the file names, the data column headings, and the algebra, thereby eliminating "re-inventing the wheel".
 
 
REQUIRED OPERATIONS MAPBASIC SCRIPT
   
Open base table containing ALL data Open Table "C:\WINDOWS\DESKTOP\MapInfo\Orleans\Orl_school_study1.TAB"
1st SQL:  choose only census tracts where the child population has increased (ie: 1996 population is greater than 1991 population) select * from Orl_school_study1 where Child_96 > Child_91 into Selection
Save the resulting query as "Child_growth.TAB" Commit Table Query1 As "C:\WINDOWS\DESKTOP\MapInfo\Orleans\Child_growth.TAB"
2nd SQL:  choose only census tracts where the child population has decreased (ie: 1996 population is less than 1991 population) select * from Orl_school_study1 where Child_96 < Child_91 into Selection
Save the resulting query as "Child_decline.TAB" Commit Table Query1 As "C:\WINDOWS\DESKTOP\MapInfo\Orleans\Child_decline.TAB"
After creating a number of queries for later thematic work, I usually close all open tables and start fresh.  I tend to do my thematic work separate from my database operations. Close All Interactive
Open Table "C:\WINDOWS\DESKTOP\MapInfo\Orleans\Orl_school_study1.TAB"
Open Table "C:\WINDOWS\DESKTOP\MapInfo\Orleans\Child_growth.TAB"
This step occurs automatically -- since the 2 maps are geo-coded correctly (UTM/NAD83 - zone9), the 2nd layer is automatically added to the open mapper, instead of to a 2nd mapper. Add Map Auto Layer Child_growth3
as above "...growth.TAB" Open Table "C:\WINDOWS\DESKTOP\MapInfo\Orleans\Child_decline3.TAB
as above "...growth.TAB" Add Map Auto Layer Child_decline3
1st thematic map; theme is based on an "expression" (ie: "[child_96 - child_91] / 5") to plot the annual change in number of children.  I used the "expression" option, rather than adding a column to the database, to conserve disk space. shade window 10277744 2 with (Child_96 - Child_91) / 5 density 1:4 color 16711680
2nd thematic map: as above, "expression" used but MapInfo does not permit the plotting of negative numbers, so the algebraic expression is multiplied by -1 (see * below). shade window 10277744 1 with -1 * (Child_96 - Child_91) / 5 density 1:4 color 255

* Plotting Negative Numbers:

When the thematic map from "child_decline.TAB" was attempted without the -1 in the algebra, MapInfo did indeed proceed to completion, but the map was blank.  Examining the thematic info revealed that each dot was representing -0.04 children!

Unable to process negative values, and being presented with only negative values, MapInfo defaulted to a "dot value" that was outside the range of actuals.  This was probably done in order to complete the macro so as not to create a run-time error in the .EXE file.  When I attempted to <modify> the thematic map by replacing "-0.04" with "-1", MapInfo returned an error message.  So, while it seems to create a negative number within its own macro routine, it does not permit operator entry of a negative number.  The value of "-0.04" was probably similar to entry of, say, "999" as an "end-of-file" indicator.

Would ArcView have the intuitive ability to thematically map negative numbers?  That is, to recognize that, when a value range is all negative, the values should be automatically made positive, in order to produce a meaningful thematic map (ie: a map of decline, rather than increase).  This will be investigated.


Your comments on this page are welcome!

Back to Contents