|
|
|
|
|
|
|
Empress Technical News – May 2009 Database Spatial Search Index – Fast Geographical Data Retrieval
IntroductionEmpress Ultra Embedded V10.20 offers many additional features to application developers. One of those features is a Spatial Search Index capability for fast geographical data retrieval. Empress Spatial IndexEmpress Ultra Embedded V10.20 Spatial Search Index capability empowers application developers to implement an efficient search using spatial access methods for geographic location data. The spatial index capability is developed as an additional set of C calls that are used in conjunction with Empress C/C++ Kernel Level API (mr Routines) and a set of SQL commands. The Empress spatial Index technology is based on an R* tree index. R* tree is a variant of R tree for indexing spatial information. are tree data structures similar to B-trees (already in use with Empress indexes) but are used for spatial access methods, i.e. for indexing multi-dimensional information for example, the (X, Y) coordinates of geographical data. A common real-world usage for an R-tree might be: " Find all points of interest within 5 kilometers of my current location" . Empress Spatial Index C APIThe Empress spatial search capability uses the following set of C API calls that should be used in conjunction with Empress C/C++ Kernel Level mr Routines: ms_rstree_open Example Using Spatial SearchIn the following source code example rstree_select.c searches for all the restaurants in the specified rectangle given by its geographical coordinates. Restaurants, stored as points of interest, have the characteristics such as, for example: ID: 4 R* tree index expects geographical parameters, such as longitude and latitude, defined as integers or float numbers. Hence, the values expressed in degrees, minutes and seconds need to be converted. For example: The latitude 43 degrees 49 minutes 09.51 seconds North is converted to: 43 * 360000 + 49 * 6000 + 9.51*100 = 15774951 The following tables give an idea of how distances in meters relates to degrees, minutes and seconds. The figures are taken from the following source: Robinson, Arthur H. et al. of Cartography, 5th ed. New York: John Wiley & Sons, 1984. (pp 64-66, Appendix B) Latitude:
Example Source CodeIn the example below, integers were used as the coordinates. Float values could have been used as well. When dealing with the circular search in the example the radius of 1500 represents approximately 450 meters. The source code example is as follows: #include
<
mscc.h>
***/ (!mrclose (poi_tabdesc)) fprintf
(stderr, " Unable to close the
table\n"
)
Example – Preparing Data Thefollowing sequence of steps will show how to prepare data in the database for running the example. The latitude and longitude values were real values derived from Google Earth. To create the database testdb it doesn’t exist) run: empmkdb testdb To create the table poi that contains ‘points of interest’ locations and insert records with some restaurants information, run: empbatch testdb sql_commands where sql_commands file looks as follows: CREATE TABLE poi ( INSERT INTO poi VALUES ( 6," Tandoori Queen" , Example– Compiling the C Program To compile an example: go to the directory where the example is copied and run the Empress compiler utility empcc command: empcc -o rstree_select rstree_select.c The executable file be created in the same directory. Example – Running the Program Using a Rectangle When rstree_select gets executed it will display the following result. Points of Interest inside defined rectangle id coordinate coordinate Points ofinterest (i.e. restaurants) that satisfy the criteria for the above search are shown in the Fig 1. The letter A in the red balloon on the map below is the starting point. The numbers in the blue balloons on the map below correspond to the “id” of the “Points of Interest”. Fig 1: Spatial search for all points of interest inside the defined rectangle Example – Running the Program Using a Circle Insteadof using rectangle spatial search: ms_rstree_point_search_in_rectangle (rshandle, ( Pointsof Interest inside defined circle 1 Ten23 15773195 Points of interest (i.e. restaurants) that satisfy the criteria for the above search are shown in the Fig 2. The letter A in the red balloon on the map below is the starting point. The numbers in the blue balloons on the map below correspond to the “id” of the “Points of Interest”. Fig 2: Spatial search for all points of interest inside the defined circle The rectangle produced 3 points ofinterest while the circle produced 4 points of interest. And FurthermoreEmpress Spatial index search functionality can be used with other regular Empress query search conditions. In addition, it can be used with special Empress features such as Empress text search and Empress Shiborikomi search. Empress
Software Inc. |
Company |
Products |
Services |
Partners |
Media |
|
USA: 301-220-1919 Canada
& International: 905-513-8888 |