X

Oracle Spatial and Graph – technical tips, best practices, and news from the product team

Using GDAL with Oracle Spatial GeoRaster – Code Examples

Jean Ihm
Product Manager, Oracle Spatial and Graph

GDAL is an excellent open source tool for loading several raster formats into Oracle Spatial GeoRaster.  Here are some resources and code examples to help you get started using GDAL with Oracle Spatial and Graph.

About the Oracle Spatial GeoRaster driver for GDAL

Getting Started With GDAL Presentation (PDF)

Code examples:

More about Oracle Spatial Features – Open Source Components

 

===============================

 

USING GDAL

 

===============================

--

-- Run gdalinfo to see the georeference information, including the SRID

--

gdalinfo sf1.gtif

 

sqlplus student/student

 

DROP TABLE sf_rasters;

 

-- Create a raster data table.

DROP TABLE student_rdt_01;

 

-- Loading is faster if you turn off logging.

CREATE TABLE student_rdt_01 OF SDO_RASTER

  (PRIMARY KEY (

     rasterId,

     pyramidLevel,

     bandBlockNumber,

     rowBlockNumber,

     columnBlockNumber))

  LOB(rasterblock) STORE AS (NOCACHE NOLOGGING);

 

exit;

 

--

-- Include DESCRIPTION create option if you want GDAL to create the sf_rasters table

-- The INSERT create option makes a call to SDO_GEOR.INIT to intialize the raster.

-- On windows, the continuation character is ^, on UNIX or Linux it's \.

--

gdal_translate -of georaster sf1.gtif ^

               georaster:student/student,,sf_rasters,georaster ^

               -co "DESCRIPTION=(georid NUMBER, source_file VARCHAR2(100), georaster SDO_GEORASTER)" ^

               -co "INSERT=VALUES(101, 'file called sf1.tif', SDO_GEOR.INIT('student_rdt_01',1))" ^

               -co "BLOCKXSIZE=512" -co "BLOCKYSIZE=512"

 

-- Load a second raster into SF_RASTERS.

-- No need to include the DESCRIPTION create option because the SF_RASTERS table already exists.

gdal_translate -of georaster sf2.gtif ^

               georaster:student/student,,test_gdal,raster_column ^

               -co "INSERT=VALUES(102, SDO_GEOR.INIT('student_rdt_01',2))" ^

               -co "BLOCKXSIZE=512" -co "BLOCKYSIZE=512"

 

-- Load a third raster into SF_RASTERS.

gdal_translate -of georaster sf4.gtif ^

               georaster:student/student,,test_gdal,raster_column ^

               -co "INSERT=VALUES(103, SDO_GEOR.INIT('student_rdt_01',3))" ^

               -co "BLOCKXSIZE=512" -co "BLOCKYSIZE=512"

 

-- Load a fourth raster into SF_RASTERS.

gdal_translate -of georaster sf5.gtif ^

               georaster:student/student,,test_gdal,raster_column ^

               -co "INSERT=VALUES(104, SDO_GEOR.INIT('student_rdt_01',4))" ^

               -co "BLOCKXSIZE=512" -co "BLOCKYSIZE=512"

 

 

--

-- Create pyramids for all the rasters in the table

--

sqlplus student/student

 

DECLARE

  geor_v  sdo_georaster;

  status  varchar2(20);

BEGIN

  FOR r in (SELECT georid FROM sf_rasters ORDER BY georid) LOOP

    SELECT georaster INTO geor_v

    FROM sf_rasters

    WHERE georid = r.georid

    FOR UPDATE;

 

    sdo_geor.generatePyramid(geor_v, 'resampling=NN');

 

    UPDATE sf_rasters

    SET georaster = geor_v

    WHERE georid = r.georid;

 

    COMMIT;

  END LOOP;

END;

/

 

 

-- Create a spatial index for all

--

--  To see the extent of all the rasters in this column, you can run the following:

--

SELECT sdo_aggr_mbr (a.georaster.spatialextent) from sf_rasters a;

 

--

-- When populating USER_SDO_GEOM_METADATA, expand the extent returned above

--   to be large enough to contain any rasters added in the future.

--

DELETE FROM user_sdo_geom_metadata

  WHERE table_name = 'SF_RASTERS'

    AND column_name = 'GEORASTER.SPATIALEXTENT';

