TIP : How to deal with SDO_GEOMETRY object in .NET ( OO4O and dotnet )
Date: 24 Oct 2002 07:55:22 -0700
Message-ID: <1be8547d.0210240655.79b1aac7_at_posting.google.com>
Hi!
I've been having problems with the SDO_GEOMETRY objects for about a
week. I just found out a solution.
If you're having problem inserting/binding a SDO_GEOMETRY object with
OO4O, try this :
-> Instead of inserting the values directly in the 2
collections(SDO_ELEM_INFO & SDO_ORDINATES), create yourself an
OraCollection, insert your values into it, they assign this collection
to the SDO_GEOMETRY object (OraObject). It is important to assign the
collection AFTER they have been filled. To do this, type-cast the
OraObject in a plain dotnet Object. Otherwise, you're collections will
end up beeing <NULL> for some reason.
-> If you're still having problems, create yourself a stored procedure
to print the content of the SDO_GEOMETRY object to a file to make sure
everything is fine.
-> There's a bug in the .NET debugger or something. When you what to
see the value of an item in an OraCollection, Write the "Item"
keyword. It is not needed because it's the default property, but write
it anyway. Otherwise, you will end up with a string twice as long,
each char separated by a '\0' or something. True story!
Example :
- DO! *
Dim sdo As OraObject =
m_connection.m_database.CreateOraObject("MDSYS.SDO_GEOMETRY")
Dim sdoElemInfo As OraCollection =
m_connection.m_database.CreateOraObject("MDSYS.SDO_ELEM_INFO_ARRAY")
Dim sdoOrdinates As OraCollection =
m_connection.m_database.CreateOraObject("MDSYS.SDO_ORDINATE_ARRAY")
sdo.Item(1).Value = 2003 'SDO_GTYPE (2003 is a 2-dimensional polygon)
sdoElemInfo.Append(1) 'SDO_ELEM_INFO.SDO_STARTING_OFFSET (We start at
the first vertex)
sdoElemInfo.Append(1003) 'SDO_ELEM_INFO.SDO_ETYPE (1003 mean we are
defining the exterior ring of a polygon)
sdoElemInfo.Append(4) 'SDO_ELEM_INFO.SDO_INTERPRETATION (4 is for
circle)
sdoOrdinates.Append(pt1.m_x) 'SDO_ORDINATES (x1) sdoOrdinates.Append(pt1.m_y) 'SDO_ORDINATES (y1) sdoOrdinates.Append(pt2.m_x) 'SDO_ORDINATES (x2) sdoOrdinates.Append(pt2.m_y) 'SDO_ORDINATES (y2) sdoOrdinates.Append(pt3.m_x) 'SDO_ORDINATES (x3) sdoOrdinates.Append(pt3.m_y) 'SDO_ORDINATES (y3)
'HACK : OO4O late binding hack
CType(sdo, Object).sdo_elem_info = sdoElemInfo
CType(sdo, Object).sdo_ordinates = sdoOrdinates
'THIS WILL NOT WORK FOR SOME REASONS 'sdo.Item(4).Value = sdoElemInfo 'sdo.Item(5).Value = sdoOrdinates
- DONT! : The 2 collection will end up beeing null if you try to bind the SDO_GEOMETRY object! *
Dim sdo As OraObject =
m_connection.m_database.CreateOraObject("MDSYS.SDO_GEOMETRY")
sdo.Item(1).Value = 2003 'SDO_GTYPE (2003 is a 2-dimensional polygon)
sdo.Item(4).Value.Append(1) 'SDO_ELEM_INFO.SDO_STARTING_OFFSET (We
start at the first vertex)
sdo.Item(4).Value.Append(1003) 'SDO_ELEM_INFO.SDO_ETYPE (1003 mean we
are defining the exterior ring of a polygon)
sdo.Item(4).Value.Append(4) 'SDO_ELEM_INFO.SDO_INTERPRETATION (4 is
for circle)
sdo.Item(5).Value.Append(pt1.m_x) 'SDO_ORDINATES (x1) sdo.Item(5).Value.Append(pt1.m_y) 'SDO_ORDINATES (y1) sdo.Item(5).Value.Append(pt2.m_x) 'SDO_ORDINATES (x2) sdo.Item(5).Value.Append(pt2.m_y) 'SDO_ORDINATES (y2) sdo.Item(5).Value.Append(pt3.m_x) 'SDO_ORDINATES (x3) sdo.Item(5).Value.Append(pt3.m_y) 'SDO_ORDINATES (y3)
*Example of stored procedure to print the content of a SDO_GEOMETRY object. Will pop up a message box in VS.NET. *
[...]
if not shape.sdo_ordinates is null then
msg := msg || 'SDO_ORDINATES.COUNT = ' || to_char(shape.sdo_ordinates.count) || chr(13);
for i in 1..shape.sdo_ordinates.count loop msg := msg || 'SDO_ORDINATES(' || to_char(i) || ') = ' || to_char(shape.sdo_ordinates(i)) || chr(13); end loop;
else
msg := msg || 'SDO_ORDINATES = <NULL>' || chr(13);
end if;
RAISE_APPLICATION_ERROR(-20100, msg);
[...]
I hope it helps!
Mathieu Gauthier
Development Team
JCMB Technology Inc
Received on Thu Oct 24 2002 - 16:55:22 CEST