This chapter provides a reference and guide to using the Oracle Spatial cartridge, which extends Oracle Continuous Query Language (Oracle CQL) to provide advanced spatial features for locationenabled applications.
You can use Oracle Spatial types, methods, fields, and constructors in Oracle CQL queries and views as you would Oracle CQL native types when building Oracle CEP applications.
This chapter describes:
For more information, see:
Oracle Spatial is an option for Oracle Database that provides advanced spatial features to support highend geographic information systems (GIS) and locationenabled business intelligence solutions (LBS).
Oracle Spatial is an optional data cartridge which allows you to write Oracle CQL queries and views that seamlessly interact with Oracle Spatial classes in your Oracle CEP application.
Using Oracle Spatial, you can configure Oracle CQL queries that perform the most important geographic domain operations such as storing spatial data, performing proximity and overlap comparisons on spatial data, and integrating spatial data with the Oracle CEP server by providing the ability to index on spatial data.
To use Oracle Spatial, you require a working knowledge of the Oracle Spatial API. For more information about Oracle Spatial, see:
Product overview: http://www.oracle.com/technology/products/spatial/index.html
Oracle Spatial documentation: http://www.oracle.com/pls/db112/portal.portal_db?selected=7&frame=#oracle_spatial_and_location_information
Oracle Spatial Java API reference: http://download.oracle.com/docs/cd/E11882_01/appdev.112/e11829/toc.htm
This section describes:
Oracle Spatial uses the cartridge ID com.oracle.cep.cartrdiges.spatial
and registers the serverscoped reserved link name spatial
.
Use the spatial
link name to associate an Oracle Spatial method call with the Oracle Spatial application context.
For more information, see:
Oracle Spatial is based on the Oracle Spatial Java API. Oracle Spatial exposes Oracle Spatial functionality in the com.oracle.cep.cartridge.spatial.Geometry
class. Oracle Spatial functionality that is not in the Oracle Spatial Java API is not accessible from Oracle Spatial.
Using Oracle Spatial, your Oracle CQL queries may access the Oracle Spatial functionality that Table 161 describes.
Table 161 Oracle Spatial Scope
Oracle Spatial Feature  Scope 

Geometry Types 
The following geometry types from the Oracle Spatial Java API:
The following geometry operations:
For more information, see: 
Coordinate Systems 
For more information, see Section 16.1.2.3, "Ordinates and Coordinate Systems and the SDO_SRID". 
Geometric Index 
For more information, see Section 16.1.2.4, "Geometric Index". 
Geometric Relation Operators 
For more information, see Section 16.1.2.5, "Geometric Relation Operators". 
Geometric Filter Operators 
For more information, see Section 16.1.2.6, "Geometric Filter Operators". 
Geometry API 
For a complete list of the methods that 
For more information on how to access these Oracle Spatial features using Oracle Spatial, see Section 16.2, "Using Oracle Spatial".
The Oracle Spatial data model consists of geometries. A geometry is an ordered sequence of vertices. The semantics of the geometry are determined by its type.
Oracle Spatial allows you to access the following Oracle Spatial types directly in Oracle CQL queries and views:
SDO_GTYPES
: Oracle Spatial supports the following geometry types:
2D points
2D simple polygons
2D rectangles
Table 162 describes the geometry types from the com.oracle.cep.cartridge.spatial.Geometry
class that you can use.
SDO_ELEMENT_INFO
: You can create the Element Info array using:
com.oracle.cep.cartridge.spatial.Geometry.createElemInfo
static method
einfogenerator
function
For more information, see Section 16.1.2.2, "Element Info Array".
ORDINATES
: You can create the ordinates using the Oracle Spatial ordsgenerator
function.
For more information, see Section 16.1.2.3, "Ordinates and Coordinate Systems and the SDO_SRID".
For more information, see:
The Element Info attribute is defined using a varying length array of numbers. This attribute specifies how to interpret the ordinates stored in the Ordinates attribute.
Oracle Spatial provides the following helper function for generating Element Info attribute values:
com.oracle.cep.cartridge.spatial.Geometry.createElemInfo(int SDO_STARTING_OFFSET, int SDO_ETYPE , int SDO_INTERPRETATION)
You can also use the einfogenerator
function.
For more information, see:
"SDO_ELEM_INFO" in the Oracle Spatial Developer's Guide.
Table 163 lists the coordinate systems that Oracle Spatial supports by default and the SDO_SRID
value that identifies each coordinate system.
Table 163 Oracle Spatial Coordinate Systems
Coordinate System  SDO_SRID  Description 

