Thread: TIP : How to deal with SDO_GEOMETRY object in .NET (dotnet)


Permlink Replies: 0 - Pages: 1 Threads: [ Previous | Next ]
bleubleu

Posts: 23
Registered: 01/18/02
TIP : How to deal with SDO_GEOMETRY object in .NET (dotnet)
Posted: Oct 24, 2002 8:51 AM
Click to report abuse...   Click to reply to this thread Reply
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

Legend
Guru Guru : 2500 - 1000000 pts
Expert Expert : 1000 - 2499 pts
Pro Pro : 500 - 999 pts
Journeyman Journeyman : 200 - 499 pts
Newbie Newbie : 0 - 199 pts
Oracle ACE Director
Oracle ACE Member
Oracle Employee ACE
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums