IBM® Informix® 12.10 Virtual Appliance

Using IBM Informix Spatial Data

The objective of this tutorial is to demonstrate how to use ESQL/C and the Client-side Java™ API to create and use geometry objects.

The client-side Java API consists of Java classes that you can use to work with Geodetic objects from Java client-side programs.

The spatial demonstration requires the Java development kit (JDK). This software component might not be installed on your image, depending on which virtualization environment you are using. To determine whether a Java JDK is installed on your system enter the following command in a terminal window:
javac
If a Java JDK is installed, usage information is displayed. If it is not installed, you receive a command not found message. If a Java JDK is not installed, you must locate and install a copy to run the tutorial.

The following programs are included in the ESQL/C demonstration directory:

Table 1. ESQL/C demonstration programs
Program name Description
load_shapes.ec Uses the SE_GeomFromShape function to create a table with an ST_Geometry column, and then insert examples of all geometry types in ESRI shape format
load_wkb.ec Uses the ST_GeomFromWKB function to create a table with an ST_Geometry column and insert examples of all geometry types in OGIS WKB format
geomfromshape.ec Uses the SE_GeomFromShape function to insert a polygon into a table in ESRI shape format
geomfromwkb.ec Uses the ST_GeomFromWKB function to insert a polygon into a table in OGIS WKB format
asbinary.ec Retrieves data in OGIS WKB format
asshape.ec Retrieves data in ESRI shape format
The Java API demo includes the following three example programs:
Table 2. Java demonstration programs
Program name Description
GeometryToWKT Reads geometry objects from an IBM® Informix® spatial table and converts them into WKT (well-known text) strings. The program first creates a table, inserts geometry data, then queries the table. The output of this program shows the well-known text representation of sample geometries.
GeometryToArray Uses a geometry factory to create new geometries, and then reads coordinate data out of the geometry objects. The program first creates several geometry objects, stores them in a Java vector, then uses two techniques to read coordinate data out of the geometry objects,IfxGeometry.toCoordArray() and IfxGeometry.toPointArray()
CoordRefCreate Creates new coordinate reference objects and inserts them into the SPATIAL_REFERENCES table. The program creates a new CoordRef object, then serializes it as a new SRS row into the SPATIAL_REFERENCES table. The output of this program shows the result of a query to retrieve the new spatial reference systems from the database.
The examples are included with IBM Informix in the following directory:
$INFORMIXDIR/extend/spatial.8.21.xxx/examples
The xxx in the directory name depends upon the version of the IBM Informix Virtual Appliance you are using. To find the version you have installed, change to the $INFORMIXDIR/extend directory and note the directory name that begins with spatial. This information is required for the examples in the rest of this tutorial wherever xxx is displayed.

Both the ESQL/C and the Java API examples assume that you are logged in to the informix account. If you are logged in as user developer, switch to informix account using the su command.

For these examples, the demo_on instance is up and running. To verify that the server is online, type the following in a terminal window:
onstat -
  1. If the server is not online, start it by entering the following command as user informix:
    startDemo
  2. Create a database named geodemodb with logging enabled by entering the following from a command prompt:
    dbaccess <<EOF
    create database geodemodb with log;
    EOF

Building and running the ESQL/C examples

You build the sample programs by running the make utility.

  1. Change to the directory in which the ESQL/C programs reside:
    cd /opt/IBM/informix/extend/spatial.8.21.xxx/examples/esqlc
  2. Build the examples:
    make
  3. Run the examples by entering the example program followed by the database name, geodemodb. For example:
    ./load_shapes geodemodb

Building and running the Java examples

You run the Java examples by first setting the CLASSPATH environment variable and then running the example programs.
  1. Export the CLASSPATH environment variable:
    export CLASSPATH=/opt/IBM/informix/extend/spatial.8.21.xxx/spatial.jar:
           $CLASSPATH
  2. Change to the directory in which the Java example programs reside:
    cd $INFORMIXDIR/extend/spatial.8.21.xxx/examples/java
  3. Build the examples:
       javac -Xlint:unchecked *.java
  4. Run the examples by using the following syntax:
      java program_name "connection_URL" 

    In the example, program_name is the name of the example program to run and connection_URL specifies the JDBC driver, the server name and port number, the database to use, and the user name and password for the database. For example, the following demonstrates the command syntax for VMware environments:

      java CoordRefCreate "jdbc:informix-sqli://informixva:9088/ 
          geodemodb:informixserver=demo_on;user=informix;password=informix"
    For cloud environments, specify the IP address or the public DNS name of your IBM Informix Virtual Appliance instance instead of informixva, and substitute the password that you selected when the instance was provisioned.

Summary

In this tutorial, you completed the following steps:
  • Examine samples of the Java and ESQL/C demonstration programs
  • Create a new database with logging enabled
  • Compile and run both Java and ESQL/C demonstration programs
This tutorial provides only a brief overview of using Informix spatial data. For more information, see the IBM Informix Spatial Data User's Guide.


Send feedback | Examples exchange | Troubleshooting

For the release notes, see the Release Notes page.
timestamp Release date: March 2013