Cartesian 
0 
Cartesian coordinates are coordinates that measure the position of a point from a defined origin along axes that are perpendicular in the represented space. 
Geodetic (WGS84) 
8307 
Geodetic coordinates (sometimes called geographic coordinates) are angular coordinates (longitude and latitude), closely related to spherical polar coordinates, and are defined relative to a particular Earth geodetic datum. This is the default coordinate system in Oracle Spatial. 
You can specify the SDO_SRID
value as an argument to each Oracle Spatial method and constructor you call or you can configure the SDO_SRID
in the Oracle Spatial application context once and use com.oracle.cep.cartridge.spatial.Geometry
methods without having to set the SDO_SRID
as an argument each time. Using the application context, you can also specify any coordinate system that Oracle Spatial supports.
Note:
If you use a com.oracle.cep.cartridge.spatial.Geometry
method that does not take an SDO_SRID
value, then you must use the Oracle Spatial application context. For example, the following method call will cause a runtime exception:
com.oracle.cep.cartridge.spatial.Geometry.createPoint(lng, lat)
Instead, you must use the spatial
link name to associate the method call with the Oracle Spatial application context:
com.oracle.cep.cartridge.spatial.Geometry.createPoint@spatial(lng, lat)
If you use a Geometry
method that takes an SDO_SRID
value, then the use of the spatial
link name is optional. For example, both the following method calls are valid:
com.oracle.cep.cartridge.spatial.Geometry.createPoint(8307, lng, lat) com.oracle.cep.cartridge.spatial.Geometry.createPoint@spatial(lng, lat)
For more information, see Section 16.1.4, "Oracle Spatial Application Context".
Ordinates define the array of coordinates for a geometry using a double array. Oracle Spatial provides the ordsgenerator
helper function for generating the array of coordinates. For syntax, see "ordsgenerator".
For more information, see:
"SDO_SRID" in the Oracle Spatial Developer's Guide
"Coordinate Systems (Spatial Reference Systems)" in the Oracle Spatial Developer's Guide
Section 16.2.6, "How to Use the Default Geodetic Coordinates"
Oracle Spatial uses a spatial index to implement the primary filter. The purpose of the spatial index is to quickly create a subset of the data and reduce the processing burden on the secondary filter.
A spatial index, like any other index, provides a mechanism to limit searches, but in this case the mechanism is based on spatial criteria such as intersection and containment.
Oracle Spatial uses RTree indexing for the default indexing mechanism. A spatial Rtree index can index spatial data of up to four dimensions. An Rtree index approximates each geometry by a single rectangle that minimally encloses the geometry (called the Minimum Bounding Rectangle, or MBR)
For more information, see:
"Indexing of Spatial Data" in the Oracle Spatial Developer's Guide
Oracle Spatial supports the following Oracle Spatial geometric relation operators:
You can use any of these operators in either the Oracle CQL query projection clause or where clause.
When you use a geometric relation operator in the where clause of an Oracle CQL query, Oracle Spatial enables Rtree indexing on the relation specified in the where clause.
Oracle Spatial supports only geometric relations between point and other geometry types.
For more information, see Section 16.2.4, "How to Use Geometry Relation Operators".
Oracle Spatial supports the following Oracle Spatial geometric filter operators:
These filter operators perform primary filtering and so they may only appear in an Oracle CQL query where clause.
These filter operators use the spatial index to identify the set of spatial objects that are likely to interact spatially with the given object.
For more information, see:
Oracle Spatial is based on the Oracle Spatial Java API. Oracle Spatial exposes Oracle Spatial functionality in the com.oracle.cep.cartridge.spatial.Geometry
class. This Geometry
class also extends oracle.spatial.geometry.J3D_Geometry
.
Although Oracle Spatial supports only 2D geometries, for efficiency, the Geometry
class uses some J3D_Geometry
methods. The Geometry
class automatically zeropads the Z coordinates for J3D_Geometry
methods.
Oracle Spatial functionality inaccessible from the Geometry
class (or not conforming to the scope and geometry types that Oracle Spatial supports) is inaccessible from Oracle Spatial.
This section describes:
Section 16.1.2.7.1, "com.oracle.cep.cartridge.spatial.Geometry Methods"
Section 16.1.2.7.2, "oracle.spatial.geometry.JGeometry Methods"
For more information, see:
Note:
To simplify Oracle Spatial type names, you can use aliases as Section 2.7.2, "Defining Aliases Using the Aliases Element" describes.
Table 164 lists the public methods that the Geometry
class provides.
Table 164 Oracle Spatial Geometry Methods
Type  Method 

Buffers 

Distance 

Element information 

Geometries 

Linear polygons 

Minimum Bounding Rectangle (MBR) 

Points 

Rectangles 

