The following section explains how to install the Geospatial module on an informix database / instance.

1 Installation

From version 12.10 of IDS onwards, the BTS module is automatically integrated into databases and it does not require further registration. To setup the BTS on a database, simply connect to a database where you need spatial options and execute:

Copy
EXECUTE FUNCTION sysbldprepare ('spatial.*', 'create')

For versions after 11.70, additional steps are required.

1.1 Download the geospatial module and put it in a directory on the server

Download the geospatial module from the IBM page, or check if it already comes with the distribution itself in the $INFORMIXDIR/extend/spatial.8.21.FC5 directory (depending on the version the directory will vary). The version used in this document is Spatial_Datablade_8.21.xC3_CZ27WEN.tar.

  1. Create a directory on the database server /tmp/BLADE
  2. Copy the file Spatial_Datablade_8.21.xC3_CZ27WEN.tar to the /tmp/BLADE directory
  3. Unzip the file Spatial_Datablade_8.21.xC3_CZ27WEN.tar in /tmp/BLADE

1.2 Install the geospatial module

To install it we follow the following steps:

  1. We connect via console to the database server, we connect with the informix user.
  2. We move to the /tmp/BLADE directory.
  3. We run the .bin installer depending on the platform on which we are installing it, in our example it is a 64 bit linux, so we choose spatial.8.21.FC3.LINUX86_64.bin
    Copy
    cd /tmp/BLADE
    ./spatial.8.21.FC3.LINUX86_64.bin
  4. The installer will ask us to confirm the directory where informix is installed in our example /home/informix.
  5. The installer will ask us to confirm the license.
  6. The installer shows us an advance of the installation and in the end it will tell us that the installation was successful.

2 Test spatial module

To verify that it is installed correctly, the following SELECT can be performed:

Copy
SELECT * FROM SDE.SPATIAL_REFERENCES

You should return a result similar to the following:

Copy
srid         0
description  Unspecified datum for use with unprojected lat/lon coords
auth_name
auth_srid
falsex       -180,000000000
falsey       -90,0000000000
xyunits      5965232,000000
falsez       -50000,0000000
zunits       1000,000000000
falsem       -1000,00000000
munits       1000,000000000
srtext       UNKNOWN

3 Troubleshooting

In the $INFORMIXDIR/extend/spatial.8.21.FC4R1/metadata directory (depending on the version the directory name will vary) the file with the necessary information for managing the geometric data is located. If this file were corrupted it would be necessary to implement the following procedure to correct it:

Copy
execute procedure SE_MetadataInit()

This could occur when performing a restore of an ONTAPE for example, since the data may have changed.

4 Loading table spatial_references

The table spatial_references contains information about each of the reference systems that are used to store geometries. For example, the data may be in the Mercator projection. The spatial_references table contains information for transforming spherical data into X-Y data from a plane coordinate system. Each reference system is identified by an id known by SRID, in the following link there is a database of the coordinating systems used.

The procedure for creating records in the spatial_references table is detailed below. If 32631 (corresponding to UTM zone 31 N) is the srid to be inserted, it will execute:

Copy
INSERT INTO spatial_references (srid, description, auth_name, auth_srid, falsex, falsey, xyunits, falsez, zunits, falsem, munits, srtext) 
VALUES (32631,  'WGS 84 / UTM zone 31N',  'EPSG',  32631,  -1000000,  -1000000,  1000000,  -1000,  1000,  -1000,  1000, SE_CreateSrtext(32631));

5 Loading shape data

You can load shape geometries data into a column using the tool loadshp. For example, the following link provides the geometry data of countries for the entire world https://gadm.org.

Use the loadshp tool to load the files with suffix .shp

Copy
$ loadshp -o create -D sample_maps -l gadm_0,geom -f "gadm34_0.shp" -srid 4

Beginning transaction.

Committing work.

Inserted 256 row(s).

Rejected 0 row(s).

Building B-tree index on column gadm_0.se_row_id.

Defining primary key constraint on column gadm_0.se_row_id.

Building R-tree index on column gadm_0.geom.

Updating statistics for table gadm_0.

Elapsed time   0:00:25.8

5.1 Utilities

You can customize the URL to download the files with the geometries for all countries.

Copy

download.sh

#!/bin/sh