INSERT INTO user_sdo_geom_metadata VALUES

  ('SF_RASTERS', 'GEORASTER.SPATIALEXTENT',

    SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', 1700000, 2000000, .05),

                  SDO_DIM_ELEMENT('Y', 550000, 700000, .05)),

    26943);

commit;

 

DROP INDEX sf_rasters_sidx;

CREATE INDEX sf_rasters_sidx ON sf_rasters(georaster.spatialExtent)

  INDEXTYPE IS mdsys.spatial_index;

 

exit;

 

--

-- Now you can create a GeoRaster theme in MapViewer to preview the rasters loaded in Oracle.

--

 

 

===============================

 

HOW TO COMPILE - LINUX

 

===============================

 

 

If you don't need the ECW plugin, skip anything that references ECW below.

 

 

For ECW SDK

===========

 

The following is the Erdas ECW JPEG 2000 Codec SDK download site.

 

http://www.erdas.com/Products/ERDASProductInformation/tabid/84/currentid/1142/default.aspx

 

Register, and download the ECW JPEG2000 Codec SDK Source Code.

  Note that downloading and installing the ECW JPEG 2000 Codec SDK requires agreeing to a license.

  Please review the license terms carefully.

 

 

Download ECW JPEG2000 Codec SDK Source Code

mkdir full_path_to_ECW_INSTALL_directory/ECW_INSTALL

mkdir full_path_to_ECW_INSTALL_directory/ECW_INSTALL/include

cd libecwj2-3.3

./configure --prefix=full_path_to_ECW_INSTALL_directory/ECW_INSTALL

 

make

make install

 

For GDAL

========

 

Make sure your $ORACLE_HOME environment variable is set.  If it is, SDO_GEORASTER will automatically be part of the GDAL build.

 

 

http://trac.osgeo.org/gdal/

Click on BuildHints

Click on DownloadSource

click on http://download.osgeo.org/gdal

click on daily

stable is stable code, trunk is code under development (you choose which one you want to compile).

                       trunk may contain fixes to SDO_GEORASTER extension that are not in stable.

.gz files are source code for UNIX/Linux, .zip files are source code for Windows

Unzip the source

cd to top level directory of source tree

 

 

mkdir full_path_to_GDAL_INSTALL_directory/GDAL_INSTALL

 

Call configure. Backslash ('\') is the continuation character for a UNIX command line

./configure --help

 

./configure \

--prefix=full_path_to_GDAL_INSTALL_directory/GDAL_INSTALL \

--with-ecw=full_path_to_GDAL_INSTALL_directory/ECW_INSTALL

 

setenv LD_LIBRARY_PATH full_path_to_GDAL_INSTALL_directory/ECW_INSTALL/lib

make

make install

 

Add full_path_to_GDAL_INSTALL_directory/GDAL_INSTALL/bin to your path environent variable.

To test install, georaster should appear as one of the gdalinfo formats.

For example, run the gdalinfo command as follows:

 

gdalinfo --formats

 

  --  ECW (rw): ERMapper Compressed Wavelets

  --  GeoRaster (rw+): Oracle Spatial GeoRaster

 

===============================

 

HOW TO COMPILE - WINDOWS

 

===============================

 

For Windows, there are two choices.

 

1) Use GDAL prebuilt libraries (no comipling required).

   The installation program is called OSGeo4W.

  

2) Compile GDAL and third party extensions, like the Erdas ECW SDK on Windows.

 

 

===============================================================================================

===                                                                                         ===

===                 1) Installation of OSGeo4w                                              ===

===                                                                                         ===

===============================================================================================

 

 

1.  Download OSGeo4W from http://wiki.osgeo.org/wiki/OSGeo_Win32_Installer

2.  Open/Run "osgeo4w-setup.exe"

3.  Select "Advanced install"

4.  Click on "Next"

5.  Select "Install from Internet".

6.  Click on "Next"

7.  Select the Root Directory where you want to install OSGeo4W

8.  Click on "Next"

9.  By default, the Local Package Directory will be the Root Directory you specified.

10. Click on "Next"

11. Chose how to connect to the Internet, for example, Ues IE5 Settings

12. Click on "Next"

13. On "Select Packages", select tools you are interested in, but don't forget to select:

 

[-] Commandline_Utilities

   1.6.0 .............................. gdal16: The GDAL/OGR library, command line tools (1.6 ABI)

 

[-] Libs

   1.6.0 .............................. gdal16: The GDAL/OGR library, command line tools (1.6 ABI)

   1.6.0 .............................. gdal16-oracle: TheOGR OCI and GeoRaster Plugins for Oracle

 

For ECW, select

[-] Libs

   1.6.0 .............................. gdal16-ecw: ECW Raster Plugin for GDAL 1.6

 

 

14. Click on "Next"

15. Finalize installation

 

16. If you chose to install gdal16-ecw, the ERDAS plugin, you must download the ECW DLL's

    from the ERDAS website, after you agree to the ERDAS lisencing agreement.

 

    The steps needed are summarized below.

    Full details are here: http://trac.osgeo.org/osgeo4w/wiki/pkg-gdal16-ecw

 

    SUMMARIZED STEPS

    ================

    Go to Erdas Web Site: http://www.erdas.com/Products/ERDASProductInformation/tabid/84/currentid/1142/default.aspx

 

    Download the ECW JPEG2000 Codec SDK (you will need to register, and agree to the ERDAS lisence agreement).

 

    Run the ERMapperImageCompressionSDK3.3Setup_20070509.exe

 

    After installation, copy the .dll files in the redistributable\vc71 directory somewhere appropriate,

    like C:\windows\system32. eg.

 

      copy C:\"Program Files"\"Earth Resource Mapping"\"ECW SDK"\redistributable\vc71\*.dll C:\windows\system32

 

    Note that downloading and installing these DLLs requires agreeing to a license.

    Please review the license terms carefully.

 

17. Now Open the icon "OSGeo4W Shell" by clicking on the icon on your desktop, or by

    executing OSGEO4W_ROOT\OSGeo4w.bat

 

18. Execute gdal16.bat

 

19. Try GeoRaster support:

C:\>gdalinfo --format georaster

 

  

 

===============================================================================================

===                                                                                         ===

===                 2) Compiling GDAL and third party extension on Windows                  ===

===                                                                                         ===

===============================================================================================

 

Visual Studio 2003 or newer is required.

 

Make sure your %ORACLE_HOME% environment variable is set.  If it is, SDO_GEORASTER will automatically be part of the GDAL build.

 

 

http://trac.osgeo.org/gdal/

Click on BuildHints

If you don't need the ECW plugin, skill anything that references ECW below.

 

 

For ECW SDK

===========

 

The following is the Erdas ECW JPEG 2000 Codec SDK download site.

 

http://www.erdas.com/Products/ERDASProductInformation/tabid/84/currentid/1142/default.aspx

 

Register, and download the ECW JPEG2000 Codec SDK Source Code.

  Note that downloading and installing the ECW JPEG 2000 Codec SDK requires agreeing to a license.

  Please review the license terms carefully.

 

Download ECW JPEG2000 Codec SDK Source Code

cd libecwj2-3.3\Source

Compile for Windows

 

 

For GDAL

========

 

Click on DownloadSource

click on http://download.osgeo.org/gdal

click on daily

stable is stable code, trunk is code under development (you choose which one you want to compile).

                       trunk may contain fixes to SDO_GEORASTER extension that are not in stable.

.gz files are source code for UNIX/Linux, .zip files are source code for Windows

Unzip the source

cd to top level directory of GDAL source tree

 

mkdir full_path_to_GDAL_INSTALL_directory\GDAL_INSTALL

 

make the following edits in nmake.opt

  set MSVC_VER to your version of the Visual C++ compiler

  set GDAL_HOME = full_path_to_GDAL_INSTALL_directory\GDAL_INSTALL

  Comment out STDCALL=YES

  Add -DCPL_DISABLE_STDCALL to OPTFLAGS

 

If you want ECW, also make the following edits to nmake.opt

  Uncomment ECW support

  ECW_PLUGIN = NO

  ECWDIR  = full_path_to_ECW\libecwj2-3.3

  ECWLIB  = $(ECWDIR)\Source\NCSBuildQmake\Debug\libecwj2.lib

 

From top level directory of GDAL source tree

nmake -f makefile.vc

nmake -f makefile.vc install

 

 

Add full_path_to_GDAL_INSTALL_directory\GDAL_INSTALL\bin to your path environment variable.

 

To test install, georaster should appear as one of the gdalinfo formats.

For example, run the gdalinfo command as follows:

 

gdalinfo --formats

 

  --  ECW (rw): ERMapper Compressed Wavelets

  --  GeoRaster (rw+): Oracle Spatial GeoRaster

 

 

 

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.