Type and type conversion 
Note:
Geometry
class methods are case sensitive and you must use them in the case shown.
Note:
If you use a com.oracle.cep.cartridge.spatial.Geometry
method that does not take an SDO_SRID
value, then you must use the Oracle Spatial application context. For example, the following method call will cause a runtime exception:
com.oracle.cep.cartridge.spatial.Geometry.createPoint(lng, lat)
Instead, you must use the spatial
link name to associate the method call with the Oracle Spatial application context:
com.oracle.cep.cartridge.spatial.Geometry.createPoint@spatial(lng, lat)
If you use a Geometry
method that takes an SDO_SRID
value, then the use of the spatial
link name is optional. For example, both the following method calls are valid:
com.oracle.cep.cartridge.spatial.Geometry.createPoint(8307, lng, lat) com.oracle.cep.cartridge.spatial.Geometry.createPoint@spatial(lng, lat)
For more information, see Section 16.1.4, "Oracle Spatial Application Context".
The following JGeometry
public methods are applicable to Oracle Spatial:
double area(double tolerance)
: returns the total planar surface area of a 2D geometry.
double length(double tolerance)
: returns the perimeter of a 2D geometry. All edge lengths are added.
double[] getMBR()
: returns the Minimum Bounding Rectangle (MBR) of this geometry. It returns a double array containing the minX
, minY
, maxX
, and maxY
value of the MBR for 2D.
For more information, see:
The Oracle Spatial cartridge supports one data type: com.oracle.cep.cartridge.spatial.Geometry
.
For a complete list of the methods that com.oracle.cep.cartridge.spatial.Geometry
provides, see Section 16.1.2.7, "Geometry API".
You can define an application context for an instance of Oracle Spatial and propagate this application context at runtime. This allows you to associate specific Oracle Spatial application defaults (such as an SDO_SRID
) with a particular Oracle Spatial instance.
Before you can define an Oracle Spatial application context, edit your Oracle CEP application EPN assembly file to add the required namespace and schema location entries as Example 161 shows:
Example 161 EPN Assembly File: Oracle Spatial Namespace and Schema Location
<?xml version="1.0" encoding="UTF8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xmlns:osgi="http://www.springframework.org/schema/osgi" xmlns:wlevs="http://www.bea.com/ns/wlevs/spring" xmlns:spatial="http://www.oracle.com/ns/ocep/spatial/" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/springbeans.xsd http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/springosgi.xsd http://www.bea.com/ns/wlevs/spring http://www.bea.com/ns/wlevs/spring/springwlevsv11_1_1_6.xsd" http://www.oracle.com/ns/ocep/spatial http://www.oracle.com/ns/ocep/spatial/ocepspatial.xsd">
Example 162 shows how to create a spatial context named SpatialGRS80
in an EPN assembly file using the Geodetic Reference System 1980 (GRS80) coordinate system.
Example 162 spatial:context Element in EPN Assembly File
<spatial:context id="SpatialGRS80" srid="4269" sma="6378137" rof="298.25722101" />
Example 163 shows how to reference a spatial:context
in an Oracle CQL query. In this case, the query uses link name SpatialGRS80
(defined in Example 162) to propagate this application context to Oracle Spatial. The spatial:context
attribute settings of SpatialGRS80
are applied to the createPoint
method call.
Example 163 Referencing spatial:context in an Oracle CQL Query
<view id="createPoint"> select com.oracle.cep.cartridge.spatial.Geometry.createPoint@SpatialGRS80( lng, lat) from CustomerPos[NOW] </view>
For more information (including a complete list of all spatial:context
attributes), see "How to Configure Oracle Spatial Application Context" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing for Eclipse.
Note:
If you use a com.oracle.cep.cartridge.spatial.Geometry
method that does not take an SDO_SRID
value, then you must use the Oracle Spatial application context. For example, the following method call will cause a runtime exception:
com.oracle.cep.cartridge.spatial.Geometry.createPoint(lng, lat)
Instead, you must use the spatial
link name to associate the method call with the Oracle Spatial application context:
com.oracle.cep.cartridge.spatial.Geometry.createPoint@spatial(lng, lat)
If you use a Geometry
method that takes an SDO_SRID
value, then the use of the spatial
link name is optional. For example, both the following method calls are valid:
com.oracle.cep.cartridge.spatial.Geometry.createPoint(8307, lng, lat) com.oracle.cep.cartridge.spatial.Geometry.createPoint@spatial(lng, lat)
For more information, see Section 16.1.2.7, "Geometry API".
This section describes common usecases that highlight how you can use Oracle Spatial in your Oracle CEP applications, including:
Section 16.2.1, "How to Access the Geometry Types That the Oracle Spatial Java API Supports"
Section 16.2.3, "How to Access Geometry Type Public Methods and Fields"
Section 16.2.6, "How to Use the Default Geodetic Coordinates"
For more information, see Section 16.1.2.7, "Geometry API".
This procedure describes how to access Oracle Spatial geometry types SDO_GTYPE
, SDO_ELEMENT_INFO
, and ORDINATES
using Oracle Spatial in an Oracle CQL query.
To access the geometry types that the Oracle Spatial Java API supports:
Import the package com.oracle.cep.cartridge.spatial
into your Oracle CEP application's MANIFEST.MF
file.
For more information, see "How to Import a Package" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing for Eclipse.
Define your Oracle CEP application event type using the appropriate Oracle Spatial data types.
Example 164 shows how to define event type MySpatialEvent
with two event properties x
and y
of type com.oracle.cep.cartridge.spatial.Geometry
.
Example 164 Oracle CEP Event Using Oracle Spatial Types
<wlevs:eventtyperepository> <wlevs:eventtype typename="MySpatialEvent"> <wlevs:properties> <wlevs:property name="x" type="com.oracle.cep.cartridge.spatial.Geometry"/> <wlevs:property name="y" type="com.oracle.cep.cartridge.spatial.Geometry"/> </wlevs:properties> </wlevs:eventtype> </wlevs:eventtyperepository>
You can use these event properties in an Oracle CQL query like this:
CONTAIN@spatial(x, y, 20.0d)
For more information, see "Overview of Oracle CEP Events" in the Oracle Fusion Middleware Developer's Guide for Oracle Complex Event Processing for Eclipse.
Choose an SDO_GTYPE
, for example, GTYPE_POLYGON
.
For more information, see Section 16.1.2.1, "Geometry Types".
Choose the Element Info appropriate for your ordinates.
For more information, see Section 16.1.2.2, "Element Info Array"
Define your coordinate values.
For more information, see Section 16.1.2.3, "Ordinates and Coordinate Systems and the SDO_SRID".
Create your Oracle CQL query as Example 165 shows.
Example 165 Oracle CQL Query Using Oracle Spatial Geometry Types
view id="ShopGeom"> select com.oracle.cep.cartridge.spatial.Geometry.createGeometry@spatial( com.oracle.cep.cartridge.spatial.Geometry.GTYPE_POLYGON, com.oracle.cep.cartridge.spatial.Geometry.createElemInfo(1, 1003, 1), ordsgenerator@spatial( lng1, lat1, lng2, lat2, lng3, lat3, lng4, lat4, lng5, lat5, lng6, lat6 ) ) as geom from ShopDesc </view>
You can use Oracle Spatial to create a geometry in an Oracle CQL query by invoking:
static methods in com.oracle.cartridge.spatial.Geometry
methods in oracle.spatial.geometry.JGeometry
that conform to the scope and geometry types that Oracle Spatial supports.
For more information, see Section 16.1.2.7, "Geometry API".
Using a Static Method in the Oracle Spatial Geometry Class
Example 166 shows how to create a point geometry using a static method in com.oracle.cartridge.spatial.Geometry
. In this case, you must use a link (@spatial
) to identify the data cartridge that provides this class. The advantage of using this approach is that the Oracle Spatial application context is applied to set the SRID and other Oracle Spatial options, either by default or based on an application context you configure (see Section 16.1.4, "Oracle Spatial Application Context").
Example 166 Creating a Point Geometry Using a Geometry Static Method
<view id="CustomerPosGeom"> select com.oracle.cep.cartridge.spatial.Geometry.createPoint@spatial( lng, lat) as geom from CustomerPos[NOW] </view>
For more information, see Section 16.1.2.1, "Geometry Types".
Using Oracle Spatial, you can access the public member functions and public member fields of Oracle Spatial classes directly in Oracle CQL.
Oracle Spatial functionality inaccessible from the Geometry
class (or not conforming to the scope and geometry types that Oracle Spatial supports) is inaccessible from Oracle Spatial.
In Example 167, the view ShopGeom
creates an Oracle Spatial geometry called geom
. The view shopMBR
calls JGeometry
static method getMBR
which returns a double[]
as stream element mbr
. The query qshopMBR
accesses this double[]
using regular Java API.
Example 167 Accessing Geometry Type Public Methods and Fields
<view id="ShopGeom"> select com.oracle.cep.cartridge.spatial.Geometry.createGeometry@spatial( com.oracle.cep.cartridge.spatial.Geometry.GTYPE_POLYGON, com.oracle.cep.cartridge.spatial.Geometry.createElemInfo(1, 1003, 1), ordsgenerator@spatial( lng1, lat1, lng2, lat2, lng3, lat3, lng4, lat4, lng5, lat5, lng6, lat6 ) ) as geom from ShopDesc </view> <view id=”shopMBR”> select geom.getMBR() as mbr from ShopGeom </view> <query id=”qshopMBR”> select mbr[0], mbr[1], mbr[2], mbr[3] from shopMBR </query>
For more information, see:
Using Oracle Spatial, you can access the following Oracle Spatial geometry relation operators in either the WHERE
or SELECT
clause of an Oracle CQL query:
In Example 168, the view op_in_where
uses the CONTAIN
geometry relation operator in the WHERE
clause: in this case, Oracle Spatial uses RTree indexing. The view op_in_proj
uses CONTAIN
in the SELECT
clause.
Example 168 Using Geometry Relation Operators
<view id="op_in_where"> RStream( select loc.customerId, shop.shopId from LocGeomStream[NOW] as loc, ShopGeomRelation as shop where CONTAIN@spatial(shop.geom, loc.curLoc, 5.0d) = true ) </view> <view id="op_in_proj"> RStream( select loc.customerId, shop.shopId, CONTAIN@spatial(shop.geom, loc.curLoc, 5.0d) from LocGeomStream[NOW] as loc, ShopGeomRelation as shop ) </view>
For more information, see Section 16.1.2.5, "Geometric Relation Operators".
Using Oracle Spatial, you can access the following Oracle Spatial geometry filter operators in the WHERE
clause of an Oracle CQL query:
In Example 169, the view filter
uses the FILTER
geometry filter operator in the WHERE
clause.
Example 169 Using Geometry Filter Operators
<view id="filter"> RStream( select loc.customerId, shop.shopId from LocGeomStream[NOW] as loc, ShopGeomRelation as shop where FILTER@spatial(shop.geom, loc.curLoc, 5.0d) = true ) </view>
For more information, see Section 16.1.2.6, "Geometric Filter Operators".
When you create an Oracle CQL query using the default Oracle Spatial application context, the default SRID
will be set to CARTESIAN
.
As Example 1610 shows, the createPoint
method call uses the default link (@spatial
). This guarantees that the default Oracle Spatial application context is applied.
Example 1610 Using the Default Geodetic Coordinates in an Oracle CQL Query
<view id="createPoint"> select com.oracle.cep.cartridge.spatial.Geometry.createPoint@spatial( lng, lat) from CustomerPos[NOW] </view>
For more information, see:
This procedure describes how to use the Oracle Spatial application context to specify a geodetic coordinate system other than the default Cartesian geodetic coordinate system in an Oracle CQL query:
For more information, see:
To use other geodetic coordinates:
Create an Oracle Spatial application context and define the srid
attribute for the geodetic coordinate system you want to use.
Example 1611 shows how to create a spatial context named SpatialGRS80
in an EPN assembly file using the Geodetic Reference System 1980 (GRS80) coordinate system.
In your Oracle CQL query, use the id of this spatial:context
in your links.
Example 1612 shows how to reference a spatial:context
in an Oracle CQL query. In this case, the query uses link name SpatialGRS80
(defined in Example 1611) to propagate this application context to Oracle Spatial. The spatial:context
attribute settings of SpatialGRS80
are applied to the createPoint
method call.
Note:
This is an Oracle Spatial geometric relation operator and not a method of the com.oracle.cep.cartridge.spatial.Geometry
class so you invoke this operator as Example 1613 shows, without a package prefix:
ANYINTERACT@spatial
This operator returns true
if the GTYPE_POINT
interacts with the geometry, and false
otherwise.
This operator takes the following arguments:
geom
: any supported geometry type.
key
: a GTYPE_POINT
geometry type.
The geometry type of this geometry must be GTYPE_POINT
or a RUNTIME_EXCEPTION
will be thrown.
tol
: the tolerance as a double
value.
For more information, see "SDO_ANYINTERACT" in the Oracle Spatial Developer's Guide.
Example 1627 shows how to use the ANYINTERACT
Oracle Spatial geometric relation operator in an Oracle CQL query.
Example 1613 Oracle CQL Query Using Geometric Relation Operator ANYINTERACT
<view id="op_in_where"> RStream( select loc.customerId, shop.shopId from LocGeomStream[NOW] as loc, ShopGeomRelation as shop where ANYINTERACT@spatial(shop.geom, loc.curLoc, 5.0d) = true ) </view> <view id="op_in_proj"> RStream( select loc.customerId, shop.shopId, ANYINTERACT@spatial(shop.geom, loc.curLoc, 5.0d) from LocGeomStream[NOW] as loc, ShopGeomRelation as shop ) </view>
This com.oracle.cep.cartridge.spatial.Geometry
method returns a new com.oracle.cep.cartridge.spatial.Geometry
object which is the buffered version of the input oracle.spatial.geometry.JGeometry
polygon.
This method takes the following arguments:
polygon
: an oracle.spatial.geometry.JGeometry
polygon.
distance
: the distance value used for this buffer as a double
.
This value is assumed to be in the same unit as the Unit of Projection for projected geometry. If the geometry is geodetic, this buffer width should be in meters.
This method obtains parameters from the Oracle Spatial application context. Consequently, you must use the spatial
link name to associate the method call with the Oracle Spatial application context:
com.oracle.cep.cartridge.spatial.Geometry.bufferPolygon@spatial(geom, 1300)
For more information, see Section 16.1.4, "Oracle Spatial Application Context".
Example 1614 shows how to use the bufferPolygon
method. Because this bufferPolygon
call depends on the Oracle Spatial application context, it uses the spatial
link name.
Note:
This is an Oracle Spatial geometric relation operator and not a method of the com.oracle.cep.cartridge.spatial.Geometry
class so you invoke this operator as Example 1613 shows, without a package prefix:
CONTAIN@spatial
This operator returns true
if the GTYPE_POINT
is contained by the geometry, and false
otherwise.
This operator takes the following arguments:
geom
: any supported geometry type.
key
: a GTYPE_POINT
geometry type.
The geometry type of this geometry must be GTYPE_POINT
or a RUNTIME_EXCEPTION
will be thrown.
tol
: the tolerance as a double
value.
For more information, see "SDO_CONTAINS" in the Oracle Spatial Developer's Guide.
Example 1627 shows how to use the CONTAIN
Oracle Spatial geometric relation operator in an Oracle CQL query.
Example 1615 Oracle CQL Query Using Geometric Relation Operator CONTAIN
<view id="op_in_where"> RStream( select loc.customerId, shop.shopId from LocGeomStream[NOW] as loc, ShopGeomRelation as shop where CONTAIN@spatial(shop.geom, loc.curLoc, 5.0d) = true ) </view> <view id="op_in_proj"> RStream( select loc.customerId, shop.shopId, CONTAIN@spatial(shop.geom, loc.curLoc, 5.0d) from LocGeomStream[NOW] as loc, ShopGeomRelation as shop ) </view>
Note:
Alternatively, you can use the function einfogenerator
. For more information, see "einfogenerator".
This com.oracle.cep.cartridge.spatial.Geometry
method returns a single element info value as an int[]
from the given arguments.
This method takes the following arguments:
soffset
: the offset, as an int
, within the ordinates array where the first ordinate for this element is stored.
SDO_STARTING_OFFSET
values start at 1 and not at 0. Thus, the first ordinate for the first element will be at SDO_GEOMETRY.Ordinates(1)
. If there is a second element, its first ordinate will be at SDO_GEOMETRY.Ordinates(
n
* 3 + 2)
, where n
reflects the position within the SDO_ORDINATE_ARRAY
definition.
etype
: the type of the element as an int
.
Oracle Spatial supports SDO_ETYPE
values 1, 1003, and 2003 are considered simple elements (not compound types). They are defined by a single triplet entry in the element info array. These types are:
1: point.
1003: exterior polygon ring (must be specified in counterclockwise order).
2003: interior polygon ring (must be specified in clockwise order).
These types are further qualified by the SDO_INTERPRETATION
.
Note:
You cannot mix 1digit and 4digit SDO_ETYPE
values in a single geometry.
interp
: the interpretation as an int
.
For an SDO_ETYPE that is a simple element (1, 1003, or 2003) the SDO_INTERPRETATION
attribute determines how the sequence of ordinates for this element is interpreted. For example, a polygon boundary may be made up of a sequence of connected straight line segments.
If a geometry consists of more than one element, then the last ordinate for an element is always one less than the starting offset for the next element. The last element in the geometry is described by the ordinates from its starting offset to the end of the ordinates varying length array.
Table 165 describes the relationship between SDO_ETYPE
and SDO_INTERPREATION
.
Table 165 SDO_ETYPE and SDO_INTERPRETATION
SDO_ETYPE  SDO_INTERPRETATION  Description 

0 
Any numeric value 
Used to model geometry types not supported by Oracle Spatial. 
1 
1 
Point type. 
1 
0 
Orientation for an oriented point. 
1003 or 2003 
1 
Simple polygon whose vertices are connected by straight line segments. You must specify a point for each vertex; and the last point specified must be exactly the same point as the first (within the tolerance value), to close the polygon. For example, for a 4sided polygon, specify 5 points, with point 5 the same as point 1. 
Example 1616 shows how to use the createElemInfo
method.
Example 1616 Oracle CQL Query Using Geometry.createElemInfo
<view id="ShopGeom"> select com.oracle.cep.cartridge.spatial.Geometry.createGeometry@spatial( com.oracle.cep.cartridge.spatial.Geometry.GTYPE_POLYGON, com.oracle.cep.cartridge.spatial.Geometry.createElemInfo(1, 1003, 1), ordsgenerator@spatial( lng1, lat1, lng2, lat2, lng3, lat3, lng4, lat4, lng5, lat5, lng6, lat6 ) ) as geom from ShopDesc </view>
This com.oracle.cep.cartridge.spatial.Geometry
method returns a new 2D oracle.cep.cartridge.spatial.Geometry
object.
This method takes the following arguments:
gtype
: the geometry type as an int
.
For more information, see Table 162.
eleminfo
: the geometry element info as an int[]
.
For more information, see "createElemInfo".
ordinates
: the geometry ordinates as a double[]
.
srid
: the optional SDO_SRID
of the geometry as an int
.
If you omit the srid
parameter, then this method obtains parameters from the Oracle Spatial application context. Consequently, you must use the spatial
link name to associate the method call with the Oracle Spatial application context:
com.oracle.cep.cartridge.spatial.Geometry.createGeometry@spatial(gtype, eleminfo, ordinates)
For more information, see Section 16.1.4, "Oracle Spatial Application Context".
Example 1617 shows how to use the createGeometry
method. Because this createGeometry
call does not include the srid
argument, it uses the spatial
link name to associate the method call with the Oracle Spatial application context.
Example 1617 Oracle CQL Query Using Geometry.createGeometry
<view id="ShopGeom"> select com.oracle.cep.cartridge.spatial.Geometry.createGeometry@spatial( com.oracle.cep.cartridge.spatial.Geometry.GTYPE_POLYGON, com.oracle.cep.cartridge.spatial.Geometry.createElemInfo(1, 1003, 1), ordsgenerator@spatial( lng1, lat1, lng2, lat2, lng3, lat3, lng4, lat4, lng5, lat5, lng6, lat6 ) ) as geom from ShopDesc </view>
This com.oracle.cep.cartridge.spatial.Geometry
method returns a new com.oracle.cep.cartridge.spatial.Geometry
object which is a 2D simple linear polygon without holes. If the coordinate array does not close itself (the last coordinate is not the same as the first) then this method copies the first coordinate and appends this coordinate value to the end of the input coordinates array.
To create a simple linear polygon without holes, use the following arguments:
coords
: the coordinates of the linear polygon as a double[]
.
srid
: the optional SRID
of the geometry as an int
.
If you omit the srid
parameter, then this method obtains parameters from the Oracle Spatial application context. Consequently, you must use the spatial
link name to associate the method call with the Oracle Spatial application context:
com.oracle.cep.cartridge.spatial.Geometry.createLinearPolygon@spatial(coords)
For more information, see Section 16.1.4, "Oracle Spatial Application Context".
Example 1618 shows how to use the createLinearPolygon
method. Because this createLinearPolygon
method call does not include the srid
argument, it must use the spatial
link name to associate the method call with the Oracle Spatial application context.
This com.oracle.cep.cartridge.spatial.Geometry
method returns a new com.oracle.cep.cartridge.spatial.Geometry
object which is a 3D point.
This method takes the following arguments:
x
: the x coordinate of the lower left as a double
.
y
: the y coordinate of the lower left as a double
.
srid
: the optional SRID
of the geometry as an int
.
If you omit the srid
parameter, then this method obtains parameters from the Oracle Spatial application context. Consequently, you must use the spatial
link name to associate the method call with the Oracle Spatial application context:
com.oracle.cep.cartridge.spatial.Geometry.createPoint@spatial(x, y)
For more information, see Section 16.1.4, "Oracle Spatial Application Context".
Example 1619 shows how to use the createPoint
method. Because this createPoint
call includes the srid
argument, it does not need to use the spatial
link name.
This com.oracle.cep.cartridge.spatial.Geometry
method returns a new com.oracle.cep.cartridge.spatial.Geometry
object which is a 2D rectangle.
This method takes the following arguments:
x1
: the x coordinate of the lower left as a double
.
y1
: the y coordinate of the lower left as a double
.
x2
: the x coordinate of the upper right as a double
.
y2
: the y coordinate of the upper right as a double
.
srid
: the optional SRID
of the geometry as an int
.
If you omit the srid
parameter, then this method obtains parameters from the Oracle Spatial application context. Consequently, you must use the spatial
link name to associate the method call with the Oracle Spatial application context:
com.oracle.cep.cartridge.spatial.Geometry.createRectangle@spatial(x1, y1, x2, y2)
For more information, see Section 16.1.4, "Oracle Spatial Application Context".
Example 1620 shows how to use the createRectangle
method. Because this createRectangle
method call does not include the srid
argument, it must use the spatial
link name to associate the method call with the Oracle Spatial application context.
This com.oracle.cep.cartridge.spatial.Geometry
method calculates the distance between two geometries as a double
.
To calculate the distance between a given com.oracle.cep.cartridge.spatial.Geometry
object and another, use the nonstatic distance
method of the current Geometry
object with the following arguments:
g
: the other com.oracle.cep.cartridge.spatial.Geometry
object.
To calculate the distance between two com.oracle.cep.cartridge.spatial.Geometry
objects, use the static distance
method with the following arguments:
g1
: the first com.oracle.cep.cartridge.spatial.Geometry
object.
g2
: the second com.oracle.cep.cartridge.spatial.Geometry
object.
In both cases, this method obtains parameters from the Oracle Spatial application context. Consequently, you must use the spatial
link name to associate the method call with the Oracle Spatial application context:
com.oracle.cep.cartridge.spatial.Geometry.distance@spatial(geom) com.oracle.cep.cartridge.spatial.Geometry.distance@spatial(geom1, geom2)
For more information, see Section 16.1.4, "Oracle Spatial Application Context".
Example 1621 shows how to use the distance
method. Because the distance
method depends on the Oracle Spatial application context, it must use the spatial
link name.
Example 1621 Oracle CQL Query Using Geometry.distance
<view id="LocGeomStream" schema="customerId curLoc"> select customerId, com.oracle.cep.cartridge.spatial.Geometry.createRectangle(x1, y1, x2, y2, 8307) from CustomerLocStream where com.oracle.cep.cartridge.spatial.Geometry.distance@spatial(geom1, geom2) < 5 </view>
Note:
This is an Oracle CQL function and not a method of the com.oracle.cep.cartridge.spatial.Geometry
class so you invoke this function as Example 1622 shows, without a package prefix:
einfogenerator@spatial
Alternatively, you can use the Geometry
method createElemInfo
. For more information, see "createElemInfo".
This function returns a single element info value as an int[]
from the given arguments.
This function takes the following arguments:
offset
: the offset, as an int
, within the ordinates array where the first ordinate for this element is stored.
SDO_STARTING_OFFSET
values start at 1 and not at 0. Thus, the first ordinate for the first element will be at SDO_GEOMETRY.Ordinates(1)
. If there is a second element, its first ordinate will be at SDO_GEOMETRY.Ordinates(
n
* 3 + 2)
, where n
reflects the position within the SDO_ORDINATE_ARRAY
definition.
etype
: the type of the element as an int
.
Oracle Spatial supports SDO_ETYPE
values 1, 1003, and 2003 are considered simple elements (not compound types). They are defined by a single triplet entry in the element info array. These types are:
1: point.
1003: exterior polygon ring (must be specified in counterclockwise order).
2003: interior polygon ring (must be specified in clockwise order).
These types are further qualified by the SDO_INTERPRETATION
.
Note:
You cannot mix 1digit and 4digit SDO_ETYPE
values in a single geometry.
interp
: the interpretation as an int
.
For an SDO_ETYPE
that is a simple element (1, 1003, or 2003) the SDO_INTERPRETATION
attribute determines how the sequence of ordinates for this element is interpreted. For example, a polygon boundary may be made up of a sequence of connected straight line segments.
If a geometry consists of more than one element, then the last ordinate for an element is always one less than the starting offset for the next element. The last element in the geometry is described by the ordinates from its starting offset to the end of the ordinates varying length array.
Table 166 describes the relationship between SDO_ETYPE
and SDO_INTERPREATION
.
Table 166 SDO_ETYPE and SDO_INTERPRETATION
SDO_ETYPE  SDO_INTERPRETATION  Description 

