|
| DB2 Spatial dynamic type exception |
 |
Mon, 10 Mar 2008 08:35:51 -040 |
The information below was posted in a different newsgroup but is being
reposted here as it may be of general interest.
We have an application which extracts GPS Latitude and Longitude at 50ft
granularity from GIS Spatial database using spatial queries. We are
facing some issues in these GIS Spatial queries.
Query to extract Latitude and Longitude from GIS Shape File
With PROJECTION as (
Select db2gse.ST_FindMeasure (SHAPE, 183.52218320150752) as SHAPE
From
GGADMIN.FTRACK_ENG_LIN
Where
LINE_SEG_NBR = 3
And TRACK_SDTK_NBR = '1'
And track_type = 'M'
And MP_LABEL_BEG = ' '
And ((effective_ts <= current timestamp)
And (current timestamp < expire_ts or expire_ts is null))
And co_abbr = 'BNSF'
) ,
APOINT as (
Select db2gse.st_pointN (treat (SHAPE as db2gse.ST_MULTIPOINT), 1)
as shape
From
PROJECTION
Where
db2gse.st_isEmpty (Shape) = 0
)
Select cast (db2gse.ST_Y (treat (db2gse.ST_Transform (shape, 1) as
db2gse.st_point)) as decimal (15, 9)) as LATITUDE,
Cast (db2gse.ST_X (treat (db2gse.ST_Transform (shape, 1) as
db2gse.st_point)) as decimal (15, 9)) as LONGITUDE
From
APOINT;
Exception:
SQL20082N: The dynamic type "1029" of the expression is not a subtype
of the
Target data type "1041" in a TREAT specification. SQLSTATE=0D000
*******************************************************************************
The reason for this problem is that ST_FindMeasure has a static return
type of ST_Geometry because it can actually return geometries of type
ST_Point, ST_MultiPoint, ST_Linestring or ST_MultiLinestring depending
on the types and values of the arguments.
The TREAT operator can be used to "treat" an ST_Geometry value as the
static type of a parameter of a spatial function. For example, if the
returned geometry of the function ST_FindMeasure was actually
ST_MultiPoint, TREAT (shape as dbgse.ST_MultiPoint) will allow it to be
an input to ST_PointN.
However, in the code example above, ST_FindMeasure is actually returning
an ST_Point geometry (dynamic type 1029) which is not in the same type
hierarchy as ST_Multipoint (dynamic type 1041).
The easiest way to address this situation is to always convert the
result of ST_FindMeasure to an ST_MultiPoint with the ST_ToMultPoint
spatial function as follows:
Select db2gse.st_pointN (db2gse.st_tomultipoint (SHAPE), 1) as shape
You can see the dynamic spatial type values by looking at the DB2
|
| Post Reply
|
|
|
|
|
|
|
|
|
|