COUNTRIES="
AFG
XAD
ALA
ALB
DZA
ASM
AND
AGO
AIA
ATA
ATG
ARG
ARM
ABW
AUS
AUT
AZE
BHS
BHR
BGD
BRB
BLR
BEL
BLZ
BEN
BMU
BTN
BOL
BES
BIH
BWA
BVT
BRA
IOT
VGB
BRN
BGR
BFA
BDI
KHM
CMR
CAN
CPV
XCA
CYM
CAF
TCD
CHL
CHN
CXR
XCL
CCK
COL
COM
COK
CRI
CIV
HRV
CUB
CUW
CYP
CZE
COD
DNK
DJI
DMA
DOM
TLS
ECU
EGY
SLV
GNQ
ERI
EST
ETH
FLK
FRO
FJI
FIN
FRA
GUF
PYF
ATF
GAB
GMB
GEO
DEU
GHA
GIB
GRC
GRL
GRD
GLP
GUM
GTM
GGY
GIN
GNB
GUY
HTI
HMD
HND
HKG
HUN
ISL
IND
IDN
IRN
IRQ
IRL
IMN
ISR
ITA
JAM
JPN
JEY
JOR
KAZ
KEN
KIR
XKO
KWT
KGZ
LAO
LVA
LBN
LSO
LBR
LBY
LIE
LTU
LUX
MAC
MKD
MDG
MWI
MYS
MDV
MLI
MLT
MHL
MTQ
MRT
MUS
MYT
MEX
FSM
MDA
MCO
MNG
MNE
MSR
MAR
MOZ
MMR
NAM
NRU
NPL
NLD
NCL
NZL
NIC
NER
NGA
NIU
NFK
PRK
XNC
MNP
NOR
OMN
PAK
PLW
PSE
PAN
PNG
PIS
PRY
PER
PHL
PCN
POL
PRT
PRI
QAT
COG
REU
ROU
RUS
RWA
BLM
MAF
SHN
KNA
LCA
SPM
VCT
WSM
SMR
STP
SAU
SEN
SRB
SYC
SLE
SGP
SXM
SVK
SVN
SLB
SOM
ZAF
SGS
KOR
SSD
ESP
SP-
LKA
SDN
SUR
SJM
SWZ
SWE
CHE
SYR
TWN
TJK
TZA
THA
TGO
TKL
TON
TTO
TUN
TUR
TKM
TCA
TUV
UGA
UKR
ARE
GBR
USA
UMI
URY
UZB
VUT
VAT
VEN
VNM
VIR
WLF
ESH
YEM
ZMB
ZWE
"

for COUNTRY in $COUNTRIES; do
    echo "Processing country: $COUNTRY"

    FILENAME="gadm34_${COUNTRY}_shp.zip"

    wget https://biogeo.ucdavis.edu/data/gadm3.4/shp/${FILENAME}.zip

    # -n: Avoid overwrite (and prompt) the license.txt
    unzip -n $FILENAME
done
Copy

loadshp.sh

#!/bin/sh

COUNTRIES="
AFG
XAD
ALA
ALB
DZA
ASM
AND
AGO
AIA
ATA
ATG
ARG
ARM
ABW
AUS
AUT
AZE
BHS
BHR
BGD
BRB
BLR
BEL
BLZ
BEN
BMU
BTN
BOL
BES
BIH
BWA
BVT
BRA
IOT
VGB
BRN
BGR
BFA
BDI
KHM
CMR
CAN
CPV
XCA
CYM
CAF
TCD
CHL
CHN
CXR
XCL
CCK
COL
COM
COK
CRI
CIV
HRV
CUB
CUW
CYP
CZE
COD
DNK
DJI
DMA
DOM
TLS
ECU
EGY
SLV
GNQ
ERI
EST
ETH
FLK
FRO
FJI
FIN
FRA
GUF
PYF
ATF
GAB
GMB
GEO
DEU
GHA
GIB
GRC
GRL
GRD
GLP
GUM
GTM
GGY
GIN
GNB
GUY
HTI
HMD
HND
HKG
HUN
ISL
IND
IDN
IRN
IRQ
IRL
IMN
ISR
ITA
JAM
JPN
JEY
JOR
KAZ
KEN
KIR
XKO
KWT
KGZ
LAO
LVA
LBN
LSO
LBR
LBY
LIE
LTU
LUX
MAC
MKD
MDG
MWI
MYS
MDV
MLI
MLT
MHL
MTQ
MRT
MUS
MYT
MEX
FSM
MDA
MCO
MNG
MNE
MSR
MAR
MOZ
MMR
NAM
NRU
NPL
NLD
NCL
NZL
NIC
NER
NGA
NIU
NFK
PRK
XNC
MNP
NOR
OMN
PAK
PLW
PSE
PAN
PNG
PIS
PRY
PER
PHL
PCN
POL
PRT
PRI
QAT
COG
REU
ROU
RUS
RWA
BLM
MAF
SHN
KNA
LCA
SPM
VCT
WSM
SMR
STP
SAU
SEN
SRB
SYC
SLE
SGP
SXM
SVK
SVN
SLB
SOM
ZAF
SGS
KOR
SSD
ESP
SP-
LKA
SDN
SUR
SJM
SWZ
SWE
CHE
SYR
TWN
TJK
TZA
THA
TGO
TKL
TON
TTO
TUN
TUR
TKM
TCA
TUV
UGA
UKR
ARE
GBR
USA
UMI
URY
UZB
VUT
VAT
VEN
VNM
VIR
WLF
ESH
YEM
ZMB
ZWE
"

DBNAME="sample_maps"

STRINGTEST=(${COUNTRIES[@]})
FIRST="${STRINGTEST[0]}"

echo "The first country is $FIRST"

for COUNTRY in $COUNTRIES; do
    echo "Processing country: $COUNTRY"

    for LAYER in 0 1 2 3 4 5; do

        CMD="append"
        OPT=""

        RES=$(echo "SELECT COUNT(*) FROM systables WHERE tabname = 'gadm_${LAYER}'" | dbaccess $DBNAME)
        COUNT=`echo $RES | cut -d' ' -f 2`

        if [ $COUNT = 0 ]; then
            CMD="create"
            OPT="-srid 4"
        fi

        FILESHP="gadm34_${COUNTRY}_${LAYER}.shp"

        echo "Executing: loadshp -o $CMD -D $DBNAME -l gadm_${LAYER},geom -f \"${FILESHP}\" ${OPT}"

        loadshp -o $CMD -D $DBNAME -l gadm_${LAYER},geom -f "${FILESHP}" ${OPT}
    done

done

You can execute the following command:

Copy
nohup ./loadshape.sh &