0 
Any numeric value 
Used to model geometry types not supported by Oracle Spatial. 
1 
1 
Point type. 
1 
0 
Orientation for an oriented point. 
1003 or 2003 
1 
Simple polygon whose vertices are connected by straight line segments. You must specify a point for each vertex; and the last point specified must be exactly the same point as the first (within the tolerance value), to close the polygon. For example, for a 4sided polygon, specify 5 points, with point 5 the same as point 1. 
Example 1622 shows how to use the oeinfogenerator
function to create the element information for a geometry.
Example 1622 Oracle CQL Query Using Oracle Spatial Geometry Types
view id="ShopGeom"> select com.oracle.cep.cartridge.spatial.Geometry.createGeometry@spatial( com.oracle.cep.cartridge.spatial.Geometry.GTYPE_POLYGON, einfogenerator@spatial(1, 1003, 1), ordsgenerator@spatial( lng1, lat1, lng2, lat2, lng3, lat3, lng4, lat4, lng5, lat5, lng6, lat6 ) ) as geom from ShopDesc </view>
Note:
This is an Oracle Spatial geometric filter operator and not a method of the com.oracle.cep.cartridge.spatial.Geometry
class so you invoke this operator as Example 1613 shows, without a package prefix:
FILTER@spatial
This operator returns true
for object pairs that are nondisjoint, and false
otherwise.
This operator takes the following arguments:
key
: a GTYPE_POINT
geometry type.
The geometry type of this geometry must be GTYPE_POINT
or a RUNTIME_EXCEPTION
will be thrown.
tol
: the tolerance as a double
value.
For more information, see "SDO_FILTER" in the Oracle Spatial Developer's Guide.
Example 1627 shows how to use the FILTER
Oracle Spatial geometric filter operator in an Oracle CQL query.
This com.oracle.cep.cartridge.spatial.Geometry
method returns the Minimum Bounding Rectangle (MBR) of a given Geometry
as a double[][]
that contains the following values:
[0][0]
: minX
[0][1]
: maxX
[1][0]
: minY
[1][1]
: maxY
This method takes the following arguments:
geom
: the com.oracle.cep.cartridge.spatial.Geometry
object.
Example 1624 shows how to use the get2dMbr
method.
Note:
This is an Oracle Spatial geometric relation operator and not a method of the com.oracle.cep.cartridge.spatial.Geometry
class so you invoke this operator as Example 1613 shows, without a package prefix:
INSIDE@spatial
This operator returns true
if the GTYPE_POINT
is inside the geometry, and false
otherwise.
This operator takes the following arguments:
geom
: any supported geometry type.
key
: a GTYPE_POINT
geometry type.
The geometry type of this geometry must be GTYPE_POINT
or a RUNTIME_EXCEPTION
will be thrown.
tol
: the tolerance as a double
value.
For more information, see "SDO_INSIDE" in the Oracle Spatial Developer's Guide.
Example 1627 shows how to use the INSIDE
Oracle Spatial geometric relation operator in an Oracle CQL query.
Example 1625 Oracle CQL Query Using Geometric Relation Operator INSIDE
<view id="op_in_where"> RStream( select loc.customerId, shop.shopId from LocGeomStream[NOW] as loc, ShopGeomRelation as shop where INSIDE@spatial(shop.geom, loc.curLoc, 5.0d) = true ) </view> <view id="op_in_proj"> RStream( select loc.customerId, shop.shopId, INSIDE@spatial(shop.geom, loc.curLoc, 5.0d) from LocGeomStream[NOW] as loc, ShopGeomRelation as shop ) </view>
Note:
This is an Oracle Spatial geometric filter operator and not a method of the com.oracle.cep.cartridge.spatial.Geometry
class so you invoke this operator as Example 1613 shows, without a package prefix:
NN@spatial
This operator returns the objects (nearest neighbors) from geom
that are nearest to key
. In determining how near two geometry objects are, the shortest possible distance between any two points on the surface of each object is used.
This function takes the following arguments:
geom
: any supported geometry type.
key
: a GTYPE_POINT
geometry type.
The geometry type of this geometry must be GTYPE_POINT
or a RUNTIME_EXCEPTION
will be thrown.
tol
: the tolerance as a double
value.
For more information, see "SDO_NN" in the Oracle Spatial Developer's Guide.
Example 1627 shows how to use the NN
Oracle Spatial geometric filter operator in an Oracle CQL query.
Note:
This is an Oracle CQL function and not a method of the com.oracle.cep.cartridge.spatial.Geometry
class so you invoke this function as Example 1627 shows, without a package prefix:
ordsgenerator@spatial
This function returns the double
array of 2D coordinates that Oracle Spatial requires.
This function takes the following arguments:
x1, y1, ... xN, yN
: a commaseparated list of double
coordinate values.
Example 1627 shows how to use the ordsgenerator
function to create an Oracle Spatial double array out of six double
coordinate values.
Example 1627 Oracle CQL Query Using Oracle Spatial Geometry Types
view id="ShopGeom"> select com.oracle.cep.cartridge.spatial.Geometry.createGeometry@spatial( com.oracle.cep.cartridge.spatial.Geometry.GTYPE_POLYGON, com.oracle.cep.cartridge.spatial.Geometry.createElemInfo(1, 1003, 1), ordsgenerator@spatial( lng1, lat1, lng2, lat2, lng3, lat3, lng4, lat4, lng5, lat5, lng6, lat6 ) ) as geom from ShopDesc </view>
This com.oracle.cep.cartridge.spatial.Geometry
method converts an oracle.spatial.geometry.JGeometry
type to a 3D com.oracle.cep.cartridge.spatial.Geometry
type. If the given geometry is already a Geometry
type and a 3D geometry, then no conversion is done. If the given geometry is a 2D geometry, then the given geometry is converted to 3D by padding z coordinates.
This method takes the following arguments:
geom
: the oracle.spatial.geometry.JGeometry
object to convert.
Example 1628 shows how to use the to_Geometry
method.
This com.oracle.cep.cartridge.spatial.Geometry
method converts a com.oracle.cep.cartridge.spatial.Geometry
object to an oracle.spatial.geometry.JGeometry
2D type.
This method takes the following arguments:
g
: the com.oracle.cep.cartridge.spatial.Geometry
object to convert.
Example 1629 shows how to use the to_JGeometry
method.
Note:
This is an Oracle Spatial geometric relation operator and not a method of the com.oracle.cep.cartridge.spatial.Geometry
class so you invoke this operator as Example 1613 shows, without a package prefix:
WITHINDISTANCE@spatial
This operator returns true
if the GTYPE_POINT
is within the given distance of the geometry, and false
otherwise.
This operator takes the following arguments:
geom
: any supported geometry type.
key
: a GTYPE_POINT
geometry type.
The geometry type of this geometry must be GTYPE_POINT
or a RUNTIME_EXCEPTION
will be thrown.
dist
: the distance as a double
value.
For more information, see "SDO_WITHIN_DISTANCE" in the Oracle Spatial Developer's Guide.
Example 1627 shows how to use the WITHINDISTANCE
Oracle Spatial geometric relation operator in an Oracle CQL query.
Example 1630 Oracle CQL Query Using Geometric Relation Operator WITHINDISTANCE
<view id="op_in_where"> RStream( select loc.customerId, shop.shopId from LocGeomStream[NOW] as loc, ShopGeomRelation as shop where WITHINDISTANCE@spatial(shop.geom, loc.curLoc, 5.0d) = true ) </view> <view id="op_in_proj"> RStream( select loc.customerId, shop.shopId, WITHINDISTANCE@spatial(shop.geom, loc.curLoc, 5.0d) from LocGeomStream[NOW] as loc, ShopGeomRelation as shop ) </view>