Oracle Spatial is an integrated set of functions, data structures, and tables that aid in storing and retrieving spatial data. That data describes shapes and their geometric relationships in two-dimensional, three-dimensional, or four-dimensional space.
With Oracle Spatial, you would typically define a set of shapes (such as points, lines, rectangles, polygons, or circles); store and register the data in the Oracle Spatial data dictionary; and then issue queries against the data to retrieve information about area, intersections, close relations, and other interpolated information.
Oracle Spatial data is primarily retrieved in very hard-to-read stored objects, such as SDO_POINT and SDO_ORDINATES. It would be useful to extract and manipulate the data directly without needing additional software packages. SVG, generated from the database, could handle this task quite easily as long as an SVG viewer is installed in a browser.
In this article, I'll show a PL/SQL package that, when called via the modplsql interface, will generate enough SVG to view the data used in the simple example from the Oracle Spatial User's Guide, chapter 2. (You can find HTML versions of the User's Guides for each major database version online at the Oracle Technology Network, where you may have to sign in.) The example defines four shapes -- a rectangle, two polygons, and a circle -- to represent geographical areas of marketing interest for a soft drink manufacturer. To save space, I'll support only the three types of shapes that are in this example. I won't support unit translation (metres to pixels), but I will support scrolling around the image and magnification. I also assume all data is two-dimensional for now.
The biggest challenge in translating the data to something SVG expects is the different ways of representing shapes. For example, Oracle Spatial defines a "circle" by three points along its circumference. This is useful to describe a two-dimensional circle, which may be skewed in a particular direction in three-dimensional or four-dimensional spaces. SVG expects the coordinates of a centre point and a radius. The maths required is lengthy but possible, as long as those three points don't lie in a relatively straight line. A minor challenge is the fact that Oracle Spatial tends to describe data in terms of a mathematical graph, with the Y axis in an upward direction, while SVG maps the Y axis in a downward direction, so the entire graph needs to be flipped vertically.
If you install Oracle Spatial, and run the statements from chapter two of the Oracle Spatial User's Guide, you'll be able to compile and run the following script from modplsql. I found that "m=20" gave a nice magnification level to fit in the diagram.
The code is shown in Listing A.
Scott Stephens worked for Oracle for more than 13 years in technical support, e-commerce, marketing, and software development.