Db2 Spatial Extender sample program
The Db2 Spatial Extender sample program, runGseDemo, has two purposes. You can use the sample program to become familiar with application programming for Db2 Spatial Extender, and you can use the program to verify the Db2 Spatial Extender installation.
- On UNIX, you can locate
the runGseDemo program in the following path:
where $HOME is the instance owner's home directory.$HOME/sqllib/samples/extenders/spatial
- On Windows®, you can locate the runGseDemo program in the following
path:
where c:\Program Files\IBM\sqllib is the directory in which you installed Db2 Spatial Extender.c:\Program Files\IBM\sqllib\samples\extenders\spatial
The Db2 Spatial Extender runGseDemo sample program makes application programming easier. Using this sample program, you can enable a database for spatial operations and perform spatial analysis on data in that database. This database will contain tables with fictitious information about customers and flood zones. From this information you can experiment with Spatial Extender and determine which customers are at risk of suffering damage from a flood.
- See the steps typically required to create and maintain a spatially-enabled database.
- Understand how to call spatial stored procedures from an application program.
- Cut and paste sample code into your own applications.
Use the following sample program to code tasks for Db2 Spatial Extender. For example,
suppose that you write an application that uses the database interface
to call Db2 Spatial Extender
stored procedures. From the sample program, you can copy code to customize
your application. If you are unfamiliar with the programming steps
for Db2 Spatial Extender, you
can run the sample program, which shows each step in detail. For instructions
on running the sample program, see Related tasks
at the end
of this topic.
The following table describes each step in the sample program. In each step you will perform an action and, in many cases, reverse or undo that action. For example, in the first step you will enable the spatial database and then disable the spatial database. In this way, you will become familiar with many of the Spatial Extender stored procedures.
Steps | Action and description |
---|---|
Enable or disable the spatial database |
|
Create or drop a coordinate system |
|
Create or drop a spatial reference system |
|
Create and populate the spatial tables |
|
Populate the columns |
|
Register or unregister the geocoder |
These steps register and unregister the geocoder named SAMPLEGC and then create a new geocoder, KY_STATE_GC, to use in the sample program. |
Create spatial indexes |
These steps create the spatial grid index for the CUSTOMERS, OFFICES, FLOODZONES, and REGIONS tables. |
Enable automatic geocoding |
|
Perform insert, update, and delete operations on the CUSTOMERS table | These steps demonstrate insert, update,
and delete operations on the LATITUDE, LONGITUDE, STREET, CITY, STATE,
and ZIP columns of the CUSTOMERS table. After the automatic geocoding
is enabled, data that is inserted or updated in these columns is automatically
geocoded into the LOCATION column. This process was enabled in the
previous step.
|
Disable automatic geocoding | These steps disable the automatic invocation
of the geocoder and the spatial index in preparation for the next
step. The next step involves re-geocoding the entire CUSTOMERS table.
Recommendation: If you are loading a large amount of geodata, drop the spatial index before you load the data, and then re-create it after the data is loaded. |
Create a view and register the spatial column in the view | These steps create a view and register its
spatial column.
|
Perform spatial analysis | These steps perform spatial analysis using the spatial predicates and
functions in Db2
SQL. The Db2
query optimizer exploits the spatial index on the spatial columns to improve the query performance
whenever possible.
All of these steps use the gseRunSpatialQueries internal function. |
Export spatial data into shape files | This step shows an example of exporting the HIGHRISKCUSTOMERS view to
shape files. Exporting data from a database format to another file format enables the information to
be used by other tools (such as ArcExplorer for Db2).
|